Re: daemon caching weird exit status from a shell script
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 20 Mar 2007 21:27:12 GMT
brasilino@xxxxxxxxx <brasilino@xxxxxxxxx> wrote:
I'm developing a daemon written in C which will control some program
execution (something like init, but simpler),
and I'm getting something strange. I'm using fork() and execv() to
execute a bash script, for instance, and
the parent process is calling waitpid() to collect script exit status.
When the script ends with "exit 1" bash
instruction, waitpid() collects 256 as exit status, when it end with
"exit 2", 512 is collected. Seems that
the exit status from a bash script is seen as a more significant byte
within C daemon code and the
first byte is zeroed. Why? Is that right? What I done was to shift 8
bits right the exit status...
Have another look at the man page for waitpid(). The 'status'
you get back is a combination of the exit value of the program
and some additional information about the reasons the program
terminated (since there is not necessarily an exit value if the
process got killed e.g. due to an uncaught signal). Use the macro
WIFEXITED() on the 'status' value waitpid() reported and, if this
is true, you know there's an exit value and you can determine it
by using the WEXITSTATUS() on 'status'.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- Follow-Ups:
- Re: daemon caching weird exit status from a shell script
- From: brasilino@xxxxxxxxx
- Re: daemon caching weird exit status from a shell script
- References:
- daemon caching weird exit status from a shell script
- From: brasilino@xxxxxxxxx
- daemon caching weird exit status from a shell script
- Prev by Date: Re: Is splint the best for static code checking? I mean free.
- Next by Date: Re: Is splint the best for static code checking? I mean free.
- Previous by thread: daemon caching weird exit status from a shell script
- Next by thread: Re: daemon caching weird exit status from a shell script
- Index(es):
Relevant Pages
|