How to Stop a Hanging NodeJS Process
Once in a while you find yourself needing to terminate a hanging Node process manually.
While hanging Node processes are a rare case, they can happen from time to time which is why below commands will come in handy.
I maintain several droplets on DigitalOcean simultaneously and each run Node.js processes. If you haven’t given DigitalOcean a try, you can spin up a droplet and start with a $100 credit:
To list all Linux processes with some extra information about its origin, use this command:
$ ps -ef -A
Using Grep to List Node Processes
You can also list Node processes only with a grep search:
$ ps -ef | grep node
This will show a list of running Node processes with their process ID pid. Let us assume that the pid is 1234
, you would kill it with:
$ kill 1234
Stop All Node Processes
In the event you want to kill all Node processes at once:
$ pkill -f node
The Difference Between kill
and pkill
The kill
command is a wrapper to the kill
system call, which knows only about process IDs. pkill
can determine the process ID based on things like, process name, owner of the process or session id.