Search code examples
linuxshellubuntukillfuser

Shell Script for Killing PID


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.


Solution

  • 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.