bug-bash
[Top][All Lists]
Advanced

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

Strange behavior with job control


From: Christoph Dittmann
Subject: Strange behavior with job control
Date: Tue, 27 Jul 2010 01:50:07 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100528 Thunderbird/3.0.5

Hi,

consider the following script:

#!/bin/bash
sleep 0.5 &
if [[ $1 = a ]]; then
    sleep 5 &
else
    { sleep 5; } &
fi
PID=$!
wait %1
kill $PID
ps aux | grep '[s]leep 5'
exit 0

When I run this script with parameter "a" I get the following output:
./foo.sh: line 11: 12132 Terminated              sleep 5

When I run the script with the parameter "b" instead, I get two lines of
output:
1000     12117  0.0  0.0   9728   828 pts/1    S+   01:39   0:00 sleep 5
./foo.sh: line 11: 12116 Terminated              { sleep 5; }

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"?

What's even more puzzling to me is that removing the "wait %1" call
makes the problem disappear. That is, without the wait call the sleep 5
job properly terminates due to the kill, no matter if it was in curly
braces or not.

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

Christoph

(I use "GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)" on
Ubuntu 10.04.)



reply via email to

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