1

I am collaborating on a deploy using sudo with ssh access to aws ec2 instance.

The application starts up and throws the error

Error: listen EADDRINUSE :::4000

if I do:

sudo fuser 4000/tcp

I get:

4000/tcp:             1669

If I do:

sudo fuser -i -k 4000/tcp

I get:

4000/tcp:             1669 Kill process 1669 ? (y/N)

If I do:

y

It doesn't kill the port. I have stopped the app as well of course.


I don't have netstat.

Is this a privilege thing with the root access? I would try to change the port number but don't have that access right now.

Is there anything else I can try?

thanks

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
godhar
  • 1,128
  • 1
  • 14
  • 34

1 Answers1

2

You can do this using a combination of kill and lsof.

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

Which tells the os to terminate the process using port 4000.

Craig van Tonder
  • 7,497
  • 18
  • 64
  • 109
  • If I do that above command and then run `lsof -i:4000` it outputs that the port is still running with **COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME node\x20/ 21387 pavlos 19u IPv6 102232168 0t0 TCP *:4000 (LISTEN)** – godhar Mar 22 '19 at 14:35
  • Now when I do `sudo kill -9 PID_NUM` it just finds another PID to open. This is mad. – godhar Mar 22 '19 at 14:46
  • Any ideas @Craig ? – godhar Mar 22 '19 at 16:37
  • 1
    @godhar What os, do you use something like forever to keep the process up? The ls command should output the pid of the process which uses that port, if it reopens when killed, how did you start the process? – Craig van Tonder Mar 23 '19 at 18:05
  • it turns out the other user kept running the app on the linux machine. I was trying to kill the process then it would must find another PID. Interesting that often the solution is the most obvious one. thanks – godhar Mar 24 '19 at 20:06