Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consequences of using kill -9 for node processes?

When reading mongodb's documentation one of the thing that stood out was:

WARNING:

Never use kill -9 (i.e. SIGKILL) to terminate a mongod instance.

I've been running into issues while using foreman start to start my node server. Foreman will start up multiple node processes with the same PID.

However the problem is that when I stop my node process, node won't actually stop running and continues to use the port it was listening on.

To work around this I've been using sudo kill -9 <PID> for the node process I want to terminate. Are there any negative consequences to doing this?

Also, why does Mongo warn against using kill -9 to terminate a mongod instance?

like image 590
Pavan Ravipati Avatar asked Jul 01 '15 19:07

Pavan Ravipati


People also ask

How do you kill a process in node?

kill() Method. The process. kill( pid[,signal] ) is an inbuilt method of node. js which sends a signal to the process, pid (which is the process id) and signal is in the string format that is the signal to send.

How kill all node processes in Linux?

Linux machine: process. exit() in your application causes the NodeJS instance to close. killall node in bash would kill all NodeJS instances running on your machine.

Which key is used to kill a process in node JS?

Method 1: Using the Ctrl+C key This shortcut can be used to stop any running process by hitting this command on terminal.

How do you kill child processes that spawn their own child processes in node JS?

var spawn = require('child_process'). spawn; var child = spawn('my-command'); child. kill();


1 Answers

It doesn't give the process a chance to cleanly:

1) shut down socket connections

2) clean up temp files

3) inform its children that it is going away

4) reset its terminal characteristics

These are the bad consequences of what can happen when you use kill -9. You should only use kill -9 as a last resort if all else has failed.

And to the second question, because kill -9 will kill the process even if it is in the middle of doing something while kill will shutdown the process after a clean exit.

like image 177
jgr208 Avatar answered Sep 19 '22 21:09

jgr208