Linux System Administration - X


Add to my manuals
368 Pages

advertisement

Linux System Administration - X | Manualzz

troubleshooting tools

8.2. fuser

The fuser command will display the 'user' of a file system.

In this example we still have a vi process in background and we use fuser to find the process id of the process using this file system.

[root@RHEL65 ~]# jobs

[1]+ Stopped vi /srv/project33/busyfile.txt

[root@RHEL65 ~]# fuser -m /srv/project33/

/srv/project33/: 3243

Adding the -u switch will also display the user name.

[root@RHEL65 ~]# fuser -m -u /srv/project33/

/srv/project33/: 3243(root)

You can quickly kill all processes that are using a specific file (or directory) with the -k switch.

[root@RHEL65 ~]# fuser -m -k -u /srv/project33/

/srv/project33/: 3243(root)

[1]+ Killed vi /srv/project33/busyfile.txt

[root@RHEL65 ~]# fuser -m -u /srv/project33/

[root@RHEL65 ~]#

This example shows all processes that are using the current directory (bash and vi in this case).

root@debian7:~/test42# vi file42

[1]+ Stopped vi file42 root@debian7:~/test42# fuser -v .

USER PID ACCESS COMMAND

/root/test42: root 2909 ..c.. bash

root 3113 ..c.. vi

This example shows that the vi command actually accesses /usr/bin/vim.basic as an

executable file.

root@debian7:~/test42# fuser -v $(which vi)

USER PID ACCESS COMMAND

/usr/bin/vim.basic: root 3113 ...e. vi

The last example shows how to find the process that is accessing a specific file.

[root@RHEL65 ~]# vi /srv/project33/busyfile.txt

[1]+ Stopped vi /srv/project33/busyfile.txt

[root@RHEL65 ~]# fuser -v -m /srv/project33/busyfile.txt

USER PID ACCESS COMMAND

/srv/project33/busyfile.txt:

root 13938 F.... vi

[root@RHEL65 ~]# ps -fp 13938

UID PID PPID C STIME TTY TIME CMD root 13938 3110 0 15:47 pts/0 00:00:00 vi /srv/project33/busyfile.txt

77

advertisement

Was this manual useful for you? Yes No
Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Related manuals

advertisement

Table of contents