3

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 :)

grigoryvp
  • 3,415
  • 11
  • 38
  • 58

2 Answers2

3

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

psarossy
  • 266
  • 1
  • 10
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.

Jong
  • 121
  • 2