Capturing verbose exit codes

Cameron Simpson cs at zip.com.au
Sat Apr 3 23:22:11 UTC 2010


On 03Apr2010 17:07, Dave Ihnat <dihnat at dminet.com> wrote:
| On Sat, Apr 03, 2010 at 01:53:40PM -0700, Suvayu Ali wrote:
| > Whenever some job is sent to the background and it finishes, it displays 
| > a message on the shell with the exit code. ...
| > ...
| > I understand that I can get the exit code with $? but is there some way 
| > I can get the associated message (Done/Terminated/Sementation Fault...) 
| > with the exit code?
| 
| Unfortunately, every exit code is a function of the individual program
| that last ran, or the shellscript itself.  Do a man on the various
| commands; you'll find a wide range of exit codes.  About the only thing
| you can really count on--usually--is that an exit code of zero means
| everything was OK.

However, in the context of Suvayu's query (getting the _shell_'s job
control messages) the codes are universal, since the shell's knowledge
is as non-specific as you describe.

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.

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

Network Planning Constraint Of The Month:
        You can't send bits over a non-existant link.
                - Valdis Kletnieks <valdis at vtvm1.cc.vt.edu>


More information about the users mailing list