fuser:identify processes using files or sockets 查看文件或sockets或文件系統(tǒng)被哪些進程使用
fuser展示指定文件或文件系統(tǒng)被進程使用的pid和一個特定的類型標識。
c current directory.當前目錄
e executable being run.可執(zhí)行程序正在執(zhí)行
f open file. f is omitted in default display mode. 打開的文件,默認不顯示
F open file for writing. F is omitted in default display mode. 寫文件,默認不顯示
r root directory.根目錄
m mmap’ed file or shared library 映射文件或共享庫
示例:
[root@WebA-136~]#fuser-m/dev/sda2
/dev/sda2:1004e1080e1087e1482e1616e1620m5879e5917e7919e9413e9455e9459m9474e
[root@WebA-136~]#ps-ef|grep9459
root94599455018:14pts/200:00:00-bash
root94749459018:14pts/200:00:00vim/etc/passwd
root95281620018:25pts/000:00:00grep9459
[root@WebA-136~]#
常用選項:
-m 指定一個文件系統(tǒng)或一個塊設備,列出當前文件系統(tǒng)上的文件由哪些進程使用
-a 列出指定的文件被哪些進程使用
-c 和-m一樣,用于POSIX兼容
-k 殺掉訪問文件的進程
-i 殺掉進程時需要詢問進程用戶,與-k同時使用
-l 列出所有已知的信號信息
-s 靜默模式,-v -u不生效
-v 詳細模式
-u 顯示進程用戶名
-n space 指定一個不同的命名空間(space).這里支持不同的空間文件(文件名,此處默認)、tcp(本地tcp端口)、udp(本地udp端口)。對于端口, 可以指定端口號或者名稱,如果不會引起歧義那么可以使用簡單表示的形式,例如:name/space (即形如:80/tcp之類的表示)
-4 與-n一起使用
-6 與-n一起使用
-a選項示例:
[root@WebA-136~]#cattest.sh
#!/bin/bash
#
foriin{1..100}
do
echo'1'>>a.log
sleep10
done
[root@WebA-136~]#fuser-atest.sh
test.sh:9563
[root@WebA-136~]#ps-ef|grep9563
root95639459018:34pts/200:00:00/bin/bash./test.sh
root95739563018:35pts/200:00:00sleep10
root95761620018:35pts/000:00:00grep9563
[root@WebA-136~]#
-m選項:
[root@WebA-136~]#fuser-m/dev/sda6
/dev/sda6:9563rce#上面示例的pid
-k選項:若不指定signal,默認發(fā)送SIGKILL
[root@WebA-136~]#fuser-atest.sh
test.sh:9609
[root@WebA-136~]#fuser-ktest.sh
test.sh:9609
[root@WebA-136~]#fuser-atest.sh
test.sh:
[root@WebA-136~]#./test.sh
已殺死
[root@WebA-136~]#
-l選項
[root@WebA-136~]#fuser-l
HUPINTQUITILLTRAPABRTIOTBUSFPEKILLUSR1SEGVUSR2PIPEALRMTERM
STKFLTCHLDCONTSTOPTSTPTTINTTOUURGXCPUXFSZVTALRMPROFWINCHIOPWRSYS
UNUSED
[root@WebA-136~]#