2910

How do I find (and kill) processes that listen to/use my TCP ports? I'm on macOS.

Sometimes, after a crash or some bug, my Rails app is locking port 3000. I can't find it using ps -ef...

When running

rails server

I get

Address already in use - bind(2) (Errno::EADDRINUSE)

The same issue happens when stopping Node.js process. Even after the process is stopped and the app stops running, port 3000 is locked. When starting the app again, getting

Address already in use (Errno::EADDRINUSE)
Archmede
  • 1,592
  • 2
  • 20
  • 37
oma
  • 38,642
  • 11
  • 71
  • 99
  • 42
    A very neat solution to kill a process on ANY user-specified port can be found in @Kevin Suttle's answer below. Reproduced here for posterity: `function killport() { lsof -i TCP:$1 | grep LISTEN | awk '{print $2}' | xargs kill -9 }` – user456584 Jan 17 '14 at 18:39
  • @user456584 's comment above should be the accepted answer ^^^ That function worked to kill the _many_ processes i had running on a port – Andrew Bowman Jun 19 '19 at 15:12
  • works after finding processes with netstat and killing the process with kill -9 command! – Gaurav Apr 08 '21 at 15:39
  • 17
    @richardec `kill -9 $(lsof -ti:3000)` not working? – Abhijith Sasikumar Jan 18 '22 at 09:49
  • This is clearly a very specific programming problem that a lot of folks Google all the time. I need to find out what's running on a port so I can restart my webapp. I do not believe it should be closed. Vote to reopen. – superluminary Jun 07 '23 at 17:25
  • for macb version BigSur this working lsof -t -i tcp:3000 | xargs kill – Mandeep Singh Jun 13 '23 at 04:07
  • Just because its popular does not mean it should be opened. Voting to leave it closed – Rohit Gupta Jul 06 '23 at 12:18

40 Answers40

