Locked file how to find

Well I run into this issue a lot.  I cannot unmount a partition.. or I cannot open a file because it’s locked and in use.  How do I see what has that file or mount locked?  Well since everything in Linux is a file you can list open files … which will show you what processes have certain files locked this is done with the lsof command.

For example on my Mythbox I want to see what has the /storage partition locked I would issue:

[root@linuxmonkey2 ~]# lsof | grep storage
mysqld     2285      mysql   13u      REG      253,0        124     325498 /var/lib/mysql/mythconverg/storagegroup.MYD
mysqld     2285      mysql   57u      REG      253,0       5120     325424 /var/lib/mysql/mythconverg/storagegroup.MYI
gnome-key  2887     mythtv  mem       REG      253,0      40808     502127 /usr/lib/libhal-storage.so.1.0.0
mythbacke  7126       root   18w      REG      253,2 1492874876    1523719 /storage/recordings/1007_20100421150000.mpg

From that you can see mysql, gnome-key and mythbackend all have open files inside storage I would have to kill them before unmounting.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.