I would like to the know the reason that a now-defunct process exited,
i.e. its exit status or the signal that caused it to exit. Can I find
this information in /proc or elsewhere?
I see that /proc/$pid/stat has a field exit_signal. Is there another
field that gives the exit status?
Thanks,
Shaun
The exit status of the most recent process is in an environment variable
called that you can get at as $?. Beyond that, you'd have to wrap the
command in a shell script that saves this away somewhere.
--
As we enjoy great advantages from the inventions of others, we should
be glad of an opportunity to serve others by any invention of ours;
and this we should do freely and generously. (Benjamin Franklin)
> Hi,
>
> I would like to the know the reason that a now-defunct process exited,
> i.e. its exit status or the signal that caused it to exit.> Can I find
> this information in /proc or elsewhere?
Perhaps in /proc, but most definitely elsewhere.
You have two processes: a process that is now defunct (call this the DEFUNCT
process), and a process that is trying to determine the cause of the other
process's defunctness (sic) (call this the ANALYSIS process).
The ANALYSIS process may retrieve the DEFUNCT process status using a wait(2)
or waitpid(2) syscall. This works only if the ANALYSIS process is the
parent of the DEFUNCT process, but gives the ANALYSIS process both the exit
status /and/ signal status of the DEFUNCT process. If you don't have a
parent/child relationship with the DEFUNCT process, and the DEFUNCT process
is parentless (i.e. an orphan process), the DEFUNCT process becomes adopted
by the init(8) process. init(8) will retrieve and discard the exit and
signal status from the DEFUNCT process.
/IF/ you have enabled "process accounting", the system will update the
process accounting file with, among other things, the exit and signal
status of the DEFUNCT process. You can either parse the process accounting
file, or use the process accounting tools (sa(8)) to examine the process
status.
> I see that /proc/$pid/stat has a field exit_signal. Is there another
> field that gives the exit status?
IIRC, the /proc/$pid entries only exist while the process is running, and
are discarded/deleted/dissolved when the process terminates. If this is
true, then you can't use /proc/$pid to retrieve information about defunct
processes. Someone care to elaborate? I don't have any zombie processes to
check against.
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------
Making a zombie isn't hard.
perl -e 'if(!($pid=fork())){
# child just waits to be killed
sleep 9999
} else {
# parent kills it
kill 9, $pid;
# wait long enough for it to finish dying
sleep 1;
# see what information we can get on the zombie
system "cat /proc/$pid/stat"
}'
Yes, /proc/$zombie/ does exist, and contains useful information (otherwise,
how would ps be able to show zombies at all?) But that's not what the
exit_signal field is for. It's the signal that the parent process will
receive (or in the case of a zombie, already did receive!) when this process
dies. Normally SIGCHLD, but can be something different when clone(2) gets
involved.
(clone zombie creator script left as an exercise)
Since a zombie is by definition still available for its parent to wait() on,
at which point the parent will get the exit status, that exit status must
still be around somewhere, but I don't see it in /proc. And it seems you
can't ptrace a zombie, so there may be no way for an unrelated process to get
it.
--
Alan Curry