LINUX :: Kill a Process Id by looking up the port
2 min read
We might always feel the need to find the process running on a specific port.
A classic example would be a default installation of Apache Tomcat which might not run successfully (i.e. default port 8080). One of the probability is that there might be already a process running on port 8080.
Following are some ways to find the port number for the relevant process
- netstat – a command-line tool that displays network connections, routing tables, and a number of network interface statistics.
- fuser – a command line tool to identify processes using files or sockets.
- lsof – a command line tool to list open files under Linux / UNIX to report a list of all open files and the processes that opened them.
- /proc/$pid/ file system – Under Linux /proc includes a directory for each running process (including kernel processes) at /proc/PID, containing information about that process, notably including the processes name that opened port.
Please run the following commands as root user (ie. "sudo")
netstat -tulpn | grep :8080
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1689/apacheSample
So the process id found is PID --> 1689
Linux and Unix-like operating system supports the standard terminate signals listed below:
SIGHUP (1) – Hangup detected on controlling terminal or death of controlling process. Use SIGHUP to reload configuration files and open/close log files.
SIGKILL (9) – Kill signal. Use SIGKILL as a last resort to kill process. This will not save data or cleaning kill the process.
SIGTERM (15) – Termination signal. This is the default and safest way to kill process.
What Linux or Unix permissions do I need to kill a process?
Rules are simple:
You can kill all your own process.
Only root user can kill system level process.
Only root user can kill process started by other users.
sudo kill 1689
sudo kill -15 1689
sudo kill -9 1689
Did you find this article valuable?
Support Manish Warang by becoming a sponsor. Any amount is appreciated!