Which processes accessing which files?

Fuser is very powerful utility which identify process using files or sockets.It
lists the process numbers of local processes that use the local or remote files specified by the File parameter. For block special devices, the command
lists the processes that use any file on that device.

Sometimes you may want to know which process is accessing a particular file or filesystem — for example, if you get a "device is busy" error message. fuser will provide this information:

PID accessing the file

[root@localhost ~]# fuser /var/log/messages
/var/log/messages: 2255

Want to see which user is using it:

More Detail Info:

F indicates that the file is open file.
syslogd indicates command being used to access the file.

Which all processes accessing the file system?

The -m switch shows all process accessing the filesystem, which the file is on; or you can simply specify a filesystem rather than a file. So fuser -m /dev/sdb1 output looks like:

/dev/sdb1: 18647c 16875m 7122c 19579m 1606c 7258c 5760c 13644

To kill all processes accessing a particular file

Use fuser -k filename.txt

(add -i for a confirmation message before each kill).

You can also use fuser on network ports: fuser -n tcp 21. This will show which process is using port 21 (useful if you get a 'port busy' message).

Linux fuser command to forcefully unmount a disk partition:

Suppose you have /dev/sda1 mounted on /mnt directory then you can use fuser command as follows:

Type the command to unmount /mnt forcefully:
# fuser -km /mnt

No comments:

Post a Comment