To isolate potentially crashy code (code that spawns binaries via the 
child_process module) from a long-running server process I've been spawning 
a node process which executes the code from the server process which in 
turn executes all the potentially crashing processes. This way - I figured 
- the server process was isolated both from any crashes of the spawned node 
program and of any of it's binaries, also the idea of killing the child 
process if it's taking too long appeals to me. However I discovered killing 
a child process doesn't automatically kill and process that child process 
spawns.

To solve this issue I read up a bit about how signals work in relation to 
processes and child processes I found a solution:

   1. Start the child process with the option 'detached': true, this causes 
   the child to become part of a new process group
   2. Instead of killing the child process via childProc.kill(signal) kill 
   it with process.kill(-childProc.pid, signal) (note the - in front of the 
   pid) this kills the entire process group

This seems to work on linux, I'm not sure if it works in other environments 
but for our current use case that's not important. But what I'm wary about 
is using an undocumented feature (granted, it's documented in the POSIX C 
library but not Node which wraps it) so I'd like to know if I can rely on 
this feature?

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to