lsof Identify Resource Locked Process
Samba server comes with a handy utility called smbstatus to report users who are holding the shared resources.
Utilities used to find out processes that are locking system resources are among the most wanted system utilities for experienced users and system administrators. The lsof being one of such excellent utility that used to identify process or user that is locking system resource such as file or network socket.
For example, a system administrator could use the lsof -i to easily understand how the IBM MQ server communicate over the TCP/IP network with IBM Informix server. The lsof output, as in the diagram below, shows that the Informix oninit is listening to a user defined mnemonic port name stp which the IBM MQ server communicate with. The /etc/services system files is usually used to map a numeric port number to a descriptive port name defined by user.
Related information:
Each of the process id suffix with an ASCII character code which represent the resource access type. These resource access type codes are not standardize among various Linux distributions. To be safe and accurate, always consult the fuser man page to confirm the code definitions.
To check out what process ID is using TCP port 8080, execute the fuser as fuser -n tcp 8080 or fuser 8080/tcp
netstat -tulap
will shows both the program and process id that bind to the network port. The diagram below shows the commands output of lsof vs netstat.
Both of the commands displaying pseudo port name instead of numeric port number, where the mapping of pseudo port name and numeric port number is defined in /etc/services file.
The netstat command, however, able to display numeric port and IP address with -n option switch. For example, rewrite the command as netstat -tulapn
Note! Both netstat -tulap and lsof -i MUST be executed with root user account privileges, else nothing as those in the diagram above will be seen.
This article has 1 comments.
You may have your comments on this article too...
If you don't want to see a ton of garbage when you're just looking for the pid of a process using a specific port, use lsof -t -i tcp:*port_num*. Good to use in scripts!
So, feel free to write your comments for this article...