Linux have a lot of tools to manage processes and network. But fuser
is one of the most popular tool which combines process and network management in a single command. fuser
can display process according to their directory, file and network handles. Also it can kill these process according to various parameter.
Syntax
fuser [options] [file|socket]
Help
$ fuser -h

Display Processes Using Directory
In daily usage of a server there will be a lot of users and processes. Finding related process about opened directory can be hard. fuser
command provides feature simply find related processes according to directory usage. In the example we will provide the directory path we want to inspect which is /home/ismail
. Best way to use fuser
is with root privileges
$ fuser /home/ismail

From output we can see that some process ID are printed. There is also some characters after PIDs. These are used to specify access type and information about the process. Here is what they mean
c
– current directorye
– executeable is runningf
– open fileF
– open file for writingr
– root directorym
– mmaped file or shared library
Display More Information Like User And Command
In the previous example we have only listed PID’s. But this information can not be enough some time. We may need more information like the user name and related command. To get user name and related command more verbose output is needed. Verbose output can be displayed with -v
option. In the example we will list information about directory access of processes with user and command information in a column based output.
$ fuser -v /home/ismail

In the example out we can see that our looking path is /home/ismail
and process id is 2548
which is the PID of bash
cmomand with user ismail
Display Processes Using File System
Process access information about the file system can be displayed with -m
option. This will create enormous amount of output.
$ fuser -v -m /home/ismail/.bashrc

Display Processes About TCP and UDP Sockets
Another useful feature of fuser
command is listing process information of TCP and UDP sockets. This can be very useful if our Apache web server do not starts because of the TCP 80 is used by another process we do not know. We can find this process easily. Furthermore this process can be killed with a single command which we will look below examples. In the example we want to list processes information listening TCP 22. We need root privileges to get information. We will provide -n
option with tcp 22
parameter
$ fuser -v -n tcp 22

In order to use with UDP ports look following command.
$ fuser -v -n udp 53
Kill Process Using Specified TCP Socket
As previously stated we can kill process by specifying TCP or UDP ports or sockets in a single command. We will provide -k
option to kill related process. In the example we will kill all ssh
or TCP port 22 process.
$ sudo fuser -k -n tcp 22

We can see that we have killed our current ssh connection to our server.
List Signals
In previous example we have killed the ssh process. Killing a process is done by sending signal to the process. Signals are used to communicate with process. To kill a process kill related signals are sent. There is also different type of signals those may send to the related process. We can list signals list-signals
option like below.
$ fuser -list-signals

Kill Process With Specific Signal
As we stated we can send specific signal to the process we have specified. In the example we will send -HUP
signal to the TCP 22 or ssh port with the following command.
$ sudo fuser -k -HUP -n tcp 22

Kill Process Interactively
While killing process in the critical servers we have no room for mistakes. But issuing fuser
command will execute command in real time without any caution. We can prevent mistakes and kill related processes in a more controlled way with interactive option. Interactive option is provided with -i
$ sudo fuser -i -k -n tcp 22

1 thought on “Linux fuser Command Tutorial With Examples”