Take the 2-minute tour ×

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?

share|improve this question
fuser /var/lock/my_lock ? –  leonbloy May 16 '13 at 19:56
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
That's cracking a nut with a sledgehammer. fuser is the tool to be used. –  Hauke Laging May 16 '13 at 19:58
It's not necessary to use grep, lsof will accept the filename as an argument. –  Dennis Williamson May 17 '13 at 0:06
add comment

Your Answer


