I have a Bash script that runs in multiple processess concurrently. The relevant portion looks like this:

flock /var/lock/my_lock my_command

Given that /var/lock/my_lock exists, is there a way to determine which process owns it and thus which one is executing my_command?

  • 2
    fuser /var/lock/my_lock ?
    – leonbloy
    May 16, 2013 at 19:56

2 Answers 2


Something like lsof | "egrep /var/lock/my_lock" should work

  • 2
    That's cracking a nut with a sledgehammer. fuser is the tool to be used. May 16, 2013 at 19:58
  • 2
    It's not necessary to use grep, lsof will accept the filename as an argument. May 17, 2013 at 0:06
  • fuser and lsof report all processes trying to adquire the lock, doesn't say which is actually running my_command
    – quimnuss
    Oct 19, 2017 at 9:27

fuser -v /var/lock/mylock will display the user, process ID, access and command. I found this page to be helpful in understanding fuser.

You must log in to answer this question.

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