Is it possible to get zombie process exit status from shell

processzombie

If i execute 'ps' command in shell, i can get some processes marked as '' – they are exited, but parent process don't receive they exit status yet. Sometimes, while debugging network apps, i need to get exit status of such process from shell – is it 0 or some error code like segmentation fault?

Is it possible to get this exit status from shell given PID, or only zombie's parent process can get this exit status?

P.S. I don't need to "kill" them, "close" them etc. I only need to check they exit status 🙂

Best Answer

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...