Is it possible to get zombie process exit status from shell?

Solution 1:

The definition of a zombie process is a process that finishes execution, but it still has it's exit status to report to it's partent process (which apparently is no longer there), because of this, the kernel will keep it it the process table, it is no longer scheduled for further execution but cannot be removed and not allow the PID to be reused until the exit status is determined to be not needed.

So per this definition, if you "receive" the exit code, you resolve the zombie process altogether. You would need a kernel module that can access the kernel strucures. Typically only the parent or init can read the value from waitpid(), but I remember reading that with newer kernels, there's a way to have process "controllers" take the place of init, i.e. they would adopt such children, so if you don't care killing the parent... this would be a workable way too.

I went though /proc to see if there's something to be dug out from there, but due to the nature of the exit codes, this won't be represented there...

Solution 2:

The exit code is available in /proc/pid/stat since 5b172087f99189416d5f47fd7ab5e6fb762a9ba3, it was probably too new by the time this question was asked... :)

Nowadays you can get the exit code from the last number in /proc/pid/stat.

Tags:

Process

Zombie