Process

lsof 和 fuser -uvm 有什麼區別

  • June 4, 2020

兩者都顯示了我們正在使用的文件數。

然而,它們都顯示出不同的結果。

root@host [~]# lsof /home4
root@host [~]# lsof /home2
root@host [~]# lsof /home4

然後我們得到了

fuser -uvm /home4

                    root       2621 Frce. (root)crond
                    root       2635 Frce. (root)atd
                    root       4554 frce. (root)S99firstboot
                    root       4768 .rce. (root)firstboot
                    root       6533 .rce. (root)setup
                    root      11042 Frce. (root)leechprotect
                    root      11049 Frce. (root)httpd
                    root      17885 Frce. (root)httpd
                    root      18163 .rce. (root)sshd
                    root      18184 .rce. (root)bash
                    nobody    18619 Frce. (nobody)httpd
                    nobody    18679 Frce. (nobody)httpd
                    nobody    18812 Frce. (nobody)httpd
                    nobody    18821 Frce. (nobody)httpd
                    nobody    18841 Frce. (nobody)httpd
                    nobody    18843 Frce. (nobody)httpd
                    nobody    18850 Frce. (nobody)httpd
                    nobody    18869 Frce. (nobody)httpd
                    nobody    18885 Frce. (nobody)httpd
                    nobody    18901 Frce. (nobody)httpd
                    nobody    18914 Frce. (nobody)httpd
                    root      18932 .rc.. (root)flush-7:0
                    root      30728 Frce. (root)cphulkd
                    root      30756 Frce. (root)cpsrvd-ssl
                    root      30806 Frce. (root)cpdavd
                    root      30833 .rce. (root)queueprocd
                    root      30904 Frce. (root)tailwatchd
                    root      30913 Frce. (root)cpanellogd

我哪裡做錯了?

兩者的用法不同。

對於lsof,要僅顯示特定路徑的打開文件,請放在--指定的第一個路徑的前面:

lsof -- /home4
lsof -- /home4 /home2

lsof將顯示所有打開的包含路徑的文件。

fuser另一方面,顯示打開您指定的文件的程序

fuser -uv <filename> 

要顯示訪問特定路徑的程序,請使用-m

fuser -uvm /home3

fuser在辨識打開特定文件的程序 ID 時更有用。

lsof對於找出特定程序打開的所有文件很有用。

引用自:https://unix.stackexchange.com/questions/60492