bug-bash
[Top][All Lists]
Advanced

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

Re: Running multiple processes using trap and kill -s


From: Chet Ramey
Subject: Re: Running multiple processes using trap and kill -s
Date: Wed, 29 Jun 2005 16:39:51 -0400
User-agent: Mozilla Thunderbird 1.0.2 (Macintosh/20050317)

Sammo wrote:
> 2.05b.0(1)-release
> 
> I seem to be having problems with one of the examples in the Advanced
> Bash Scripting Guide [1]. The script is supposed to start a specified
> number of processes, and when each process finishes, it sends a trap
> signal, which starts a new process. I think the script is correct, but
> it's not working as expected.
> 
> This is what is happening: The first process that finishes sends a
> trap signal to $$, and a new process is started (as expected). But
> when subsequent processes try to send the trap signal, they can't find
> the process. Also, seems that the "wait" command is only waiting until
> the first process finishes, instead of waiting for all of them to
> finish.

I don't see how this can work in a modern version of bash.  If you
start a non-zero number of processes, each of which will send SIGRTMIN
back to the controlling shell when it finishes, at least one of those
signals will arrive while `wait' is executing.

Bash is POSIX-conformant in this regard: since SIGRTMIN is trapped, wait
will terminate and the trap will be executed.  Once wait terminates,
control falls right through to the end of the script, and the remaining
children lose their controller.

I don't know when the script was written, and it's reasonable to assume
that wait's behavior has changed over time to become POSIX-conformant.
However, it's behavior is correct now and I doubt it will change unless
POSIX does.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
                                                Live...Laugh...Love
Chet Ramey, ITS, CWRU    chet@case.edu    http://tiswww.tis.case.edu/~chet/




reply via email to

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