flock

FLOCK(2)                   Linux Programmer's Manual                  FLOCK(2)



åå
       flock - ãªã¼ãã³ããããã¡ã¤ã«ã«ããã¯ã®é©ç¨ã解é¤ãè¡ãªã

æ¸å¼
       #include <sys/file.h>

       int flock(int fd, int operation)

説æ
       ãªã¼ãã³ããããã¡ã¤ã«ã«ã¢ããã¤ã¶ãªã»ããã¯(advisory lock)ã®é©ç¨
       ã¾ãã¯è§£é¤ãè¡ãã ãã¡ã¤ã«ã¯ fd ã§æå®ããã æå¹ãªæä½(operation)ã¯ä»¥ä¸ã®éã:


              LOCK_SH   å±æããã¯ã æå®ãããã¡ã¤ã«ã«å¯¾ãã¦ãä¸ã¤ä»¥ä¸ã®ããã»ã¹ãåæã«
                        å±æããã¯ãä¿æãããã¨ãã§ããã

              LOCK_EX   æä»ããã¯ã  æå®ãããã¡ã¤ã«ã«å¯¾ãã¦ããã ä¸ã¤ã®ããã»ã¹ã ãã
                        åæã«æä»ããã¯ãä¿æãããã¨ãã§ããã

              LOCK_UN   ã¢ã³ããã¯ã

              LOCK_NB   ããã¯ããã¨ãã«ãããã¯ããªããä»ã®æä½(operation)ã¨ãã£ããã«( or
                        ã§)æå®ãã¦ãããã


       ä¸ã¤ã®ãã¡ã¤ã«ã«å±æããã¯ã¨æä»ããã¯ãåæã«è¨å®ãããã¨ã¯ã§ããªãã

       ãã¡ã¤ã«(ããªãã¡ inode)ã¯ããã¯ããããã ãã¡ã¤ã«ã»ãã£ã¹ã¯ãªãã¿ã¼ãããã¯ããããã§ã¯
       ãªãã ããã§ã dup(2) ã fork(2) ã«ãã£ã¦è¤æ°ã®ããã¯ãä½ãã ããããã¨ã¯ãªãã

è¿ãå¤
       æåãããã¼ããè¿ããããã¨ã©ã¼ã®æã¯ã-1 ãè¿ããã errno ã«é©åãªå¤ãè¨å®ãããã

ã¨ã©ã¼
       EWOULDBLOCK
              æå®ãããã¡ã¤ã«ãããã¯ããã¦ããã LOCK_NB ãã©ã°ãæå®ããã¦ããã

æºæ
       4.4BSD ( flock(2) ã³ã¼ã«ã¯ 4.2BSD ã§æåã« ç¾ããã)ã

é¢é£é ç®
       open(2), close(2), dup(2), execve(2), fcntl(2), fork(2).
       /usr/src/linux/Documentation ã«ãã locks.txt 㨠mandatory.txt ãåç§ãããã¨ã



Linux 0.99.11                    22 July 1993                         FLOCK(2)