Capturing verbose exit codes

Cameron Simpson cs at zip.com.au
Sun Apr 4 03:15:35 UTC 2010


On 03Apr2010 18:06, Suvayu Ali <fatkasuvayu+linux at gmail.com> wrote:
| On Saturday 03 April 2010 04:22 PM, Cameron Simpson wrote:
| > So the shell can report Terminated and Segmentation Fault reliably and
| > Done versus failed because the wait status has distinct information.
| > So he should be able to check done versus failed ($? == 0 versus
| > nonzero), and he may find the shell returns negative values for
| > "terminated by signal N". Core dumps may not be exposed by the shell.
| >
| > Suvayu: try this:
| >
| >    sleep 3600&
| >    kill -9 $!; wait; echo "\$?=$?"
| >
| > and repeat with various kill numbers. See if you get anything useful.
| >
| 
| Thank you Cameron for the hints! With some more thinking and some help 
| from my roomie, I found something useful to work with. Substituting `n' 
| below gives me quite a bit to experiment with. :)
| 
| $ sleep 3600 &
| $ pid=$! ;kill -n $pid;wait $pid;echo "$pid exited with $?"

You should also read "man 2 wait" and likewise for wait3, wait4 and
waitpid (possibly "man 3 blah" for some of these, and they may all show
up on the same manpage). That will give you an idea of what information
the shell gets to know after a process exits.

And to get an idea of what you may expect on UNIX systems in general as
opposed to linux in particular, use "3p" instead of "2" and "3" above;
that will get you the corresponding POSIX manual on most linux systems.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Besides, it's good to force C programmers to use the toolbox occasionally. :-)
        - Larry Wall in <1991May31.181659.28817 at jpl-devvax.jpl.nasa.gov>


More information about the users mailing list