1

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 '13 at 19:56
1

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

| improve this answer | |
  • 2
    That's cracking a nut with a sledgehammer. fuser is the tool to be used. – Hauke Laging May 16 '13 at 19:58
  • 2
    It's not necessary to use grep, lsof will accept the filename as an argument. – Paused until further notice. May 17 '13 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 '17 at 9:27
2

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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