Signup/Sign In

How to find the Process using a Port in Linux and Kill it?

Posted in Tricks   LAST UPDATED: SEPTEMBER 8, 2021

    While working with linux machines, running different applications, sometimes even though there is no application running, still some processes hold up the port they were running on which leads to unavailability of that post even though no application is running. To tackle such a situation, we must find the process which is occupying the port and then kill that process to free the port.

    To list down which port is currently being used or not, we can use the netstat command.

    netstat -a -o -n

    But this command list down all the ports along with all the connection statuses in which you will have to manually look for the port that you want to free.

    A better approach is to uset the fuser command to find the process id of the process using the port number.

    fuser [port number]/tcp
    

    In the above command change the [port number] with the port which you want to free, for example if you want to free the 8080 port, then run the following command to find the process id using that port:

    fuser 8080/tcp
    

    Once you get the process id for the process using that port, all you have to do is kill the process using the kill command.

    kill -9 [pid]

    The argument -9 is to forcefully kill the process.

    Hope this helps you to free the port being forcefully used by some rogue process.

    You may also like:

    About the author:
    This is the official profile of the Studytonight content team.
    Tags:Linux
    IF YOU LIKE IT, THEN SHARE IT
     

    RELATED POSTS