bretcope/oshi — pull request #14 by momow (2014-08-20 13:51:29+00:00)
Title: forcefully kill children (SIGKILL) on daemon.kill()

Currently, when `daemon.kill()` is called, the daemon process is killed, but the children keep running.

There are exceptions: for instance, when the daemon process is killed and a child process writes to stdout, the child process receives a `SIGPIPE` signal and gets killed.

This PR introduces a forceful kill by sending the `SIGKILL` signal to all the children when `.kill()` is called on the daemon.

**Notes and possible improvements:**

- It is assumed that `group.kill()` and `child.kill()` will not throw. For extra safety, try/catch blocks might be used, so that the recursive killing process continues when an error occurs.

- This solution is a high-level one: only calls to `daemon.kill()` (through `api.kill()`, for instance) will benefit from the forceful kill behavior: sending the `SIGTERM` signal to the daemon process will not kill the children processes, and the described current behavior applies. A possible solution would be to listen to the `SIGTERM` signal on the daemon process and propagate the signal to (or kill) the child processes.

- Similarly, forcefully killing the daemon (with `kill -9` for instance) will not necessarily lead to children processes being killed too. One possible solution is to modify the child processes scripts so that a child kills itself when its parent stops running (for instance, by polling the status of the daemon process. Several solutions are available here, some of them being platform-dependent)