brettwooldridge / NuProcess

Low-overhead, non-blocking I/O, external Process implementation for Java
Apache License 2.0
713 stars 84 forks source link

No notifications when issuing kill -9 to the child process #58

Open szhem opened 8 years ago

szhem commented 8 years ago

Hello,

Is it possible to know in the parent process if the state of the child process changes?

I'm trying to spawn "sh -c 'sleep 60'", then kill this child process with kill -9 from the shell and this child process starts to be in the defunct state until parent process exits. At the same time no notifications received within NuProcessHandler#onExit.

Kind Regards, Sergey

thraidh commented 3 years ago

When you spawn sh -c 'sleep 60' you are actually spawning a shell, that spawns a sleep 60.

If you kill the shell using kill, kill -9 or process.destroy(..) then only the shell is killed, while the sleep continues to live. It is reparented to some parent (usually your shell or PID 1), but still blocks the shell from finishing and it stays in defunct or zombie state.

process.waitFor(..) will also block, as long as the shell is not completely gone.

If you also kill the sleep 60 or just wait until it dies on its own, process.waitFor(..) will return and NuProcessHandler#onExit is executed.

See also #78 for a request to delete all child processes, so you can avoid this situation.