bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange behavior with job control


From: Andreas Schwab
Subject: Re: Strange behavior with job control
Date: Tue, 27 Jul 2010 12:05:18 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Christoph Dittmann <address@hidden> writes:

> Why is "sleep 5" still running in the second case even though the job
> received SIGTERM and is known to the job control as "terminated"?

Try adding "ps f" before the wait command to see the difference in how
bash executes the two cases.  In the case without the braces the
subshell replaces itself with the sleep command, which is what is then
killed.  In the other case with the braces the subshell executes the
sleep as a subprocess and waits for it to terminate.  The kill command
then kills the subshell but the sleep command continues.

If you want to kill the whole background job you need to enable job
control (set -m) and call kill with the job specifier instead (kill %2
in this case).

> How can the wait call affect a job it's not supposed to wait for?

It's a simple race.  You may not give the subshell enough time to
acutally execute the sleep command.

Andreas.

-- 
Andreas Schwab, address@hidden
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]