Re: daemon caching weird exit status from a shell script



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
.



Relevant Pages

  • Re: [SLE] closing a window running a bash script
    ... > John R. Sowden wrote: ... >> How do I close the window on a bash script I wrote. ... I put exit at the end, ... echo This program requires Root Authority. ...
    (SuSE)
  • Re: [SLE] closing a window running a bash script
    ... > How do I close the window on a bash script I wrote. ... > to mount an encrypted partition in case I didn't enter the password when I ... I put exit at the end, ... Actually, the shell isn't closing, because the command you're running ...
    (SuSE)
  • daemon caching weird exit status from a shell script
    ... execution, ... the parent process is calling waitpid() to collect script exit status. ... the exit status from a bash script is seen as a more significant byte ...
    (comp.os.linux.development.apps)
  • Re: logical OR - bash ..problems
    ... I am running a bash script that loops until a file becomes ... created/present. ... It loops waiting on 1 to 3 files, ... the script does not exit as expected. ...
    (comp.unix.shell)
  • Re: Bad habits of GOTO-using programmers
    ... The fact that it contains only the word EXIT confirms its function. ...     perform section-a ... The results of the execution of overlapping PERFORM statements are ...     The exit to main is destroyed by the second perform of a-x. ...
    (comp.lang.cobol)