只有當原始文件正在使用時,熱凝器才能向您顯示。如何檢查Linux符號鏈接是否正在使用? (去除未使用的符號鏈接)
定影器如果SYMLINK在使用中,則不會顯示您調用原始文件。這是問題。你不知道符號鏈接是否被使用,並且可以被刪除。
我已經開始兩個過程(24261打開原始文件和24262打開符號鏈接):
[email protected] DEV # ls -l /lib64/libgcc_s-4.4.7-20120601.so.1
-rwxr-xr-x 1 root root 93320 Sep 1 2014 /lib64/libgcc_s-4.4.7-20120601.so.1
[email protected] DEV # ls -l /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgcc_s.so
lrwxrwxrwx. 1 root root 20 Oct 19 2015 /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgcc_s.so -> /lib64/libgcc_s.so.1
[email protected] DEV #
[email protected] DEV # tail -f /lib64/libgcc_s.so.1 &
[1] 24261
[email protected] DEV #
[email protected] DEV # cd /usr/lib/gcc/x86_64-redhat-linux/4.4.4
[email protected] DEV # tail -f libgcc_s.so &
[2] 24262
[email protected] DEV #
[email protected] DEV # ps -ef | grep tail
root 24261 3265 0 13:39 pts/1 00:00:00 tail -f /lib64/libgcc_s.so.1
root 24262 3265 0 13:39 pts/1 00:00:00 tail -f libgcc_s.so
root 24492 3265 0 13:40 pts/1 00:00:00 grep tail
[email protected] DEV #
在這兩種情況下,定影告訴符號鏈接和原始文件正在使用(有每個命令的兩個過程):
[email protected] DEV # fuser /lib64/libgcc_s.so.1
/lib64/libgcc_s.so.1: 24261 24262
[email protected] DEV # fuser /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgcc_s.so
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgcc_s.so: 24261 24262
[email protected] DEV #
但是我們知道符號鏈接沒有用於第一個進程。它甚至可以被移除,不會影響第一個過程。
比方說,如果軟件包未被使用,我想刪除'gcc'軟件包。
原始文件來自'libgcc'包。
[email protected] DEV # rpm -qf /lib64/libgcc_s.so.1
libgcc-4.4.7-11.el6.x86_64
符號連接來自 'GCC' 包:
[email protected] DEV # rpm -qf /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgcc_s.so
gcc-4.4.7-11.el6.x86_64
如果我將刪除 '海灣合作委員會' 包,其中只包含符號鏈接,我會影響到第二個進程!如何查看符號鏈接是否未被使用?
在我的情況「PS -ef」顯示,我用命令:
root 24262 3265 0 13:39 pts/1 00:00:00 tail -f libgcc_s.so
所以PS甚至不能告訴你的是使用符號鏈接。
任何Linux專家?
編輯: 還有就是部分解決檢查CWD - 當前工作目錄:
[email protected] DEV # ls -l /proc/24262/cwd
lrwxrwxrwx 1 root root 0 Jun 20 13:57 /proc/24262/cwd -> /usr/lib/gcc/x86_64-redhat-linux/4.4.4
[email protected] DEV #
所以,從這裏,你看到的路徑 「/usr/lib/gcc/x86_64-redhat-linux/4.4.4」你可以從ps獲得文件名。
如果你這樣做不行:
[email protected] DEV # cd /root
[email protected] DEV # cat script.sh
/usr/bin/tail -f /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgcc_s.so
[email protected] DEV #
[email protected] DEV # nohup ./script.sh &
[2] 26713
[email protected] DEV #
[email protected] DEV # ls -l /proc/26713/cwd
lrwxrwxrwx 1 root root 0 Jun 20 14:32 /proc/26713/cwd -> /root
它顯示/根CWD,但符號連接是腳本/程序中。那麼你需要檢查/ psr/lib/gcc/x86_64-redhat-linux/4.4.4/libgcc_s.so的ps chill進程。
[email protected] DEV # ps -ef | grep 26713
root 26713 3265 0 14:32 pts/1 00:00:00 /bin/sh ./script.sh
root 26714 26713 0 14:32 pts/1 00:00:00 /usr/bin/tail -f /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgcc_s.so
root 26780 3265 0 14:38 pts/1 00:00:00 grep 26713
[email protected] DEV #
當您想自動移除包裹(如果包裹未被使用)時,這會非常混亂。
如果有人能看到更簡單的方法,那將會很棒。另外,如果有人可以確認使用cwd和ps子進程進行符號鏈接使用檢測的準確性。
如果script.sh會是二進制文件會發生什麼?我仍然能夠在'ps'或cwd中看到完整的符號鏈接路徑嗎?
爲什麼你需要刪除未使用的符號鏈接? – Thilo
我需要刪除未使用的編譯器(例如gcc)。這是出於安全目的。 –
「未使用的編譯器」和符號鏈接之間的關係是什麼? – hymie