【轉】fuser命令

楊奇龍發表於2011-04-15
fuser命令在linux系統中用來根據檔案或檔案結構識別程式。
使用許可權:超級使用者
語法格式:
  fuser [ -c | -d | -f ] [ -k | -K { SignalNumber | SignalName }] [ -u ] [ -x ] [ -V ]File ...
使用說明:
  此 fuser 命令列出了本地程式的程式號,那些本地程式使用 File 引數指定的本地或遠端檔案。
對於阻塞特別裝置,此命令列出了使用該裝置上任何檔案的程式。
每個程式號後面都跟隨一個字母,該字母指示程式如何使用檔案。
c 將此檔案作為當前目錄使用。
e 將此檔案作為程式的可執行物件使用。
r 將此檔案作為根目錄使用。
s 將此檔案作為共享庫(或其他可裝載物件)使用。
程式號被寫入標準輸出(在程式號之間有空格的行中)。
一個換行符被寫入標準錯誤(在每個檔案運算元的最後一個輸出之後)。其他所有輸出被寫入標準錯誤。
此 fuser 命令不會檢測有 mmap 區域的程式,其中相關的檔案描述符已從此被關閉。
主要引數:
  -c 包含 File 的檔案系統中關於任何開啟的檔案的報告。
  -d 暗示使用了 -c 和 -x 標誌。
關於任何與檔案系統(自父目錄刪除的)無連結的開啟檔案的報告。
當與 -V 標誌一起使用時,它也會報告被刪除檔案的節點號和大小。
-f 僅對檔案的開啟例項報告。
-K SignalNumber | SignalName 將指定訊號傳送到每個本地程式。
僅有 root 使用者能終止另一使用者的程式。訊號可以指定為訊號名稱(如 -9)或 KILL(用於 SIGKILL 訊號)。
SignalName 的有效值是 kill -l 命令所顯示的那些值。
-k 將 SIGKILL 訊號傳送到每個本地程式。僅有 root 使用者能終止另一使用者的程式。
注:
fuser -k 或 -K 可能無法檢測和殺死程式開始執行後立即建立的新程式。
-u 為程式號後圓括號中的本地程式提供登入名。
-V 提供詳細輸出。
-x 與 -c 或 -f 連用,報告除標準 fuser 輸出以外的可執行的和可載入的物件。
應用例項:
  要列出使用 /etc/passwd 檔案的本地程式的程式號,請輸入:
fuser /etc/passwd
要列出使用 /etc/filesystems 檔案的程式的程式號和使用者登入名,請輸入:
fuser -u /etc/filesystems
要列出正在使用已從給定檔案系統刪除的檔案的全部程式,請輸入:
fuser -d /usr
fuser -km /home
kills all   processes   accessing   the   file system /home in any way.
if fuser -s /dev/ttyS1; then :; else something; fi
invokes something if no other process is using /dev/ttyS1.
fuser telnet/tcp
shows all processes at the (local) TELNET port.
fuser [-a|-s] [-n space] [-signal] [-kimuv] name ...   [-]
[-n space] [-signal] [-kimuv] name ...
fuser -l
fuser -V
c    current directory.
e    executable being run.
f    open   file.   f is omitted in default display mode.
r    root directory.
m    mmap'ed file or shared library.
List Open Files: lsof and fuser-程式相關
The function of these commands is very similar. The goal is to determine what processes have certain files open. lsof is freeware
and thus freely compilable under all Unixes. It is available by default under Linux only.
The main difference between lsof and fuser is that lsof takes both files/filesystems and PIDs as arguments whereas fuser only
accepts files/filesystems.
lsof:
lsof stands for list open files. It lists information about files that are currently open by processes.
In the absence of any options, lsof lists all open files belonging to all active processes
To list all open files for login name ``abe'', or user ID 1234 you would use the -u option. To list files being used by process
456, process 123, or process 789, you would use the -p flag. Putting these criteria together, we would have a command that looks
like this:
lsof -p 456,123,789 -u 1234,abe
The command to list all open files on device /dev/hd4, would look like this:
lsof /dev/hd4
To find the process that has /u/abe/foo open, use:
lsof /u/abe/foo
fuser:
fuser is more widely available (under AIX, HP-UX, IRIX, Linux, Solaris, Tru64 UNIX, and others) and can only be run as root. It
displays the process ID numbers of processes using the specified files or file systems. In the default display mode, each file
name is followed by a letter denoting the type of access (these codes differ from vendor to vendor):
a if the process is using the file as its trace file in /proc (IRIX)
c if the process is using the file as its current directory
e if the process is using the file as the executable being run
f if the process is using the file as an open file (Linux)
m if the process is using the file as a mmaped or shared lib (Linux)
o if the process is using the file as an open file (IRIX, Solaris, Tru64 UNIX))
p if the process is using the file as the parent of its current directory (Tru64 UNIX)
r if the process is using the file as root directory
s if the process is using the file as a shared lib (AIX)
t if the process is using the file as its text file (Solaris)
y if the process is using the file as its controlling terminal (IRIX)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-692646/,如需轉載,請註明出處,否則將追究法律責任。