Linux的fuser命令解析

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 的返回值:

fuser如果沒有找到任何進程正在使用指定的file, filesystem 或 socket, 或者在查找過程中發生了fatal error,則返回non-zero 值。

fuser如果找到至少一個進程正在使用指定的file, filesystem 或 socket,則返回zero。

fuser 常用場景

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

fuser的其他有用的參數

-k
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
-i
interactive mode. Prompt before killing process
-v
verbose.
-u
append username
-a
display all files
-m
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 toname/. to use any file system that might be mounted on that directory.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章