[lug] checking bg processes' exit status

Tom Tromey tromey at redhat.com
Tue Mar 4 09:56:02 MST 2008


>>>>> "Nick" == Nick Golder <nrg at nirgo.net> writes:

Nick> I have a bash script that is setting a series of processes in the
Nick> background and I want to see what their exit codes are.  I have played
Nick> around trying to find a way to do it and I haven't found a reliable way,
Nick> yet.  Any suggestions?

You can save "$!" after forking the process, and then use "wait".
Offhand I don't know whether wait prints the status or returns it.

Another approach is to have the job itself report:

    ( ...; echo $? > someplace-handy) &

Tom



More information about the LUG mailing list