简体   繁体   中英

Kill a node.js program without killing child processes

I have a node.js program that has started multiple child processes. I want to be able to test what happens to those child processes if node crashes but leaves them up and running. I tried the following:

process.on('SIGUSR1', function(){   process.exit(0);    });

This worked great on my test setup, the child process kept right on running and Node instance shut down when I ran the following command:

killall -10 node

But, much to my surprise on my production deployment, it is failing to leave the child process up. The main child process of interest to me is an instance of chromium-browser. The difference seems to be the way the process is started. In my test setup I was invoking node directly but in my production setup I was calling a script that did the invoking.

What I would like to find is a way inside the anonymous callback function above that handles the SIGUSR1 signal to tell node not to shut down its child processes when it kills itself. I know I can go detach the process that I created but I'd rather do something less involved (even though admittedly, that's not too involved).

I'm running node 0.8.21 on Ubuntu 12.04.

Thanks for any ideas you can throw my way.

I went ahead and tried to see how much grief just creating the process detached would cause me, whether that would still allow me to use signal callbacks etc and all seems well. So I'm just going to implement it that way.

Here was my original code:

self.oUIProcessHandle = spawn('chromium-browser', 
    ['http://127.0.0.1:8091/index.html', '-kiosk', '-incognito', '-start-maximized']);

I changed it to the following:

self.oUIProcessHandle = spawn('chromium-browser', 
    ['http://127.0.0.1:8091/index.html', '-kiosk', '-incognito', '-start-maximized'],
    {detached: true, stdio: ['ignore', 'ignore', 'ignore']});

Now when I call process.exit(0) from my code, it leaves my browser up and running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM