semget

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



åå
       semget - ã»ããã©ã¼éåã®èå¥åãåå¾ãã

æ¸å¼
       # include <sys/types.h>
       # include <sys/ipc.h>
       # include <sys/sem.h>

       int semget ( key_t key, int nsems, int semflg )

説æ
       ãã®é¢æ°ã¯ key å¼ãæ°ã®å¤ã«é¢é£ããã»ããã©ã¼éå(semaphore set)ã® èå¥å‐
       (identifier)ãè¿ãã key ã®å¤ã IPC_PRIVATE ã®å ´åã«ã¯ nsems
       åã®ã»ããã©ã¼ãããªãæ°ããéåãä½æãããã key ã IPC_PRIVATE ã§ãªãã¦ã key
       ã«é¢é£ããã»ããã©ã¼éåãåå¨ãã semflg ã« IPC_CREAT ãæå®ããã( semflg&IPC_CREAT
       ãã¼ãã§ãªã) å ´åã«ã¯ nsems åã®ã»ããã©ã¼ãããªãæ°ããéåãä½æãããã semflg ã«
       IPC_CREAT 㨠IPC_EXCL ãè¨å®ããã¨ã open(2) ã·ã¹ãã ã»ã³ã¼ã«ã® mode å¼ãæ°ã«
       O_CREAT 㨠O_EXCL ãæå®ããã®ã¨åãå½¹å²ãæããåå¨ããã»ããã©ã¼éåãåªåããã ä¾ãã°
       semflg ã« IPC_CREAT 㨠IPC_EXCL ã®ä¸¡æ¹ãæå®ãããã key
       ã«ã¤ãã¦ã»ããã©ã¼éåãæ¢ã«åå¨ãã¦ããå ´åã semget é¢æ°ã¯å¤±æããã

       ä½ææã«ã semflg å¼ãæ°ã®ä¸ä½ 9 ãããã¯ã»ããã©ã¼éåã®ã¢ã¯ã»ã¹è¨±å¯(ææè(owner)ã
       ã°ã«ã¼ã(group)ãä»è(other))ãå®ç¾©ãã open(2) ã creat(2)
       ã·ã¹ãã ã»ã³ã¼ã«ã®ã¢ã¯ã»ã¹è¨±å¯ãã©ã¡ã¼ã¿ã¼ã¨åãæå³ãæã¤ã
       (ããããå®è¡(execute)許å¯ã¯ã·ã¹ãã ã«ãã£ã¦ä½¿ç¨ããã¦ããªãã
       æ¸ãè¾¼ã¿(write)許å¯ã¯ã»ããã©ã¼éåã®å ´åã¯å¤æ´(alter)許å¯ã¨ãã¦æ©è½ããã)

       ããã«ãä½æã®éãã·ã¹ãã ã»ã³ã¼ã«ã¯ã·ã¹ãã ã»ã»ããã©ã¼éåã® ãã¼ã¿æ§é ä½ semid_ds
       ãåæåãããæ§é ä½ã¯:

              sem_perm.cuid 㨠sem_perm.uid ã«ã¯å¼ã³åºãããã‐
              ã»ã¹ã®å®å¹(effective)ã¦ã¼ã¶ã¼ID ãè¨å®ãããã

              sem_perm.cgid 㨠sem_perm.gid ã«ã¯å¼ã³åºãããã‐
              ã»ã¹ã®å®å¹(effective)ã°ã«ã¼ãID ãè¨å®ãããã

              sem_perm.mode ã®ä¸ä½ 9 ãããã«ã¯ semflg ã®ä¸ä½ 9 ããããè¨å®ãããã

              sem_nsems ã«ã¯ nsems ã®å¤ãè¨å®ãããã

              sem_otime ã«ã¯ 0 ãè¨å®ãããã

              sem_ctime ã«ã¯ç¾å¨ã®æå»ãè¨å®ãããã

       ã·ã¹ãã ã»ã³ã¼ã«ãã»ããã©ã¼éåãä½æããªãå ´å㯠nsems å¼ãæ°ã¯ 0 ã«ã§ããã
       ãã®ä»ã®å ´å㯠nsems 㯠0 ãã大ãããªããã°ãªãããsemid
       ãã¨ã®ã»ããã©ã¼ã®æ大æ°ã¨åããå°ãã ãªããã°ãªããªã (SEMMSL)ã

       ããã»ããã©ã¼éåãæ¢ã«åå¨ãããªãã°ãã¢ã¯ã»ã¹è¨±å¯ãæ¤æ»ããã
       ç ´å£(destruction)ãã¼ã¯ããªãããã§ãã¯ãããã

è¿ãå¤
       æåããå ´åãè¿ãå¤ã¯ã»ããã©ã¼éåã®èå¥å(æ£ã®æ´æ°)ã§ããã ããã§ãªããã° -1 ãè¿ããã
       errno ã«ãã®ã¨ã©ã¼ã示ãããã

ã¨ã©ã¼
       失æããå ´åã«ã¯ã errno ã«ã¯ä»¥ä¸ã®å¤ã®ã©ãããè¨å®ããã:

       EACCES     key ã«å¯¾å¿ããã»ããã©ã¼éåã¯åå¨ãããã å¼ã³åºãããã‐
                  ã»ã¹ããã®éåã«ã¤ãã¦ã®ã¢ã¯ã»ã¹è¨±å¯ãæããªãã

       EEXIST     key ã«å¯¾å¿ããã»ããã©ã¼éåãåå¨ãã semflg ã« IPC_CREAT ã¨
                  IPC_EXCL ãæå®ãããã

       EIDRM      ã»ããã©ã¼éåã«åé¤(delete)ãã¼ã¯ãããã

       ENOENT     key ã«å¯¾å¿ããã»ããã©ã¼éåãåå¨ããã semflg ã« IPC_CREAT
                  ãæå®ããã¦ããªãã

       ENOMEM     ã»ããã©ã¼éåãä½æããªããã°ãªããªãããæ°ãããã¼ã¿æ§é ä½ã
                  ä½æããã®ã«ååãªã¡ã¢ãªãã·ã¹ãã ã«åå¨ããªãã

       ENOSPC     ã»ããã©ã¼éåãä½æããªããã°ãªããªãããã·ã¹ãã ã®ã»ããã©ã¼éåã® æ大æ°
                  (SEMMNI) ã¾ãã¯ã·ã¹ãã å¨ä½ã®ã»ããã©ã¼ã®æå¤§æ° (SEMMNS)
                  ãè¶ãã¦ãã¾ãã

注æ
       IPC_PRIVATE ã¯ãã©ã°ã»ãã£ã¼ã«ãã§ã¯ãªã key_t åã§ããã ãã®ç¹å¥ãªå¤ã key
       ã¨ãã¦ä½¿ç¨ããããªãã°ãã·ã¹ãã ã»ã³ã¼ã«ã¯ semflg ã®ä¸ä½ 9
       ããããé¤ãã¦å¨ã¦ãç¡è¦ã㦠(æåããå ´åã¯)æ°ããã»ããã©ã¼éåãä½æããã

       以ä¸ã¯ semget ã³ã¼ã«ã«å½±é¿ããã»ããã©ã¼éåã®è³æºã®å¶éã§ãã:

       SEMMNI     ã·ã¹ãã å¨ä½ã®ã»ããã©ã¼éåã®æ大æ°: æ¹éä¾åã

       SEMMSL     semid ãããã®ã»ããã©ã¼ã®æ大æ°: å®è£ä¾å(ç¾å¨ã¯ 500).

       SEMMNS     ã·ã¹ãã å¨ä½ã®ã»ããã©ã¼ã®æ大æ°: æ¹éä¾åã SEMMSL * SEMMNI
                  ããã大ããªå¤ã¯ç¡æå³ã§ããã

ãã°
       IPC_PRIVATE ã®ä½¿ç¨ãã¦ãå²å½ã¦ãããã»ããã©ã¼éåã«å¯¾ãã¦ä»ã®ããã»ã¹ã
       ã¢ã¯ã»ã¹ãããã¨ãç¦æ¢ãããã¨ã¯ã§ããªãã

       ãã¡ã¤ã«ã¨åæ§ã«ãã»ããã©ã¼éåã«å¯¾ãã¦ããã»ã¹ã®æä»çãªã¢ã¯ã»ã¹ã
       ä¿è¨¼ããåºæã®æ¹æ³ã¯ç¾å¨ã®ã¨ããåå¨ããªãã semflg ã« IPC_CREAT 㨠IPC_EXCL
       ã®ä¸¡æ¹ãæå®ãããã¨ã¯(æåããå ´åã«)æ°ããã»ããã©ã¼éåãä½æããã
       ãã¨ã®ã¿ãä¿è¨¼ãããã»ããã©ã¼éåã¸ã®æä»çã¢ã¯ã»ã¹ãå«ãã§ããªãã

       éååã®åã»ããã©ã¼ã«ã¤ãã¦ãã¼ã¿æ§é ä½ã¯ãã®ã·ã¹ãã ã»ã³ã¼ã«ã§ã¯
       åæåãããªãããããã®ãã¼ã¿æ§é ä½ãåæåããããã«ã¯ semctl(2) ã³ã¼ã«ãå®è¡ãã¦
       ã§ã»ããã©ã¼éåã« SETVAL ã SETALL å½ä»¤ãè¡ãå¿è¦ãããã

æºæ
       SVr4, SVID.  SVr4 ã«ã¯ä»ã« EINVAL, EFBIG, E2BIG, EAGAIN, ERANGE, EFAULT
       ã®ã¨ã©ã¼ç¶æã«ã¤ãã¦ã®è¨è¿°ãããã

é¢é£é ç®
       ftok(3), ipc(5), semctl(2), semop(2).



Linux 0.99.13                  November 1, 1993                      SEMGET(2)