Subject: Re: [ast-users] Question about output of jobs -ln command
--------

> Hi,
> 
> ksh version:   sh (AT&T Research) 93t+ 2009-05-01
> OS: Red Hat Enterprise Linux AS release 4 (Nahant Update 5)
> 
> I am doing some work that requires tracking background jobs in a shell.
> I earlier versions of ksh the command "jobs -ln" would print out the process
> id(s) of the job(s) that had ended, so I would parse the output
> and in a for loop to pass the process id(s) to wait, to check the exit
> status.
> 
> But in this release I have found that "jobs -ln" does not include the
> process id.
> 
> Cut down example of what I mean:
> 
> set -o monitor
> 
> trap checkbg CHLD
> 
> function checkbg
> {
> 
>     jobs -ln
> }
> 
> sleep 10 &
> 
> wait
> 
> exit 0
> 
> This prints out;
> "[1] +  Done                    <command unknown>"
> 
> Is this correct or is there something else I have to do to get the process
> id from the jobs command?
> 
> Is there a better way to check the exist status from a bunch of background
> jobs in a script?
> 
> Thanks
> 
> Pete
> 

With the version in beta, (soon to be released), you can use
the following, to wait for background jobs and to get their
exit status.

For example, the following script:
==============cut here=====================
trap 'print pid=$! completed with exit status=$?' CHLD
for (( i= 0; i < 10; i++))
do      { r=$((1+(RANDOM%8))); sleep $r; exit $r;} &
done
wait
==============cut here=====================

produce the output
pid=188346 completed with exit status=2
pid=188351 completed with exit status=2
pid=188349 completed with exit status=3
pid=188347 completed with exit status=4
pid=188345 completed with exit status=6
pid=188353 completed with exit status=6
pid=188344 completed with exit status=6
pid=188350 completed with exit status=6
pid=188352 completed with exit status=7
pid=188348 completed with exit status=8


David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to