How to kill a nodejs process in Linux?

UbuntuProcessKill

Ubuntu Problem Overview


tcp    0     0 0.0.0.0:80     0.0.0.0:*     LISTEN      9631/node    

How do I kill this process in linux(ubuntu)?

Ubuntu Solutions


Solution 1 - Ubuntu

pkill is the easiest command line utility

pkill -f node

or

pkill -f nodejs

whatever name the process runs as for your os

—- update —- It has been raised that this does not address killing a single node process and instead kills EVERY node process. If this is desired pkill is your tool, otherwise use one of the other accepted answers

Solution 2 - Ubuntu

sudo netstat -lpn |grep :'3000'

3000 is port i was looking for, After first command you will have Process ID for that port

kill -9 1192

in my case 1192 was process Id of process running on 3000 PORT use -9 for Force kill the process

Solution 3 - Ubuntu

if you want to kill a specific node process , you can go to command line route and type:

ps aux | grep node

to get a list of all node process ids. now you can get your process id(pid), then do:

kill -9 PID

and if you want to kill all node processes then do:

killall -9 node

-9 switch is like end task on windows. it will force the process to end. you can do:

kill -l

to see all switches of kill command and their comments.

Solution 4 - Ubuntu

You can use the killall command as follows:

killall node

Solution 5 - Ubuntu

Run ps aux | grep nodejs, find the PID of the process you're looking for, then run kill starting with SIGTERM (kill -15 25239). If that doesn't work then use SIGKILL instead, replacing -15 with -9.

Solution 6 - Ubuntu

In order to kill use: killall -9 /usr/bin/node

To reload use: killall -12 /usr/bin/node

Solution 7 - Ubuntu

First find the Process ID (PID) associated with the port:

lsof -i tcp:5000

That displayed for me

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox  4228 ravi  243u  IPv4 484748      0t0  TCP localhost:36216->localhost:5000 (ESTABLISHED)
node    12675 ravi   21u  IPv4 231192      0t0  TCP *:5000 (LISTEN)
node    12675 ravi   24u  IPv4 485739      0t0  TCP localhost:5000->localhost:36216 (ESTABLISHED)

then kill the process with :

kill -9 12675

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLeBlaireauView Question on Stackoverflow
Solution 1 - UbuntuvbrandenView Answer on Stackoverflow
Solution 2 - UbuntuKrunal LimbadView Answer on Stackoverflow
Solution 3 - UbuntuAli_HrView Answer on Stackoverflow
Solution 4 - UbuntuSanjay VermaView Answer on Stackoverflow
Solution 5 - UbuntukpimovView Answer on Stackoverflow
Solution 6 - UbuntumafonyaView Answer on Stackoverflow
Solution 7 - UbuntuRaviRokkamView Answer on Stackoverflow