Find and kill running process in Linux

There are a several ways to kill process in linux, all of them are very straightforward, you can choose which ways that suitable for you, Because sometime you just need kill process that using a certain port or just kill application directly. On this article, I will only discuss 3 of them. Be wisely, just stopping process that you know and do not be carelessly, stopping process that related to operating system could mess up your day 🙂

As far as we know, all operating system (without exception) have limited resources. Include of memory, port, storage, etc. What should we do is ensure all those resources comply with our needs. There are a condition that we got hang in our apps and operating system needs time to recover those resources. For example, I am using web server (tomcat) that use port 8181, then my tomcat get crash/hang. what should I do is shut down the tomcat service and start again. Unfortunately, the operating system still booked port 8181, With this condition, we have an option to kill that port by our self or just waiting until operating system realized this problem and clear that port. If your choice is kill the port by your self, here we go :

Using fuser

If you have known what port that should be stop, just open terminal or press CTRL+ALT+T, then use the following command :

$fuser -k 8181/tcp

the command above will kill the process, to check whether the port have been free, you can use this :

$fuser 8181/tcp

Using netstat

Open your terminal or press CTRL +ALT+T, then use the following command :

$netstat -anp | grep 8181

with netstat, you will get more detail information about the port. for example :

tcp ? ? ? ?0 ? ? ?0 ? ? ? ? ? ? ? ?* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?16360/java

the PID number is 16360, After you are sure that everything is OK. just kill the port with this command :

$sudo kill -9 16360

Using History of application

This way is my favorite, I just need the name of application, with the following command :

$ps -ef | grep tomcat

the output would be like this :

kusa ? ? 16660 ? ? 1 14 13:29 pts/2 ? ?00:00:04

the PID number is 16660, same way as before. Just kill the apps using the PID information :

$sudo kill -9 16360

That’s all, The first and the second way is used when you have known the port already. very simple. just like shooting fish in a barrel 🙂

Write a Comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.