Fuser

From LQWiki
Jump to navigation Jump to search

fuser lists which processes are using a file, port or a filesystem, and can optionally automatically kill them. It is particularly useful when attempting to unmount a partition, attach to a port or play sound but the device or file is already in use.

The following will list the pids using file:

fuser file

To make fuser work on an entire filesystem use -m option. Almost all the options can be combined with -m.

fuser -m directory

lists all the pids using the filesystem mounted in that directory.

One of the more overlooked parts of fuser is the fact that aside from acting with files and filesystems it also performs the same actions on ports.

fuser -n [udp|tcp] (port #)

To make fuser more verbose, i.e. show who owns the processes, show the process name, etc., use the -v option.

fuser -v file

Testing if something is used is also useful, especially for shell scripts.

fuser -s file

Finally, one of the more useful parts of fuser is the ability to kill every process using a certain file (or filesystem for a quick umount)

fuser -k file

See also