0

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.

5
  • The question you want to ask is, is it safe to kill these processes? (The ports themselves can't get "hurt" by killing a process, but the process can lose data.) However, the question you should ask yourself is, How do I reserve the port I want, so nothing else uses it? You probably need to reconfigure apache and/or this afs3 fileserver application... or, just choose another, unused port.
    – jpaugh
    Oct 30, 2019 at 16:09
  • 1
    You are listing both ipv4 and ipv6 sockets at port 7000. It looks like you want just the ipv6 ones (-i6 flag for lsof). But it's not a good idea to have different processes listening on the same port on different stacks (because one day you could decide to go dual-stack). You might consider moving one of them to their own port. Oct 30, 2019 at 16:11
  • @EduardoTrápani It looks to me that this already is dual-stack. Check the string on the end of the IPv4 address: 127.0.0.1:afs3-fileserver . But, your comment is still useful; I didn't even realize it was IPv6 at first.
    – jpaugh
    Oct 30, 2019 at 16:12
  • @jpaug I meant dual-stacking the service (ie, listening on both stacks). The system is obviously already using both stacks. Oct 30, 2019 at 16:14
  • @EduardoTrápani Nevermind, I was misreading the output of that command. I realize now that :adfs3-fileserver just meant port 7000.
    – jpaugh
    Oct 30, 2019 at 16:19

0

You must log in to answer this question.

Browse other questions tagged .