How To Use the Linux Fuser Command | DigitalOcean

Introduction

The fuser command is a Linux utility designed to find which process is using a given file, directory, or socket. It also provides information about the user who owns the execution of that process and the type of access.

How to use the fuser

utility

You can review the fuser manual page for an overview of all the options for using with the fuser. You can also run the fuser on its own without any options to get an overview of the fuser syntax

: fuser OutputNo process specification given Usage:

  1. fuser

[-fMuv] [-a|-s] [-4|-6] [-c|-m|-n SPACE] [-k [-i] [-SIGNAL]] NAME… fuser -l fuser -V Show which processes are used by named files, sockets, or file systems. -a,-all also displays unused files -i,-interactive ask before killing (ignored without -k) -k,-kill kill processes accessing the named file -l,-list-signals list of available signal names -m,-mount display all processes that use the named file systems or block device -M,-ismountpoint fulfill the request only if NAME is a mount point -n,- namespace SPACE search this namespace (file, udp, or tcp) -s,-silent operation -SIGNAL send this signal instead of SIGKILL -u,-user display user IDs -v,-verbose verbose output -w,-writeonly kill only processes with write access -V,-version show version information -4,-ipv4 find only IPv4 sockets -6,-ipv6 find only IPv6 sockets – reset options UDP/TCP names: [local_port] [,[rmt_host][, [rmt_port]]]

How to view the processes running on a directory founder

can also be used with the -v option, which runs the tool in verbose mode. The detailed option is used to produce more output so that the user can observe what the fuser is doing. Run fuser in the current directory, ., while including the

-v:

  1. fuser -v option.

Output USER PID ACCESS COMMAND /home/sammy: sammy 17604.. c.. bash In this case, the only process running in this

directory is the interactive bash shell from which you are currently executing commands

.

When run in verbose mode, the fuser utility provides information about a process’s USER, PID, ACCESS, and COMMAND. The c character under ACCESS shows the type of access, in this case it means the current directory. There are other types of access, such as executable that is running, root directory, open file and mapped file or shared library.

How to Find Processes Using Network Sockets

You may also need to search for processes using TCP and UDP sockets. To demonstrate this example, you will first use nc to create a TCP listener on port 8002, so that there is a running process that you can observe: nc

  1. l -p 8002

This will block the terminal while it is running. In another terminal window, use fuser to find the process running on TCP port

8002 with the -n option:

  1. fuser -v -n

tcp 8002 Output USER PID ACCESS COMMAND 8002/tcp: sammy 17985 F…. nc

This output shows that the process identifier (PID) of the process that netcat uses is 17985 and the command that was used to start it is ‘nc’. The process identifier (PID) can be used in many ways, including to stop or delete a running process. You can learn more about process management by reading How to use ps, kill, and nice to Manage Processes in Linux. You can also use the fuser itself to kill processes running on specific ports using the –

k:

  1. fuser -k 8002/tcp flag Output8002/tcp: 18056

If you navigate back to your first terminal window, you will notice that the nc program has been removed and returned to the shell

.

The fuser utility can also be used to send specific signals to a process. When used with the -k option, the fuser command sends the KILL signal to a process. There are many other signals that can be sent to a specific execution process. You can list them with

fuser -l: fuser

  1. -l

OutputHUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR SYS

Conclusion

In this article, you learned some examples of uses of fuser to monitor ports and directories in use on a Linux system. fuser can be particularly useful when you’re trying to understand what unknown processes may be running on your system.

Next, you may want to learn how to use netstat and du to monitor other server resources.

Contact US