執行umount 的時候卻提示:device is busy 的處理方法


# umount /mnt/cdrom/
umount: /mnt/cdrom: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

# umount /mnt/cdrom/ -f    //強制卸載也不行
umount2: 設備或資源忙
umount: /mnt/cdrom: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
umount2: 設備或資源忙
# fuser -m /mnt/cdrom/
/mnt/cdrom/:          1338c
# ps aux |grep 1338
root      1338  0.0  0.2 108292  1912 pts/2    Ss+  14:27   0:00 -bash
root      1423  0.0  0.1 103236   884 pts/1    S+   14:49   0:00 grep 1338# kill -9 1338# fuser -m /mnt/cdrom
# umount /mnt/cdrom/# 

=========================================================
附fuser命令詳解:
linux fuser
 
用fuser殺掉進程

一,為什么要使用fuser?
   先說 fuser的作用,fuser能識別出正在對某個文件或端口訪問的進程
大家想一下,還有哪個命令具備這個功能? 沒錯,是lsof,我們前面講過, lsof能夠找出正在對指定文件訪問的進程,
那么它們兩者之間有何區別?
fuser有一個特別的用法在於它可以一次殺死那些正在訪問指定文件的進程。   

二,如何使用fuser?

   1,如何用fuser得到正在使用指定文件的進程?
     用法: fuser 文件
     說明:它會把正在使用當前文件的進程id列出

     # umount /
     umount: /: device is busy.
           (In some cases useful info about processes that use
            the device is found by lsof(8) or fuser(1))
     # fuser /
      /:                       1rc     2rc     3rc     4rc     5rc     6rc     7rc    80rc    82rc    84rc    85rc   153rc   157rc   158rc
                               
                             
      說明:
      這些進程號后面的rc是什么意思?
      
      c 將此文件作為當前目錄使用。 
      e 將此文件作為程序的可執行對象使用。 
      r 將此文件作為根目錄使用。 
      s 將此文件作為共享庫(或其他可裝載對象)使用

  2,如何列出進程的詳細信息,而不僅僅是進程id?-v參數即可
     說明: -v:  含義是:verbose output,詳細的輸出信息
     例子:

    # fuser /var/log
     /var/log:             4196c
   # fuser -v /var/log
      
                          USER        PID ACCESS COMMAND
     /var/log:            root       4196 ..c.. bash

   3,如何列出進程所屬的用戶?-u參數即可
    說明: -u: 含義:display user IDs,顯示用戶id
     
     例子:
    # fuser -u /var/log
     /var/log:             4196c(root)

     4,如何殺死所有正在訪問指定文件的進程?-k參數即可
     說明: -k:含義: kill processes accessing the named file

     例子:

     # fuser -v /root/install.log
                          用戶     進程號 權限   命令
     /root/install.log:   root       3185 f.... tail
     # fuser -k /root/install.log
     /root/install.log:    3185
   # fuser -v /root/install.log

     說明: -k參數能夠殺死所有的正在訪問指定文件的進程,所以用來殺進程時非常方便
     說明之二: fuser如何殺死的進程?
             它發送的是這個信號:SIGKILL



三,多學一點知識

    1,fuser可以列出它所知的信號:
     用 -l參數即可
     
     例子:
    # fuser -l
     HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM
     STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS
     UNUSED

    2,fuser可以發送它已知的信號給訪問的指定文件進程而代替-k參數默認發送的SIGKILL
      例如:只是掛起進程,那么發送HUP信號就可以了
     
      例子:
     # fuser -v /root/install.log
                           用戶     進程號 權限   命令
      /root/install.log:   root       3347 f.... tail
    # fuser -k -SIGHUP /root/install.log
      /root/install.log:    3347
     # fuser -v /root/install.log

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM