Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
2  
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
1  
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.