How to end an old session in iTerm2

Maybe a stupid question with an obvious answer, but I don't know a solution. I am new to the command line, especially Apple and iTerm2.

In iTerm2, I open a new session for my PHP project using php -S localhost:port

Now I accidentally closed this tab once, and now I don’t know how to end this session. When I want to open another project on this port ( 8000 ), it says, of course, Failed to listen on 127.0.0.1:8000 (reason: Address already in use)

Can someone help me on how to end this session, so I can start another project on this port instead of using 8001, 8002, 8003, etc.

Thanks in advance

+5
source share
2 answers

I fixed it myself, but since I cannot be the only one who is asking this, here is my solution:

Enter this into the terminal:

 lsof -i TCP:8000 

This will produce a result that might look something like this:

 renaebair@siren ~/workspace/intridea/newsite (master) β†’ lsof -i TCP:3000 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME ruby 68780 renaebair 6u IPv4 0x10898278 0t0 TCP *:hbci (LISTEN) 

Take the process number (aka PID) (in this case it was 68780), and then enter "kill #{that_pid}" :

 kill 68780 

Then try restarting the server and everything should be fine!

+11
source

I think this might work, at least on my unix machine.

 sudo kill $(fuser -n tcp 8000 2> /dev/null) 
+1
source

Source: https://habr.com/ru/post/1207382/


All Articles