天天看點

linux系統fuser指令,Linux-fuser指令詳解

' 的簡寫方式,隻要不存在異義的話

-s

# 注釋 :-s 表示安靜模式。-u 和 -v 會被忽略,-a 不能和 -s 一起使用

-signal

# 注釋:-指定信号

-u

# 注釋 :-u 表示在 PID 後面加上程序的 owner

-v

# 注釋 :-v 表示 verbose 模式。程序以  ps 的方式顯示,包括 PID、USER、COMMAND、ACCESS 字段

# 如果是核心通路的(例如 mount point、swap 檔案),則顯示為 kernel 而不是 pid

-V

Display version information.

-4

Search only for IPv4 sockets. This option must not be used with the -6 option and only has an effect with the tcp and udp namespaces.

-6

Search only for IPv6 sockets. This option must not be used with the -4 option and only has an effect with the tcp and udp namespaces.

-

# 注釋:‘-’ 表示重置所有選項并把信号設定為 SIGKILL

常用的兩個功能:檢視需要的程序和要殺死我查到的程序。

比如想umount光驅或者其他檔案系統的的時候,結果系統提示裝置正在使用或者正忙,可是又找不到到底誰使用了。這個時候fuser可派上用場了。

[[email protected] tmp]#  fuser -vm /usr/local/

USER        PID ACCESS COMMAND

/usr/local/:         root          1 .rce. init

root          2 .rc.. migration/0

root          3 .rc.. ksoftirqd/0

root          4 .rc.. migration/1

root          5 .rc.. ksoftirqd/1

root          6 .rc.. migration/2

root          7 .rc.. ksoftirqd/2

root          8 .rc.. migration/3

root          9 .rc.. ksoftirqd/3

root         10 .rc.. events/0

root         11 .rc.. events/1

root         12 .rc.. events/2

root         13 .rc.. events/3

在使用fuser -km 就可以殺死程序,同時也可以使用互動式的-i參數,一個一個殺死。

# 注釋 :fuser 顯示使用指定檔案或者檔案系統的程序的 pid ,預設會在每個 pid 後面加上一個字元表示通路的方式 :

#     -)1、c :表示 current directory 。表示程序是在該目錄下啟動的。

#     -)2、e :表示是可執行的程式

#     -)3、f :打開檔案。預設不顯示

#     -)4、r :root 目錄,表示該目錄是該程序的 / 目錄

#     -)5、m :表示 mmap 過的檔案或者共享庫

# 注釋 :如果指定檔案沒有任何程序通路,或者出現嚴重錯誤,fuser 傳回非 0 的 exit status。

# 如果至少存在一個程序,則 fuser 傳回 0

# 注釋:為了查找使用某個 TCP /UDP sockets 的程序,你必須用 -n 指定 (name space)tcp 還是 udp 。

# 預設 fuser 會查找 ipv4 和 ipv6 sockets 。你可以使用 -4 或者 -6 來改變選項

# sockets 可以按照 local port:remote_host:remote_port 的方式來指定。每個字段都是可選的,但不能省略 ','

[lcl_port][,[rmt_host][,[rmt_port]]]

Either symbolic or numeric values can be used for IP addresses and port numbers.

# 注釋 ;在端口方面,你可以用端口名或者數字表示

fuser outputs only the PIDs to stdout, everything else is sent to stderr.

# 注釋 :fuser 隻輸出 PID 到 stdout ,其他都送給 stderr

舉例:

fuser -km /home

kills all processes accessing the file system /home in any way.

# 注釋 :fuser -km /home 殺死所有通路 /home 檔案系統的程序

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.