1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) and
4 .\" and Copyright 2002 Michael Kerrisk
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified Fri Jan 31 16:26:07 1997 by Eric S. Raymond <esr@thyrsus.com>
27 .\" Modified Fri Dec 11 17:57:27 1998 by Jamie Lokier <jamie@imbolc.ucc.ie>
28 .\" Modified 24 Apr 2002 by Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Substantial rewrites and additions
30 .\" 2005-05-10 mtk, noted that lock conversions are not atomic.
32 .\" Japanese Version Copyright (c) 1996 Takeshi Ueno
33 .\" all rights reserved.
34 .\" Translated 1996-07-03, Takeshi Ueno <tueno@vio.co.jp>
35 .\" Modified 1997-12-14, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
36 .\" Modified 1999-08-14, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
37 .\" Modified 2002-09-24, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
38 .\" Modified 2005-02-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
39 .\" Updated 2005-09-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
41 .TH FLOCK 2 2009-07-25 "Linux" "Linux Programmer's Manual"
43 flock \- ¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤ËÂФ¹¤ë¥¢¥É¥Ð¥¤¥¶¥ê¡¦¥í¥Ã¥¯¤ÎŬÍÑ¡¢²ò½ü¤ò¹Ô¤¦
45 .B #include <sys/file.h>
47 .BI "int flock(int " fd ", int " operation );
49 ¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ë¥¢¥É¥Ð¥¤¥¶¥ê¡¦¥í¥Ã¥¯ (advisory lock) ¤ÎŬÍÑ
55 ¤Ë¤Ï°Ê²¼¤Î¤¤¤º¤ì¤«°ì¤Ä¤ò»ØÄꤹ¤ë:
59 ¶¦Í¥í¥Ã¥¯¤òŬÍѤ¹¤ë¡£ »ØÄꤷ¤¿¥Õ¥¡¥¤¥ë¤ËÂФ·¤Æ¡¢
60 °ì¤Ä°Ê¾å¤Î¥×¥í¥»¥¹¤¬Æ±»þ¤Ë¶¦Í¥í¥Ã¥¯¤òÊÝ»ý¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
63 ÇÓ¾¥í¥Ã¥¯¤òŬÍѤ¹¤ë¡£ »ØÄꤷ¤¿¥Õ¥¡¥¤¥ë¤ËÂФ·¤Æ¡¢
64 ¤¿¤À°ì¤Ä¤Î¥×¥í¥»¥¹¤À¤±¤¬Æ±»þ¤ËÇÓ¾¥í¥Ã¥¯¤òÊÝ»ý¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
67 ¤³¤Î¥×¥í¥»¥¹¤¬ÊÝ»ý¤·¤Æ¤¤¤ë´û¸¤Î¥í¥Ã¥¯¤ò²ò½ü¤¹¤ë¡£
71 ¤ò¸Æ¤Ó½Ð¤·¤¿¤È¤¤Ë¡¢»ØÄꤷ¤¿¥í¥Ã¥¯¼ïÊ̤Ȱۤʤë¥í¥Ã¥¯¤¬ÊÌ¥×¥í¥»¥¹¤Ë¤è¤Ã¤Æ
74 ¤ÏÄä»ß (block) ¤µ¤ì¤ë¤³¤È¤¬¤¢¤ë¡£
75 ÈóÄä»ß (nonblocking) ¥¿¥¤¥×¤ÎÍ×µá¤ò¹Ô¤¦¤¿¤á¤Ë¤Ï¡¢
76 ¾åµ¤ÎÁàºî (operation) ¤Ë
78 ¤òÏÀÍýϤηÁ¤Ç»ØÄꤹ¤ë¡£
80 °ì¤Ä¤Î¥Õ¥¡¥¤¥ë¤Ë¶¦Í¥í¥Ã¥¯¤ÈÇÓ¾¥í¥Ã¥¯¤òƱ»þ¤ËÀßÄꤹ¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£
83 ¤Ë¤è¤Ã¤Æºî¤é¤ì¤ë¥í¥Ã¥¯¤Ï¡¢
84 ¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤Î¥Æ¡¼¥Ö¥ë¡¦¥¨¥ó¥È¥ê¤È´ØÏ¢ÉÕ¤±¤é¤ì¤ë¡£
85 ¤·¤¿¤¬¤Ã¤Æ¡¢¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÎÊ£À½
89 ¤Ê¤É¤Ë¤è¤êºîÀ®¤µ¤ì¤ë) ¤ÏƱ¤¸¥í¥Ã¥¯¤ò»²¾È¤·¡¢
90 ¤³¤ì¤é¤Î¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¤É¤ì¤ò»È¤Ã¤Æ¤â
91 ¤³¤Î¥í¥Ã¥¯¤òÊѹ¹¤·¤¿¤ê²òÊü¤·¤¿¤ê¤Ç¤¤ë¡£
92 ¤Þ¤¿¡¢¥í¥Ã¥¯¤Î²òÊü¤Ï¡¢
93 ¾åµ¤ÎÊ£¿ô¤Î¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¤¤¤º¤ì¤«¤ËÂФ·¤Æ
96 Áàºî¤ò»Ø¼¨¤·¤¿¾ì¹ç¤«¡¢¤³¤ì¤é¤Î¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬¤¹¤Ù¤Æ
97 ÊĤ¸¤é¤ì¤¿¾ì¹ç¤Ë¹Ô¤ï¤ì¤ë¡£
101 (¤â¤·¤¯¤ÏƱÍͤÎÊýË¡) ¤ò»È¤Ã¤ÆƱ¤¸¥Õ¥¡¥¤¥ë¤ËÂФ·¤Æ
102 Ê£¿ô¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò¼èÆÀ¤·¤¿¾ì¹ç¡¢
104 ¤Ï¤³¤ì¤éÊ£¿ô¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò³Æ¡¹ÆÈΩ¤Î¤â¤Î¤È¤·¤Æ°·¤¦¡£
105 ¤³¤ì¤é¤Î¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î°ì¤Ä¤ò»È¤Ã¤Æ¥Õ¥¡¥¤¥ë¤ò¥í¥Ã¥¯¤·¤è¤¦¤È
106 ¤·¤¿ºÝ¡¢¤½¤Î¥í¥Ã¥¯Í×µá¤Ï¡¢¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤¬¤½¤Î¥Õ¥¡¥¤¥ë¤ÎÊ̤Î
107 ¥Ç¥£¥¹¥¯¥ê¥×¥¿·Ðͳ¤Ç¤¹¤Ç¤ËÀßÄꤷ¤Æ¤¤¤ë¥í¥Ã¥¯¤Ë¤è¤Ã¤ÆµñÈݤµ¤ì¤ë¾ì¹ç¤¬¤¢¤ë¡£
109 °ì¤Ä¤Î¥×¥í¥»¥¹¤Ï¡¢°ì¤Ä¤Î¥Õ¥¡¥¤¥ë¤ËÂФ·¤Æ (¶¦Í¥í¥Ã¥¯¤ÈÇÓ¾¥í¥Ã¥¯¤Î¤¦¤Á)
110 ¤¤¤º¤ì¤«°ì¼ïÎà¤Î¥í¥Ã¥¯¤·¤«ÀßÄê¤Ç¤¤Ê¤¤¡£
111 ´û¤Ë¥í¥Ã¥¯¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤ËÂФ·¤Æ
113 ¤ò¸Æ¤Ó½Ð¤¹¤È¡¢´û¸¤Î¥í¥Ã¥¯¤ò¿·¤·¤¤¥í¥Ã¥¯¥â¡¼¥É¤ËÊѹ¹¤¹¤ë¤³¤È¤Ë¤Ê¤ë¡£
116 ¤Ë¤è¤êºîÀ®¤µ¤ì¤¿¥í¥Ã¥¯¤Ï
120 ¶¦Í¥í¥Ã¥¯¤âÇÓ¾¥í¥Ã¥¯¤â¡¢¥Õ¥¡¥¤¥ë¤¬¤É¤Î¥â¡¼¥É¤Ç¥ª¡¼¥×¥ó¤µ¤ì¤¿¤«¤Ë
121 ´Ø·¸¤Ê¤¯Å¬ÍѤ¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
123 À®¸ù¤Î¾ì¹ç¡¢0 ¤¬ÊÖ¤µ¤ì¤ë¡£¥¨¥é¡¼¤Î¾ì¹ç¤Ï¡¢\-1 ¤¬ÊÖ¤µ¤ì¡¢
125 ¤ËŬÀÚ¤ÊÃͤ¬ÀßÄꤵ¤ì¤ë¡£
130 ¤¬¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ï¤Ê¤¤¡£
133 ¥í¥Ã¥¯¤Î³ÍÆÀ¤òÂԤäƤ¤¤ë´Ö¤Ë¡¢¥Ï¥ó¥É¥é¤Ë¤è¤êÊ᪤µ¤ì¤¿¥·¥°¥Ê¥ë¤ò
145 ¥í¥Ã¥¯¡¦¥ì¥³¡¼¥É¤ò³ä¤êÅö¤Æ¤ë¤¿¤á¤Î¥á¥â¥ê¤¬ÉÔ¤·¤Æ¤¤¤ë¡£
148 »ØÄꤷ¤¿¥Õ¥¡¥¤¥ë¤¬¥í¥Ã¥¯¤µ¤ì¤Æ¤ª¤ê¡¢
150 ¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¡£
154 ¥³¡¼¥ë¤Ï 4.2BSD ¤ÇºÇ½é¤ËÅо줷¤¿)¡£
156 ¤Ç¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Ê¤É¤ò´Þ¤á¤ë¤È¡¢
158 ¤Îµ¡Ç½¤Ï¤Û¤È¤ó¤É¤Î Unix ¥·¥¹¥Æ¥à¤Ç¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¡£
161 ¤Ï NFS ¾å¤Î¥Õ¥¡¥¤¥ë¤Î¥í¥Ã¥¯¤ò¤·¤Ê¤¤¡£Âå¤ï¤ê¤Ë
163 ¤ò»ÈÍѤ¹¤ë¤³¤È¡£¤³¤ì¤Ë¤è¤ê¡¢½½Ê¬¤Ë¿·¤·¤¤¥Ð¡¼¥¸¥ç¥ó¤Î Linux ¤È¡¢¥í¥Ã¥¯µ¡Ç½¤ò
164 ¥µ¥Ý¡¼¥È¤·¤¿ NFS ¥µ¡¼¥Ð¤ò»ÈÍѤ¹¤ë¤³¤È¤Ë¤è¤ê¡¢NFS ¾å¤Ç¥í¥Ã¥¯¤¬¤Ç¤¤ë¡£
166 kernel 2.0 °Ê¹ß¤Ç¤Ï¡¢
168 ¤Ï¡¢GNU C ¥é¥¤¥Ö¥é¥ê¤Ç¤Î
170 ¤ò¸Æ¤Ó½Ð¤·¤Æ¤Î¥¨¥ß¥å¥ì¡¼¥·¥ç¥ó¤Ç¤Ï¤Ê¤¯¡¢
171 ¤½¤ì¼«ÂΤ¬¥·¥¹¥Æ¥à¥³¡¼¥ë¤È¤·¤Æ¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¡£
172 ¤³¤ì¤Ë¤è¤êÀµ¿¿ÀµÌäΠBSD ¤Ç¤ÎÆ°ºî¤¬Ã£À®¤µ¤ì¤ë:
176 ¤ÇŬÍѤµ¤ì¤ë¥í¥Ã¥¯¤Î¼ïÊ̤ˤÏÁê¸ßºîÍѤ¬¤Ê¤¯¤Ê¤ê¡¢
178 ¤¬¥Ç¥Ã¥É¥í¥Ã¥¯¤ò¸¡½Ð¤·¤Ê¤¯¤Ê¤ë¡£
181 ¥¢¥É¥Ð¥¤¥¶¥ê¡¦¥í¥Ã¥¯¤À¤±¤òŬÍѤ¹¤ë¡£¤·¤¿¤¬¤Ã¤Æ¡¢¥Õ¥¡¥¤¥ë¤ËŬÀڤʥ¢¥¯¥»¥¹¸¢¤ò
182 ÉÕÍ¿¤·¤Æ¤¤¤ì¤Ð¡¢¥×¥í¥»¥¹¤Ï
184 ¤Î»ÈÍѤË̵»ë¤·¤Æ¡¢¥Õ¥¡¥¤¥ë¤Ø¤ÎÆþ½ÐÎϤò¹Ô¤¦¤³¤È¤¬¤Ç¤¤ë¡£
189 ¤Ï fork ¤µ¤ì¤¿¥×¥í¥»¥¹¤È
195 ¤ò»È¤Ã¤Æ¼ÂÁõ¤·¤Æ¤¤¤ë¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
197 ¤ÎÆ°ºî¤Ï¤³¤Î¥Þ¥Ë¥å¥¢¥ë¡¦¥Ú¡¼¥¸¤ËµºÜ¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤È¤Ï°ã¤¦¤À¤í¤¦¡£
199 ¥í¥Ã¥¯¤ÎÊÑ´¹ (¶¦Í¥í¥Ã¥¯¤«¤éÇÓ¾¥í¥Ã¥¯¤Ø¡¢¤â¤·¤¯¤Ï¤½¤ÎÈ¿ÂÐ) ¤¬¥¢¥È¥ß¥Ã¥¯¤Ë
200 ¹Ô¤ï¤ì¤ë¤³¤È¤ÏÊݾڤµ¤ì¤Æ¤¤¤Ê¤¤: ´û¸¤Î¥í¥Ã¥¯¤¬¤Þ¤ººï½ü¤µ¤ì¡¢¤½¤ì¤«¤é¿·¤·¤¤
201 ¥í¥Ã¥¯¤¬ÀßÄꤵ¤ì¤ë¡£¤³¤Î 2¤Ä¤Î¥¹¥Æ¥Ã¥×¤Î´Ö¤Ë¡¢Â¾¤Î¥×¥í¥»¥¹¤«¤é¤Î½èÍýÂÔ¤Á¤Î
202 ¥í¥Ã¥¯Í׵᤬ǧ¤á¤é¤ì¤ë¤«¤â¤·¤ì¤º¡¢·ë²Ì¤È¤·¤ÆÊÑ´¹¤ÏÄä»ß (block) ¤·¤¿¤ê¡¢
204 ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¤Ë¤Ï) ¼ºÇÔ¤·¤¿¤ê¤¹¤ë¡£
205 (¤³¤ì¤Ï¸µ¡¹¤Î BSD ¤ÎÆ°ºî¤Ç¤¢¤ê¡¢Â¿¤¯¤Î¾¤Î¼ÂÁõ¤Ç¤âµ¯¤³¤ë¡£)
206 .\" ¥«¡¼¥Í¥ë 2.5.21 ¤Ç¾¯¤·Æ°ºî¤¬Êѹ¹¤µ¤ì¤¿: ¥í¥Ã¥¯ÊÑ´¹¤ÎºÇÃæ¤Ï
207 .\" ¤½¤Î¥í¥Ã¥¯¤ò¹Ô¤ª¤¦¤È¤·¤Æ¤¤¤ë¥×¥í¥»¥¹¤¬ºÇ¹âÍ¥Àè¤È¤Ê¤ë -- mtk
218 .I Documentation/filesystem/locks.txt
220 .IR Documentation/locks.txt )