Skip to content

Instantly share code, notes, and snippets.

@andris9
Created February 20, 2012 08:44
Show Gist options
  • Save andris9/1868460 to your computer and use it in GitHub Desktop.
Save andris9/1868460 to your computer and use it in GitHub Desktop.
node cookbook

Node Cookbook

Kill child process when parent quits

Source SO

Reuiqures: node-ffi

// handle parent death
(function(){
    var FFI = require('node-ffi'),
        current = new FFI.Library(null, {"prctl": ["int32", ["int32", "uint32"]]}),

        //1: PR_SET_PDEATHSIG, 15: SIGTERM
        returned = current.prctl(1,15);

    process.on('SIGTERM',function(){
            //do something interesting
            process.exit(1);
    });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment