One of the most important tasks in Linux system administration is process management. These are various operations under monitoring, signaling processes, as well as prioritizing processes in the system.
There are numerous Linux tools/utilities designed to monitor/manage processes like top, ps, pgrep, kill, killall, nice along with many others.
In this article, we will discover how to find processes using a nifty Linux utility called fuser.
fuser is a simple but powerful command line utility intended to locate processes based on the files, directories or sockets that a particular process accesses. In short, it helps a system user to identify processes using files or sockets.
How to use fuser on Linux systems
The conventional syntax to use fuser es:
# fuser [opciones] [archivo|socket] # fuser [opciones] -SIGNAL [archivo|socket] # fuser -l
Below are some examples of usage to fuse to locate processes on your system.
Find which process accesses a directory
run command fuser without any option will show the PID of processes currently accessing your current working directory.
$ fuser . O $ fuser /home/javier
Find running processes in the directory
For more detailed and clear output, enable -v
o --verbose
in the following way. At the exit, fuser prints the name of the current directory, then the process owner columns ( USER ), the process ID ( PID ), the type of access ( ACCESS ) and the command ( COMMAND ) as in the image below.
$ fuser -v
Directory list of running processes
under the column ACCESSyou will see the types of access indicated by the following letters:
c
– current directorye
– an executable file that is runningf
– open file, however, f omitted in outputF
– open file for writing, F is also excluded from the outputr
– root directorym
– mmap’ed file or shared library
Find which process accesses a file system
You can then determine which processes are accessing your file ~.bashrc
as follows:
$ fuser -v -m .bashrc
The option -m
Name or --mount
NAME means name all processes that access the file NAME. In case you spell a directory like NAMEspontaneously changes to NAME/
to use whatever filesystem is possibly mounted on that directory.
How to kill and flag processes using the fuser
In this section we will work using fuser to remove and send signals to processes.
To kill processes accessing a file or socket, use the option -k
o --kill
So:
$sudo fuser -k .
To kill a process interactively, where you are prompted to confirm your intention to kill processes accessing a file or socket, use option -i
O --interactive
:
$sudo fuser -ki .
Interactive removal process on Linux
The two previous commands they will eliminate all processes accessing its current directory, the default signal sent to processes is SIGKILLexcept when used -SIGNAL.
You can list all the signals using the options -l
o --list-signals
as it’s shown in the following:
$ sudo fuser --list-signals
List all signs of removal process
So you can send a signal to the processes as in the following command, where SIGNAL is any of the signals listed in the previous output.
$ sudo fuser -k -SEÑAL
For example, this command below sends the signal HUP to all processes that have its directory /boot
open.
$ sudo fuser -k -HUP /boot
Try reading the man page of the fuser for advanced usage options and additional, more detailed information.
That’s all for now, you can reach out to us via the comments section below for any help you need or suggestions you want to make.