Find out what files are locked by a process

If you ever copied some bigger files from one file system to another, you came to the point, that you would like to know what file the copy routine is currently processing. In this case I like to use lsof -p <process ID> to get the information.
# lsof -p 10784
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
cp 10784 root cwd DIR 199,16000 8192 2 /very/large/files
cp 10784 root rtd DIR 253,0 4096 2 /
cp 10784 root txt REG 253,0 122736 4587570 /bin/cp
cp 10784 root mem REG 253,0 156872 4981137 /lib64/ld-2.12.so
cp 10784 root mem REG 253,0 22536 4981145 /lib64/libdl-2.12.so
cp 10784 root mem REG 253,0 1918016 4981138 /lib64/libc-2.12.so
cp 10784 root mem REG 253,0 145720 4981143 /lib64/libpthread-2.12.so
cp 10784 root mem REG 253,0 47064 4981150 /lib64/librt-2.12.so
cp 10784 root mem REG 253,0 124624 4981154 /lib64/libselinux.so.1
cp 10784 root mem REG 253,0 33816 4981175 /lib64/libacl.so.1.1.0
cp 10784 root mem REG 253,0 21152 4981049 /lib64/libattr.so.1.1.0
cp 10784 root mem REG 253,0 99158576 5769198 /usr/lib/locale/locale-archive
cp 10784 root 0u CHR 136,2 0t0 5 /dev/pts/2
cp 10784 root 1u CHR 136,2 0t0 5 /dev/pts/2
cp 10784 root 2u CHR 136,2 0t0 5 /dev/pts/2
cp 10784 root 3r REG 199,16000 302241546240 7507 /very/large/files/big_file.dat
cp 10784 root 4w REG 199,20000 122454409216 26 /even/larger/files/big_file.dat

The last two lines tell you what file cp is currently working on.

About Juergen Caris

I am 54yo, MSc(Dist) and BSc in Computer Science, German and working as a Senior Server Engineer for the NHS Lothian. I am responsible for the patient management system, called TrakCare. I am a UNIX/Linux guy, working in this sector for more than 20 years now. I am also interested in robotics, microprocessors, system monitoring, Home automation and programming.
This entry was posted in Bash, Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published.