This is my problem. I'm running a Node.JS API on a Debian server using Nodemon (Because I'm currently programming on my server) and that API is on a Apache Virtual Host using a reverse proxy.
I use nodemon because every change that I make to my code restarts my node.js app but sometimes it fails, and a error occurs that says that there is already a software running on that port (my port is 7000) so I stop nodemon and I kill the process.
$ sudo lsof -n -i :7000 | grep node
node 70690 root 43u IPv6 112373950 0t0 TCP *:afs3-fileserver (LISTEN)
$ sudo kill 9 70690
First I use lsof
to find the PID that runs over the port 7000 and then I use kill that PID. But if I don't use grep
along with lsof
it gives me more than one PID running on that port.
$ sudo lsof -n -i :7000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
apache2 69823 www-data 21u IPv4 112364929 0t0 TCP 127.0.0.1:55210->127.0.0.1:afs3-fileserver (CLOSE_WAIT)
apache2 69825 www-data 21u IPv4 112364926 0t0 TCP 127.0.0.1:55208->127.0.0.1:afs3-fileserver (CLOSE_WAIT)
apache2 70051 www-data 21u IPv4 112365069 0t0 TCP 127.0.0.1:55232->127.0.0.1:afs3-fileserver (CLOSE_WAIT)
node 70690 root 43u IPv6 112373950 0t0 TCP *:afs3-fileserver (LISTEN)
I would like to use $ sudo lsof -ti :7000
to get only the list of PID and then use that with xargs
to kill them all. But I don't know if that would cause problems because according to the latest command some of these process are from apache2.
127.0.0.1:afs3-fileserver
. But, your comment is still useful; I didn't even realize it was IPv6 at first.:adfs3-fileserver
just meant port7000
.