fuser指令是用來顯示所有正在使用着指定的file, file system 或者 sockets的程序資訊。
例一:
#fuser –m –u /mnt/usb1
/mnt/usb1: 1347c(root) 1348c(guido) 1349c(guido)
在例子一中,使用了-m和-u選項,用來查找所有正在使用/mnt/usb1的所有程序的PID已經該程序的OWNER,如1347c(root),其中1347是程序PID,root是該程序的OWNER。
fuser會顯示正在使用指定的file,file system 或者 sockets的程序的PID。在預設的顯示模式下,每個檔案名之後會跟随一個字元,用來訓示目前的通路類型。
如下所示:
c current directory.e executable being run.f open file.F open file for writing.r root directory.m mmap'ed file or shared library
同時fuser 可以用來查找哪些程序正在使用指定的network port。
[root@bl25p-19 /]# fuser -v -n tcp 111
USER PID ACCESS COMMAND
111/tcp: rpc 2848 F.... portmap
fuser如果沒有找到任何程序正在使用指定的file, filesystem 或 socket, 或者在查找過程中發生了fatal error,則傳回non-zero 值。
fuser如果找到至少一個程序正在使用指定的file, filesystem 或 socket,則傳回zero。
fuser通常被用在診斷系統的“resource busy”問題,通常是在你希望umount指定的挂載點得時候遇到。 如果你希望kill所有正在使用某一指定的file, file system or sockets的程序的時候,你可以使用-k option。
fuser –k /path/to/your/filename
這時fuser會向是以正在使用/path/to/your/filename的程序發送SIGKILL。如果你希望在發送之前得到提示,可以使用-i 選項。
fuser –k –i /path/to/your/filename
<dl></dl>
<dt>-k </dt>
<dd>kills all process accessing a file. For example fuser -k /path/to/your/filename kills all processes accessing this directory without confirmation. Use -i for confirmation</dd>
<dt>-i </dt>
<dd>interactive mode. Prompt before killing process</dd>
<dt>-v </dt>
<dd>verbose.</dd>
<dt>-u </dt>
<dd>append username</dd>
<dt>-a </dt>
<dd>display all files</dd>
<dt>-m </dt>
<dd></dd>
name specifies a file on a mounted file system or a block device that is mounted. All processes accessing files on that file system are listed. If a directory file is specified, it is automatically changed to name/. to use any file system that might be mounted on that directory.
<dd> </dd>
[1] man fuser