Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: bug in zsh wait builtin - rhbz#1150541



On 10/22/14, 2:55 AM, Bart Schaefer wrote:
> On Oct 21,  9:02pm, Peter Stephenson wrote:
> }
> } There's an explanatory note in the latest POSIX standard about this,
> } quoted below.  It seems that the shell is basically required to remember
> } all background processes indefinitely (up to not very helpful get out
> } clauses).  As a baseline, CHILD_MAX here is 1024.  This probably needs
> } to be a special hash.
> 
> Since you've bothered to look this up ... does it go on to say what the
> shell is supposed to do if PIDs roll over so that a new background job
> gets the same $! as some previous one?  Is "kill" supposed to work the
> same way?  (Do we need to send an inquiry to austin-group?  If so, you
> will have to do it, my ability to post there has been messed up for a
> long time.)

The implicit assumption in the Posix spec is that the pid space is large:
large enough that PIDs won't roll over and collide before you've gone
through CHILD_MAX children.  In practice, it happens surprisingly often.

The way I do it is to add the PIDs of exited jobs to a list, and prune it
if the list gets longer than the current child_max.  I check after fork()
and remove pids from the list if they recycle.

`wait' knows how to look through this list for child PID statuses.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@xxxxxxxx    http://cnswww.cns.cwru.edu/~chet/



Messages sorted by: Reverse Date, Date, Thread, Author