Capturing verbose exit codes
Suvayu Ali
fatkasuvayu+linux at gmail.com
Sun Apr 4 01:06:36 UTC 2010
On Saturday 03 April 2010 04:22 PM, Cameron Simpson wrote:
> 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.
>
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 $?"
> Cheers,
Thanks a lot. :)
--
Suvayu
Open source is the future. It sets us free.
More information about the users
mailing list