14

The disk is mounted by sudo mount /dev/sdd5 /media/SDD/Docs and sudo mount /dev/sdd6 /media/SDD/Images and so on, thus there are some directories corresponding to the volumes of the mounted disk.

And when I wanted to eject the disk, i.e. using sudo umount /media/SDD/* to unmount the disk, there is an alert message saying

Failed to eject medium; one or more volumes on the medium are busy.

I've tried the command sudo lsof | grep "/media/SDD" to check the status of the mounted disk, but no information is shown.

Are there any commands to show what application are using the mounted disk? I want to check this to protect the files from disasters. Thank you!

UPDATE:

$ fuser -mv /media/SDD/
                     USER        PID ACCESS COMMAND
/media/SDD:          root     kernel mount /
                     ubuntu     2831 Frce. Xvnc4
                     ubuntu     2839 Frce. vncconfig
                     ubuntu     2841 Frce. gnome-session
                     ubuntu     2844 .rce. dbus-launch
                     ubuntu     2849 .rce. dbus-launch
                     ubuntu     2850 .rce. dbus-daemon
                     ubuntu     2851 .rce. dbus-daemon
                     ubuntu     2858 .rce. gconfd-2
                     ubuntu     2872 Frce. gnome-settings-
                     ubuntu     2900 .rce. gvfsd
                     ubuntu     2907 Frce. gsd-printer
                     ubuntu     2911 Frce. metacity
                     ubuntu     2987 .rce. gconfd-2
                     ubuntu     2988 Frce. gnome-panel
                     ubuntu     2992 .rce. dconf-service
                     ubuntu     2997 Frce. gnome-fallback-
                     ubuntu     2998 Frce. notification-da
                     ubuntu     3003 Frce. bluetooth-apple
                     ubuntu     3004 Frce. nautilus
                     ubuntu     3014 .rce. gvfs-gdu-volume
                     ubuntu     3025 .rce. gvfs-gphoto2-vo
                     ubuntu     3027 .rce. gvfs-afc-volume
                     ubuntu     3035 frce. gvfsd-trash
                     ubuntu     3037 .rce. gvfsd-burn
                     ubuntu     3041 Frce. indicator-apple
                     ubuntu     3043 .rce. trashapplet
                     ubuntu     3053 Frce. gvfsd-metadata
                     ubuntu     3058 .rce. indicator-sessi
                     ubuntu     3060 .rce. indicator-appli
                     ubuntu     3062 .rce. indicator-messa
                     ubuntu     3064 .rce. indicator-sound
                     ubuntu     3099 Frce. pulseaudio
                     ubuntu     3251 .rce. gconf-helper
                     ubuntu     3262 Frce. gnome-screensav
                     ubuntu     3263 Frce. zeitgeist-datah
                     ubuntu     3271 Frce. zeitgeist-daemo
                     ubuntu     3277 Frce. zeitgeist-fts
                     ubuntu     3285 Frce. cat
                     ubuntu     3527 Frce. deja-dup-monito
                     ubuntu     5516 .rce. bash
                     ubuntu     6170 .r.e. bash
                     ubuntu     6488 .r.e. bash
                     ubuntu     8940 Frce. gnome-terminal
                     ubuntu    13309 Fr.e. MATLAB
                     ubuntu    13468 .r.e. matlab_helper
                     ubuntu    17913 .rce. ssh
                     ubuntu    19035 .r.e. bash
                     ubuntu    19615 fr.e. MATLAB
                     ubuntu    19621 fr.e. MATLAB
                     ubuntu    19623 fr.e. MATLAB
                     ubuntu    19625 fr.e. MATLAB
                     ubuntu    19627 fr.e. MATLAB
                     ubuntu    19629 fr.e. MATLAB
                     ubuntu    19632 fr.e. MATLAB
                     ubuntu    19634 fr.e. MATLAB
                     ubuntu    19813 .r.e. matlab_helper
                     ubuntu    19814 .r.e. matlab_helper
                     ubuntu    19819 .r.e. matlab_helper
                     ubuntu    19822 .r.e. matlab_helper
                     ubuntu    19824 .r.e. matlab_helper
                     ubuntu    19826 .r.e. matlab_helper
                     ubuntu    19827 .r.e. matlab_helper
                     ubuntu    19834 .r.e. matlab_helper
                     ubuntu    20716 .r.e. git
                     ubuntu    20717 .r.e. pager
                     ubuntu    20725 .rce. bash

$ fuser -mv /media/SDD/*
                     USER        PID ACCESS COMMAND
/media/SDD/Data2010: root     kernel mount /media/SDD/Data2010
/media/SDD/Data2012: root     kernel mount /media/SDD/Data2012
/media/SDD/Docs:     root     kernel mount /media/SDD/Docs
/media/SDD/Doctor:   root     kernel mount /media/SDD/Doctor
/media/SDD/Files1:   root     kernel mount /media/SDD/Files1
/media/SDD/Files2:   root     kernel mount /media/SDD/Files2
/media/SDD/Papers:   root     kernel mount /media/SDD/Papers
/media/SDD/Temp:     root     kernel mount /media/SDD/Temp
/media/SDD/Videos:   root     kernel mount /media/SDD/Videos
/media/SDD/Work:     root     kernel mount /media/SDD/Work

1 Answer 1

22

The command you are looking for is fuser.

It displays all processes accessing /media/SDD by typing sudo fuser -mv /media/SDD, where the m tells it to look on the given location, the v switches the output to a human readable list instead of just a bunch of PIDs.

To automatically kill all processes (!! Use with care !!) accessing the directory, run sudo fuser -mvki /media/SDD. k means "kill" and i gives you a 2nd chance and lets you confirm each kill (which means you also can leave it and just type ...-mvk... to kill them without asking again).

To do further research on the fuser command, please read its manual by typing man fuser or online at manpages.ubuntu.com.

If I could help you and this answer is exactly what you were looking for, please don't be shy and click on the "accept" button next to the post. Otherwise feel free to ask me again. Thank you!

6
  • Thank you, sir! I've tried your answer with two commands fuser -mv /media/SDD and fuser -mv /media/SDD/*, but it seems to have different outputs. I've posted the outputs in the question above, but it seems to have no information about which process is using the disk. Please help check it.
    – mining
    Jan 28, 2015 at 2:04
  • First, please don't call me sir. Second, the command without a start lists processes accessing all files inside the directory, the command with a star lists those accessing the subdirectories. Third, in the ACCESS column, the f or F means that the listed file is opened (F to write), e means it is a running executable, the rest should be less important. But you might have to use sudo to run it properly. I'll edit my answer.
    – Byte Commander
    Jan 28, 2015 at 2:14
  • OK, thank you! In fact, I've tested with sudo, but it returns the same information. I checked the status of f or F or e, I don't find which process is visiting the files in the disk. But in fact I didn't open a file in the disk, why are there some processes want to visit the files? Is this a disallowed operation?
    – mining
    Jan 28, 2015 at 2:21
  • I agree with you that some processes (e.g. matlab) should not necessarily have to access the directory, but it is normal. I don't know why each process opens some files, sorry.
    – Byte Commander
    Jan 28, 2015 at 11:41
  • OK, thank you! Is it safe? The processes shouldn't visit those files. I didn't give the privileges to them, but I don't know how to control them when they were running in background.
    – mining
    Jan 28, 2015 at 12:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .