Кто держит файлы?

Для определения, какой процесс использует файлы или каталоги, можно использовать fuser.

Также может пригодится

lsof — list open files

It happens all the time doesn’t it? You need to unmount a CD or you want to pack away the external drive but when you try to umount it you get the dreaded “device is busy” message. Wouldn’t it be great if Linux actually told you what was keeping the drive busy? Here we are in 2008, I’m using Ubuntu Gutsy, and that message hasn’t changed in all the years I’ve used Linux.

# umount /media/disk/
umount: /media/disk: device is busy
umount: /media/disk: device is busy

First thing you’ll do will probably be to close down all your terminals and xterms but here’s a better way. You can use the fuser command to find out which process was keeping the device busy:

# fuser -m /dev/sdc1
/dev/sdc1: 538
# ps auxw|grep 538
donncha 538 0.4 2.7 219212 56792 ? SLl Feb11 11:25 rhythmbox

Rhythmbox is the culprit! Close that down and umount the drive. Problem solved!

fuser man page

fuser — identify processes using files or sockets

fuser [-fuv] [-a|-s] [-4|-6] [-c|-m|-n space ] [-k [-i] [-M] [-SIGNAL ] ] name …
fuser -l
fuser -V

fuser displays the PIDs of processes using the specified files or file systems. In the default display mode, each file name is followed by a letter denoting the type of access:

c current directory.

e executable being run.

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.

fuser returns a non-zero return code if none of the specified files is accessed or in case of a fatal error. If at least one access has been found, fuser returns zero.

In order to look up processes using TCP and UDP sockets, the corresponding name space has to be selected with the -n option. By default fuser will look in both IPv6 and IPv4
sockets. To change the default, behavior, use the -4 and -6 options. The socket(s) can be specified by the local and remote port, and the remote address. All fields are
optional, but commas in front of missing fields must be present:


Either symbolic or numeric values can be used for IP addresses and port numbers.

fuser outputs only the PIDs to stdout, everything else is sent to stderr.

-a, —all
Show all files specified on the command line. By default, only files that are accessed by at least one process are shown.

-c Same as -m option, used for POSIX compatibility.

-f Silently ignored, used for POSIX compatibility.

-k, —kill
Kill processes accessing the file. Unless changed with -SIGNAL, SIGKILL is sent. An fuser process never kills itself, but may kill other fuser processes. The effective
user ID of the process executing fuser is set to its real user ID before attempting to kill.

-i, —interactive
Ask the user for confirmation before killing a process. This option is silently ignored if -k is not present too.

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *