flock file descriptor argument
Hi all,
I'm trying to understand the flock command and got stuck trying to understand the following code example: ( flock -n 9 || exit 1 # ... commands executed under lock ... ) 9>/var/lock/mylockfile I understand most of the above code but confused about the number 9. I know it's a file descriptor from the man page and I understand the famous usage of file descriptors like "/dev/null 2>&1" but what's the significance of file descriptor 9 in the above code? Or is it just arbitrary and I can just use number 10 or 199? |
The code opens mylockfile as file descriptor 9, then applies the flock command on that file descriptor.
Any number is fine. I suppose a comparably high number avoids possible clashes with existing file descriptors. The man page I just read uses 200. Note that the last line is executed first: Before the script within parentheses is executed, the shell opens mylockfile. |
Thank you for the response, it makes sense now
|
All times are GMT -5. The time now is 02:18 PM. |