I have a node.js
application that uses some socket ports. Sometimes, when I exit the application with Ctrl + C
, some kind of node process is left running, still allocating the socket ports. Thus, I cannot restart my application, since it fails to open those ports. When I look the situation with ps
, I get the following response:
$ ps
PID TTY TIME CMD
40454 ttys000 0:00.11 -bash
41643 ttys001 0:00.00 (node)
41741 ttys001 0:00.00 (node)
Trying kill -9 41643
doesn't kill the process. Is it a some kind of unkillable zombie? How can I get rid of those (node)-things blocking my tcp
ports?
Ctrl+Z suspends it, which means it can still be running. Ctrl+C will actually kill it. Hope it is helpfull!! To know more about it, enroll in Node.
Method 1: Using ctrl+C key: When running a program of NodeJS in the console, you can close it with ctrl+C directly from the console with changing the code shown below: Method 2: Using process. exit() Function: This function tells Node. js to end the process which is running at the same time with an exit code.
To stop a running npm process, press CTRL + C or close the shell window.
exit() in your application causes the NodeJS instance to close. killall node in bash would kill all NodeJS instances running on your machine.
I'm not a MAC user, but here is what I use to kill all the available node processes (under linux):
sudo killall -9 node
On macOS, it's simply:
sudo killall -9 node
For a lot of the times, sudo
is overkill, but in your case, it looks like you might want to try sudo
.
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