Welcome to the new Linux Foundation Forum!

What is a device lock file? (Data distinctions, 2.4)

gacanepagacanepa Posts: 8
edited July 3 in LFS201 Class Forum

The subject line pretty sums it up. What is a device lock file, what are they used for, and where do I find them inside the filesystem tree?

Thanks in advance.

Comments

  • luisviveropenaluisviveropena Posts: 276

    Hi,

    A lock file is a mechanism to prevent/restrict access to a file while it's in use for an application or specific user. You can find some under /va/lock/ , and if you want to find more, you can do a find operation like this:

    find / -name "*.lock"

    You need to use sudo or run it as root.

    Regards,

    Luis.

  • gacanepagacanepa Posts: 8
    edited July 3

    Luis,

    Thanks a lot for your reply.

    I found several lock files with find:

    /home/gacanepa/.vim/plugged/vim-esearch/Gemfile.lock

    /run/ebtables.lock

    /var/lib/postfix/master.lock

    But how do I know what file they are restricting access to?

    FYI, I ran file against /var/lib/postfix/master.lock. Since it's plain text, I then inspected it with cat. Since it contains a number I thought that perhaps it was the PID of a process, but it looks like I was wrong:

    Any ideas?

  • luisviveropenaluisviveropena Posts: 276

    Hi,

    It works like "I'm using this resource, so the rest of you are out until I release it". Many times the content will be the PID of the blocking process, but some other times it won't mean that or anything relevant, but it will mean that it's locked.

    So, if you want to know what's the locking process or program you can do 'lsof' with the lock file, so it will show what process is using the file.

    I hope that helps.

    Luis.

  • gacanepagacanepa Posts: 8

    Thank you, Luis! That answers my question.

  • luisviveropenaluisviveropena Posts: 276

    It's a pleasure!

    Regards,

    Luis.

Sign In or Register to comment.