Open In App

fuser command in Linux

Last Updated : 02 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

fuser is a command line utility in Linux. fuser can identify the process using the files or sockets. This command can be also used to kill the process. In this article, we are going to see how to use the fuser command to list the processes and kill the processes associated with files and directories. Let’s see how to use the fuser command.

Using fuser command

The syntax of the fuser command is very simple. The syntax of the fuser command is as follows:

 fuser [options] [file|socket]
 fuser [options] -SIGNAL [file|socket]
 fuser -l 

While using the fuser command, always mention the filename or path of the filename with the fuser command.

Find Which Process Accessing a Directory

To list out all processes associated with a file or directory, just mention the filename or path of the directory or file with the fuser command. Here is one example:

fuser.

Or

fuser ~/

 

These are the processes that are using the ~/ directory.

For verbose output, use -v

The output of the previous command will only show the PIDs of the process, which very little information. To get more information about the processes, use the -v or –verbose option with the fuser command:

fuser -v .

 

The output of the fuser command with the -v option is containing the following fields:

  • USER:- user which owns the process.
  • PID:- PID of the process.
  • ACCESS:- Access type.
  • COMMAND:- Command which using the mentioned file or folder.

In the ACCESS column, the access type is represented using the following letters:

  • c :- represents the current directory.
  • e :- The file is executable, and it is currently running.
  • f :- open file.  f is omitted in default display mode.
  • F :- open file for writing.  F is omitted in default display mode.
  • r :- represents root directory.
  • m :- mapped file or shared library.
  • . :- Placeholder, omitted in default display mode.

Find Which Process Accessing A File System

To get the list of all processes which are using the file which is mentioned with the fuser command, use option -m or –mount. Here is one example:

fuser -v -m ~/.bashrc

 

 Check processes using an executable

We can also check the process using the executable files. To find the process which is using the executable file, first, we need to find out the path of the executable. So to find the path of the executable we can use the ‘which’ command

$ which executable_name

 

Now we can use the path given by thewhich’ command with the fuser command to find out the process associated with executable

 

In the above output, we can see the all process associated with the process spotify executable.

 Kill Processes that are Using a particular Program

We can use the fuser command to kill the processes. To kill the process using the fuser command, use the option -k or –kill with the command and mention the path of the program.

sudo fuser -k 

To kill a process interactively, use the option -i or –interactive with the above command. This command will ask while terminating each process.

sudo fuser -ki .

 

Sending a signal to process

We use the -k option to kill the process, then the SIGKILL is sent to the process. Now let’s see how to send other signals to process. First, to get a list of all available signals, use the following command:

 

To send the signal with the fuser command, mention the signal with character after option -k

sudo fuser -k -SIGNAL

Check Processes Using TCP/UDP Sockets

By using the fuser command, we can also check which process is using the given TCP/UDP sockets. We have to use the -n option followed by the port number with the fuser command.

 fuser -v -n tcp port_no

For example, we have one c program executable running on the port number 8080, and we have to find out which process uses the 8080 port, then we can use the following command

fuser -v -n tcp 8080

 

This is how we can use the fuser tool to manage processes. To know more about the fuser command, read the man page of the fuser.

man fuser 

 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads