Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-13-2019, 09:07 PM   #1
LQ Newbie
Registered: Jan 2019
Posts: 2

Rep: Reputation: Disabled
Smile 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?
Old 01-14-2019, 01:42 AM   #2
Senior Member
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 2,512

Rep: Reputation: 614Reputation: 614Reputation: 614Reputation: 614Reputation: 614Reputation: 614
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.

Last edited by berndbausch; 01-14-2019 at 01:42 AM. Reason: typo
Old 01-14-2019, 03:22 AM   #3
LQ Newbie
Registered: Jan 2019
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you for the response, it makes sense now


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Docker, FESCo Election, Android App for Flock, Flock Video Volunteers, and Release Naming (5tF LXer Syndicated Linux News 0 07-17-2014 06:30 PM
LXer: Docker, FESco Election, Android App for Flock, Flock Video Volunteers, and Release Naming (5tF LXer Syndicated Linux News 0 07-17-2014 12:51 AM
[SOLVED] shell scripting: value of argument dissapears depending on argument order akelder Programming 5 03-22-2011 12:27 AM
difference between socket returned descriptor and accept returned descriptor naveenisback Programming 1 08-29-2009 05:55 AM
message sending failed : Error[22 ] invalid argument .....but each and every argument rakeshranjanjha Linux - Software 2 01-08-2008 12:22 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:59 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration