سؤال

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