Вопрос

I run a few processes that I created myself on my Ubuntu Server, and to kill them I run:

sudo fuser -n tcp PORT
kill -9 PID-DISPLAYED

Is there any way I can obtain the PID from a port using a shell script, then kill it by running the shell script.

Thanks.

Это было полезно?

Решение

fuser can kill it:

 -k, --kill
     Kill processes accessing the file. Unless changed
     with -SIGNAL, SIGKILL is sent. An fuser process
     never kills itself, but may kill other fuser processes.
     The effective user ID of the process executing fuser is
     set to its real user ID before attempting to kill.

Другие советы

Try using either killall, or pkill, either of which will close all processes of the type of argument you describe, for example:

killall firefox

Will kill all running instances of firefox.

See this link of pkill.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top