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

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

Yves M.
  • 29,855
  • 23
  • 108
  • 144
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
  • Does this answer your question? [Node.js Port 3000 already in use but it actually isn't?](https://stackoverflow.com/questions/39322089/node-js-port-3000-already-in-use-but-it-actually-isnt) – Penny Liu May 19 '20 at 02:45

8 Answers8

128

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

vbranden
  • 5,814
  • 2
  • 22
  • 15
  • 24
    Just the heads up, it will disrupt your Skype, Slack, VSCode, etc. In other words, any program which has fired up nodejs process. – Aneel Ansari Sep 03 '18 at 02:56
  • Great solution to kill all node processes. – Keyur Chavda-kc1994 Oct 22 '19 at 09:50
  • 1
    This is a poor solution because the question was how to kill a single Node.js process, but the solution is for killing *every* Node.js process. With Node apps becoming increasing common, the risk of killing something additional that you didn't intend is a possiblity. – Mark Stosberg Jun 17 '21 at 17:08
  • 1
    @MarkStosberg agreed, this was a good solution 7 years ago but does not answer the question to a t. I can amend the answer with the caveat that it will kill all node processes – vbranden Jun 17 '21 at 17:11
101
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

Krunal Limbad
  • 1,533
  • 1
  • 12
  • 23
  • this helped me! somehow this approach gave me the node process ID I was looking for based on the blocked port, rather than `ps aux | grep node` thanks a lot! – danivicario Apr 03 '20 at 12:18
46

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.

Ali_Hr
  • 4,017
  • 3
  • 27
  • 34
34

You can use the killall command as follows:

killall node
stefanobaghino
  • 11,253
  • 4
  • 35
  • 63
Sanjay Verma
  • 397
  • 3
  • 3
9

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.

kpimov
  • 13,632
  • 3
  • 12
  • 18
8

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
RaviRokkam
  • 789
  • 9
  • 16
4

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

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

mafonya
  • 2,152
  • 22
  • 21
1

This command works for me in Mac sudo pkill node