4530
  1. You can try netstat

    netstat -vanp tcp | grep 3000
    
  2. For macOS El Capitan and newer (or if your netstat doesn't support -p), use lsof

    lsof -i tcp:3000
    
Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103
ghostdog74
  • 327,991
  • 56
  • 259
  • 343
  • 52
    Thank you! Your answer gave birth to my "death_to 'port'" script. (#!/usr/bin/ruby `lsof -t -i tcp:#{ARGV.first} | xargs kill`) – Sv1 Oct 02 '13 at 18:40
  • 326
    The "terse" flag to lsof produces output suitable for piping to a subsequent kill: `lsof -t -i tcp:1234 | xargs kill` – Manav Jan 07 '14 at 04:58
  • If you want to know what the process is before you kill it, `ps xp `. It's always nice to find out the root cause of port conflicts. – Dave Ceddia Apr 15 '15 at 18:25
  • 1
    If you only want to look for/kill *listening* processes, use `lsof -n -i4TCP:8001 -sTCP:LISTEN -t | xargs kill`. I found that if I did it without the `LISTEN` it would often kill my browser as well as a locked development server process, as the browser was also using the development port. – awidgery Jul 15 '15 at 13:48
  • 19
    I have put this into my `~/.bash_profile`: `findandkill() { port=$(lsof -n -i4TCP:$1 | grep LISTEN | awk '{ print $2 }') kill -9 $port } alias killport=findandkill` So now I just have to type `killport 8080` and it saves me some seconds – Alfonso Embid-Desmet Nov 11 '15 at 13:51
  • 9
    Another tip is to add `-P` to the `lsof` command so that the raw port is visible in the output: `lsof -P -i:3000` – Jason Axelson Jul 22 '16 at 02:06
  • on mac `lsof` is on `/usr/sbin` directory which is not in `PATH` by default. – artronics Feb 14 '17 at 18:21
  • @oma if you run the netstat command without the grep, you'll get the column names. – Will Munn Apr 20 '17 at 15:53
  • 1
    netstat -tulpn | grep 3000 Then kill the process id kill -9 id –  Jun 20 '19 at 11:27
  • Just curious but could `netstat -vanp tcp | grep 3000` sometimes return spurious results since `3000` could be present in a pid or ip? (sorry, not hugely knowledgable and hence not sure) – stevec Jan 14 '20 at 03:31
  • 26
    This post is only half the answer – png Mar 24 '20 at 17:10
  • I would have appreciated this answer to have find (and kill) part since I landed on this answer while searching for "find AND kill process running on a port"! – Arvind K. Jun 23 '21 at 14:53
  • 3
    My bashprofile function is based on the above suggestions but simplified: `killport() { lsof -t -i tcp:$1 | xargs kill -9 }` Usage: `killport 5000` – motto Oct 12 '21 at 17:42
  • 2
    If you are using macOS Monterey, the Airplay server now uses Port 5000 so you either need to change the port for your process or kill Airplay receiver in System Preferences > Sharing – Clive Townsend Nov 19 '21 at 15:49
  • On macOS Monterey you have to disable the new AirPlay functionality. Control Center stops listening to those ports when you turn off "AirPlay Receiver" in System Preferences > Sharing – Anfuca Nov 23 '21 at 06:54
  • mac: sudo npx kill-port 3000 (or with PC: npx kill-port 3000) – Ahmedakhtar11 Aug 01 '23 at 04:22
3177

Find:

sudo lsof -i :3000

Kill:

kill -9 <PID>

PLEASE NOTE: -9 kills the process immediately, and gives it no chance of cleaning up after itself. This may cause problems. Consider using -15 (TERM) or -3 (QUIT) for a softer termination which allows the process to clean up after itself.

Ulf Aslak
  • 7,876
  • 4
  • 34
  • 56
Filip Spiridonov
  • 34,332
  • 4
  • 27
  • 30
  • 92
    Sometimes **lsof -i :port** will show nothing. try **sudo lsof -i :port**. – kilik52 Jan 30 '14 at 12:05
  • 66
    Recommend trying `kill -15 ` before resorting to `-9` for safety. – Jamon Holmgren Aug 16 '15 at 23:55
  • 8
    @Jamon Holmgren why? what do both do? and why is a ```kill ``` not sufficient / dangerous / incomplete? – Michahell Nov 24 '15 at 12:45
  • 24
    @MichaelTrouw almost a year later, but here's your answer. :-) http://unix.stackexchange.com/a/8918 TL;DR `kill -15` gives the process a chance to clean up after itself. – Jamon Holmgren Oct 12 '16 at 05:57
  • 29
    I think this answer should say what `-9` does. – Joseph Fraley Jan 17 '17 at 19:13
  • 17
    Please don't just use `kill -9` without thinking twice, and trying other signals first. It will cause a process to exit immediately, without cleaning up after itself, possibly leaving a mess behind or leaving databases in inconsistent state... Try a TERM (default for `kill`, no flag needed) or QUIT (`kill -3 pid`) first at least, and check what process you are dealing with before sending a KILL. – niels Jan 26 '17 at 11:58
  • 2
    That cleanup is important for Java processes, I just experienced. Restarting my machine fixed the problem after killing with -9. Will be trying -15 next. – Beez Sep 12 '18 at 19:18
  • 1
    @MichaelTrouw kill command's [Man page](https://ss64.com/osx/kill.html) says that "-15" means "Termination signal - allow an orderly shutdown", whereas "-9" means "Kill signal". – Sufian Oct 18 '18 at 09:12
  • When I use `kill -9 `, show error `kill: kill failed: operation not permitted`. solution is add sudo in the front. `sudo kill -9 ` – Zgpeace Jan 29 '20 at 01:39
  • 1
    Kill:sudo kill No need of -9 – Amisha Mar 31 '20 at 05:32
  • how come it is not marked as the right answer, it's the fastest way to do it – Dr. Freddy Dimethyltryptamine May 28 '20 at 10:23
  • 1
    Please edit the answer and add an explanation for what `-9` does. I see some comments suggest `-15`, and an explanation will definitely be benefit others. Thanks! – themthem Apr 16 '21 at 05:37
  • difference between `-9` and `-15` is explained here: https://en.wikipedia.org/wiki/Kill_(command)#Unix_and_Unix-like. `-15` is the safest and also the default option – Koen Jun 09 '21 at 08:16
  • 3
    I've never forgotten this command due to [this rap video.](https://www.youtube.com/watch?v=Fow7iUaKrq4) – Heartthrob_Rob Apr 22 '22 at 20:48
  • i like to use -9 when I'm mad at my computer program that won't quit when I ask nicely – ICW Oct 26 '22 at 22:17
  • no sudo needed on mac – Yuqiu G. Apr 19 '23 at 12:51
1063

Quick and easiest solution:

kill -9 $(lsof -ti:3000)

For multiple ports:

kill -9 $(lsof -ti:3000,3001)

#3000 is the port to be freed

Kill multiple ports with single line command:

kill -9 $(lsof -ti:3000,3001)

#Here multiple ports 3000 and 3001 are the ports to be freed

lsof -ti:3000

If the port is occupied, the above command will return something like this: 82500 (Process ID)

lsof -ti:3001

82499

lsof -ti:3001,3000

82499 82500

kill -9 $(lsof -ti:3001,3000)

Terminates both 82499 and 82500 processes in a single command.

For using this in package.json scripts:

"scripts": {
   "start": "kill -9 $(lsof -ti:3000,3001) && npm start"
}

In terminal you can use:

npm run start
Zohra Khan
  • 5,182
  • 4
  • 25
  • 34
Abhijith Sasikumar
  • 13,262
  • 4
  • 31
  • 45
312

Nothing above worked for me. Anyone else with my experience could try the following (worked for me):

Run:

lsof -i :3000 (where 3000 is your current port in use)

then check status of the reported PID :

ps ax | grep <PID>

finally, "begone with it":

kill -QUIT <PID>
jamesmortensen
  • 33,636
  • 11
  • 99
  • 120
Austin
  • 3,556
  • 2
  • 16
  • 16
  • 34
    This actually seems a better answer than the one give much later by Filip Spiridonov, which has 277 upvotes against your 9. Yours was 6 months earlier, and has the same information with a bit more explanation. There is no justice... – Floris Dec 30 '15 at 22:15
  • 2
    Try `kill -TERM` (or just `kill`) before `kill -QUIT`. Not every process is going to do an orderly shutdown on SIGQUIT. – craig65535 Jan 21 '20 at 00:09
202

This single command line is easy to remember:

npx kill-port 3000

You can also kill multiple ports at once:

npx kill-port 3000 3001 3002

For a more powerful tool with search:

npx fkill-cli


PS: They use third party javascript packages. npx comes built in with Node.js.

Sources: tweet | github

Bruno Lemos
  • 8,847
  • 5
  • 40
  • 51
  • Can you share details on installing npx using brew? I tried installing it on my Mac High Sierra, 10.13.3 and it won't work. – realPK Oct 11 '18 at 22:44
  • 1
    @realPK `npx` comes with `npm` which comes with `node.js`, so it's not a separated package. Just upgrade your node.js and your npm versions. – Bruno Lemos Oct 12 '18 at 08:40
  • I do Java mostly, haven't exposed myself to Node yet. I found a different way of killing service running on port. TY for responding. – realPK Oct 13 '18 at 22:58
  • 13
    The need for NodeJS and JavaScript, to kill something running on port 3000 probably rails... seems like too much overhead to me. adding a simple line to your .bashrc or .zshrc with an alias would solve it without the need for the internet. alias kill3000='lsof -ti:3000 | xargs kill' then you can do: kill3000 – Khalil Gharbaoui Jan 09 '19 at 11:19
  • 1
    works flawlessly! – Gaurav Aug 25 '22 at 14:37
199

A one-liner to extract the PID of the process using port 3000 and kill it.

lsof -ti:3000 | xargs kill

The -t flag removes everything but the PID from the lsof output, making it easy to kill it.

Zlemini
  • 4,827
  • 2
  • 21
  • 23
  • 14
    You can filter out "listening" ports with: `lsof -ti:3000 -sTCP:LISTEN` – Zlemini May 22 '18 at 21:58
  • 2
    This method works best for me. Simple one liner that clears the busy port. Thanks! – Ryan Trainor Dec 03 '19 at 20:34
  • 1
    I added a couple of functions to my profile based on this ```sh port-kill() { lsof -ti :"$1" | xargs kill -9; } # give process a chance to gracefully quit port-quit() { lsof -ti :"$1" | xargs kill -QUIT; } ``` – What Would Be Cool Mar 17 '23 at 11:47
169

You can use lsof -i:3000.

That is "List Open Files". This gives you a list of the processes and which files and ports they use.

alex
  • 479,566
  • 201
  • 878
  • 984
DerMike
  • 15,594
  • 13
  • 50
  • 63
  • This is a great way to find it, can you update your answer to include the easiest way to kill the command? – CWSites Apr 19 '23 at 17:39
81

To forcefully kill a process like that, use the following command

lsof -n -i4TCP:3000  

OR lsof -i:3000

Where 3000 is the port number the process is running at

this returns the process id(PID) and run

kill -9 "PID"

Replace PID with the number you get after running the first command

For Instance, if I want kill the process running on port 8080

Why kill -9 PID does not work? If you trying to kill a process with its PID and it still runs on another PID, it looks like you have started that process in a different account most probably root account. so Login in with sudo su and kill it

Tadele Ayelegn
  • 4,126
  • 1
  • 35
  • 30
  • I tried creating an alias in ZSH: alias port="lsof -n -i4TCP:$1" and got the following error... How to achieve this? $ port 8080 lsof: unacceptable port specification in: -i 4TCP: – fotoflo Dec 14 '20 at 10:43
67

In your .bash_profile, create a shortcut for terminate the 3000 process:

terminate(){
  lsof -P | grep ':3000' | awk '{print $2}' | xargs kill -9 
}

Then, call $terminate if it's blocked.

alex
  • 479,566
  • 201
  • 878
  • 984
alexzg
  • 845
  • 8
  • 8
62

To kill multi ports.

$ npx kill-port 3000 8080 8081

Process on port 3000 killed
Process on port 8080 killed
Process on port 8081 killed

Hope this help!

Binh Ho
  • 3,690
  • 1
  • 31
  • 31
49
lsof -P | grep ':3000' | awk '{print $2}'

This will give you just the pid, tested on MacOS.

Kris
  • 19,188
  • 9
  • 91
  • 111
40

Execute in command line on OS-X El Captain:

kill -kill `lsof -t -i tcp:3000`

Terse option of lsof returns just the PID.

JE42
  • 4,881
  • 6
  • 41
  • 51
33

One of the ways to kill a process on a port is to use the python library: freeport (https://pypi.python.org/pypi/freeport/0.1.9) . Once installed, simply:

# install freeport
pip install freeport

# Once freeport is installed, use it as follows
$ freeport 3000
Port 3000 is free. Process 16130 killed successfully
YBathia
  • 894
  • 1
  • 8
  • 18
  • 7
    That's, by far, NOT the simplest way. The upvoted replies don't require you to download and install anything. – Greg Pasquariello May 25 '16 at 19:20
  • 4
    When the prerequisites are met this is so simple and easy to remember. We have a different definition of "simplest" and this answer is perfectly valid and appropriate. Maybe it's just missing the instructions to install freeport with pip. – Cyril Duchon-Doris Jul 19 '17 at 15:18
  • under the hood, freeport is just a wrapper that calls `lsof -t -i:3000`.. seems unnecessary. – Corey Goldberg Nov 16 '18 at 17:01
  • 1
    This solution is not the easiest, but it complies 100% with what the OP asked... So it is in deed valid AF – danielrvt Nov 21 '18 at 15:11
32

To view the processes blocking the port:

netstat -vanp tcp | grep 3000

To Kill the processes blocking the port:

kill $(lsof -t -i :3000)

Henry
  • 17,490
  • 7
  • 63
  • 98
  • This won't work on a Mac machine, returns the following: `kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]` It will, however, work in most linux distros – Milan Velebit Sep 19 '18 at 12:08
  • 1
    @MilanVelebit Actually it works perfectly in my Mac machine (Sierra). It works fine if your port `3000` is occupied. However if no processes is blocking the port, then you will get `kill: not enough arguments` error. – Henry Sep 19 '18 at 14:24
  • That's just weird, I've two Macs (both High Sierra tho), I remember running those commands on both of them (old habits) and I know for certain that they don't run. I've just tried it again on my machine, knowing that the port is occupied, same error. :/ – Milan Velebit Sep 19 '18 at 14:33
  • Did you get a valid PID on running `netstat -vanp tcp | grep 3000`, for your port that's occupied? – Henry Sep 19 '18 at 14:46
  • I ran a `lsof -i :portname`, returned the process. Same goes for the `netstat` command, both output the process occupying the port correctly. – Milan Velebit Sep 19 '18 at 14:49
  • 1
    I tried it in both `bash` and `zsh` shell. Works fine for me. Not sure why it's not working for you. May be some thing to with High Sierra? I have no idea :/ – Henry Sep 19 '18 at 15:27
27

Find and kill:

This single command line is easy and works correctly.

kill -9 $(lsof -ti tcp:3000)
Dylan Breugne
  • 455
  • 4
  • 7
26

Find the open connection

lsof -i -P | grep -i "listen"

Kill by process ID

kill -9 'PID'

Sourabh Bhagat
  • 1,691
  • 17
  • 20
18

Possible ways to achieve this:

top

The top command is the traditional way to view your system’s resource usage and see the processes that are taking up the most system resources. Top displays a list of processes, with the ones using the most CPU at the top.

ps

The ps command lists running processes. The following command lists all processes running on your system:

ps -A

You could also pipe the output through grep to search for a specific process without using any other commands. The following command would search for the Firefox process:

ps -A | grep firefox

The most common way of passing signals to a program is with the kill command.

kill PID_of_target_process

lsof

List of all open files and the processes that opened them.

lsof -i -P | grep -i "listen"
kill -9 PID

or

 lsof -i tcp:3000 
smooth
  • 185
  • 2
  • 6
13

lsof -i tcp:port_number - will list the process running on that port

kill -9 PID - will kill the process

in your case, it will be

lsof -i tcp:3000 from your terminal find the PID of process

kill -9 PID

Shan
  • 613
  • 9
  • 21
12

I made a little function for this, add it to your rc file (.bashrc, .zshrc or whatever)

function kill-by-port {
  if [ "$1" != "" ]
  then
    kill -9 $(lsof -ni tcp:"$1" | awk 'FNR==2{print $2}')
  else
    echo "Missing argument! Usage: kill-by-port $PORT"
  fi
}

then you can just type kill-by-port 3000 to kill your rails server (substituting 3000 for whatever port it's running on)

failing that, you could always just type kill -9 $(cat tmp/pids/server.pid) from the rails root directory

Caleb Keene
  • 379
  • 2
  • 7
12

These two commands will help you find and kill server process

  1. lsof -wni tcp:3000
  2. kill -9 pid
Akj
  • 7,038
  • 3
  • 28
  • 40
Saif chaudhry
  • 409
  • 3
  • 10
9
kill -9 $(lsof -ti:3000)

works for me on macOS always.

If you're working on a node.js project, you can add it to package.json scripts like;

"scripts": {
    ...
    "killme": "kill -9 $(lsof -ti:3000)",
    ...
  },

then

npm run killme

--

Also if you want to add system wide alias for your macOS, follow these steps;

Navigate to your home directory:

cd ~

Open up .bash_profile or zsh profile using nano or vim:

vi .bash_profile

Add an alias (press i):

alias killme="kill -9 $(lsof -ti:3000)"

save file

restart terminal

type killme to the terminal

Of course you can change port 3000 to what you want.

hakki
  • 6,181
  • 6
  • 62
  • 106
7

Add to ~/.bash_profile:

function killTcpListen () {
  kill -QUIT $(sudo lsof -sTCP:LISTEN -i tcp:$1 -t)
}

Then source ~/.bash_profile and run

killTcpListen 8080

rofrol
  • 14,438
  • 7
  • 79
  • 77
6

Using sindresorhus's fkill tool, you can do this:

$ fkill :3000
Kodie Grantham
  • 1,963
  • 2
  • 17
  • 27
5

Works for me for terminating node (Mac OS Catalina)

killall -9 node
Abdul Saleem
  • 10,098
  • 5
  • 45
  • 45
4

TL;DR:

lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill

If you're in a situation where there are both clients and servers using the port, e.g.:

$ lsof -i tcp:3000
COMMAND     PID         USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node       2043 benjiegillam   21u  IPv4 0xb1b4330c68e5ad61      0t0  TCP localhost:3000->localhost:52557 (ESTABLISHED)
node       2043 benjiegillam   22u  IPv4 0xb1b4330c8d393021      0t0  TCP localhost:3000->localhost:52344 (ESTABLISHED)
node       2043 benjiegillam   25u  IPv4 0xb1b4330c8eaf16c1      0t0  TCP localhost:3000 (LISTEN)
Google    99004 benjiegillam  125u  IPv4 0xb1b4330c8bb05021      0t0  TCP localhost:52557->localhost:3000 (ESTABLISHED)
Google    99004 benjiegillam  216u  IPv4 0xb1b4330c8e5ea6c1      0t0  TCP localhost:52344->localhost:3000 (ESTABLISHED)

then you probably don't want to kill both.

In this situation you can use -sTCP:LISTEN to only show the pid of processes that are listening. Combining this with the -t terse format you can automatically kill the process:

lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill
Benjie
  • 7,701
  • 5
  • 29
  • 44
3

Here's a helper bash function to kill multiple processes by name or port

fkill() {
  for i in $@;do export q=$i;if [[ $i == :* ]];then lsof -i$i|sed -n '1!p';
  else ps aux|grep -i $i|grep -v grep;fi|awk '{print $2}'|\
  xargs -I@ sh -c 'kill -9 @&&printf "X %s->%s\n" $q @';done
}

Usage:

$ fkill [process name] [process port]

Example:

$ fkill someapp :8080 node :3333 :9000
Miguel Mota
  • 20,135
  • 5
  • 45
  • 64
3

You can try this

netstat -vanp tcp | grep 3000
Foram
  • 483
  • 5
  • 12
3

I use:

lsof -wni tcp:3000

Get the PID, and:

kill -9 <PID>

Sahu
  • 183
  • 2
  • 9
3

my fav one-liner: sudo kill `sudo lsof -t -i:3000`

inexcitus
  • 2,471
  • 2
  • 26
  • 41
LowFieldTheory
  • 1,722
  • 1
  • 26
  • 39
3

To kill port 3000 on mac, run the below command

kill -9 $(lsof -t -i:3000 -sTCP:LISTEN)

Sachin
  • 911
  • 8
  • 12
2

You should try this, This technique is OS Independent.

In side your application there is a folder called tmp, inside that there is an another folder called pids. That file contains the server pid file. Simply delete that file. port automatically kill itself.

I think this is the easy way.

Arun P
  • 55
  • 2
2

If you want a code free way - open activity manager and force kill node :)

HannahCarney
  • 3,441
  • 2
  • 26
  • 32
2

I use this:

cat tmp/pids/server.pid | pbcopy

Then kill -9 'paste'

2

just write on terminal

sudo kill -9 $(lsof -i :3000 -t)

hope , it's work.

1

Explanation of steps with terminal o/p

I have Macbook Pro (Catalina), 1 day I found the below issue while running the Django server (which runs on port 8000 by default):

python manage.py runserver 3000

(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ python manage.py runserver 3000
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
July 27, 2021 - 23:54:05
Django version 3.2.3, using settings 'automated_classification.settings'
Starting development server at http://127.0.0.1:3000/
Quit the server with CONTROL-C.
Error: That port is already in use.

I tried to use the provided and executed but running only 1 of them was not solving my problem (I know there were some other answers too but somehow I solved my problem). E.g. I tried to rerun the above command but that too did not work (still the processes were active).

So I finally I used answer of @Cris with 1 more additional step as he & others have suggested. So my answer is just using their commands with Terminal output to make the executions more clearer to you.

lsof -P | grep ':3000' | awk '{print $2}'

(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ lsof -P | grep ':3000' | awk '{print $2}' 
36239
38272  

Now I got the list of ids to kill, let's do.

kill -9 <PID>

(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ kill -9 36239
(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ kill -9 36239
-bash: kill: (36239) - No such process
(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ kill -9 38272
(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ kill -9 38272
-bash: kill: (38272) - No such process

And now, let's try to rerun the command.

python manage.py runserver 3000

(venv) Rishikeshs-MacBook-Pro:learn-django hygull$ python manage.py runserver 3000
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
July 27, 2021 - 23:55:53
Django version 3.2.3, using settings 'project.settings'
Starting development server at http://127.0.0.1:3000/
Quit the server with CONTROL-C.

FINAL

kill -9 $(lsof -P | grep ':3000' | awk '{print $2}')

You can combine the above 2 steps in 1 line & execute to kill process listening on port 3000.

hygull
  • 8,464
  • 2
  • 43
  • 52
1

After executing the kill commands, deleting the pid file might be necessary:

rm ~/mypath/myrailsapp/tmp/pids/server.pid
0

If you're using Zsh, and don't want to remember multi-pipe commands, just add next lines of code to ~/.zshrc:

function murder() {
    lsof -nti:$1 | xargs kill -9
}

And then any time you need to kill a process on a specific port, just use:

murder 3000

P.S feel free to rename the command and improve it :)

Dmytro Chaban
  • 1,106
  • 1
  • 11
  • 19
-1

Step 1: Find server which are running: ps aux | grep puma Step 2: Kill those server Kill -9 [server number]

-3

In mac OS

kill -9 $(lsof -i TCP:3000 | grep LISTEN | awk '{print $2}')

NoughT
  • 675
  • 4
  • 20
  • 39
-10

You should try this code using the terminal:

$ killall -9 ruby
Murmel
  • 5,402
  • 47
  • 53