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?
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.
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.
Method 1: Using the Ctrl+C key This shortcut can be used to stop any running process by hitting this command on terminal.
var spawn = require('child_process'). spawn; var child = spawn('my-command'); child. kill();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With