semctl

å称
     semctl — ã»ããã©éåã«å¯¾ããæä½ãå¶å¾¡ãã

ã©ã¤ãã©ãª
     Standard C Library (libc, -lc)

æ¸å¼
     <sys/types.h> <sys/ipc.h> <sys/sem.h> int semctl(int semid, int semnum,
     int cmd, ...)

解説
     semctl() ã·ã¹ãã ã³ã¼ã«ã¯ã cmd ã示ãæä½ã semid
     ã§ç¤ºãããã»ããã©éåã«å¯¾ãã¦å®è¡ãã¾ãã ããå¤ã® cmd ã«å¯¾ãã¦ã¯ã4 çªç®ã®å¼æ°
     union semun arg ãå¿è¦ã§ãã arg å¼æ°ã使ç¨ããã³ãã³ãã®å ´åã union semun
     ã¯æ¬¡ã®ããã«å®ç¾©ããã¾ã:

     union semun {
             int     val;            /*  SETVAL ç¨ã®å¤ */
             struct  semid_ds *buf;  /*  IPC_STAT ããã³ IPC_SET ç¨ã®ãããã¡ */
             u_short *array;         /*  GETALL ããã³ SETALL ç¨ã®éå */
     };

     ã³ãã³ãã¯æ¬¡ã®ããã«å®è¡ããã¾ã:

     IPC_STAT     ã»ããã©éåã® struct semid_ds ãåå¾ãã arg.buf ãæãã¡ã¢ãªã«ä¿å‐
                  ãã¾ãã

     IPC_SET      ã»ããã©éåã® struct semid_ds ã®ã¡ã³ã sem_perm.uid,
                  sem_perm.gid ããã³ sem_perm.mode ãã arg.buf
                  ãæãæ§é ä½ã®ã¡ã³ãã¨ä¸è´ããããã«å¤æ´ãã¾ãã å¼ã³åºãåãã‐
                  ã»ã¹ã®å®å¹ã¦ã¼ã¶ ID ã¯ã sem_perm.uid ã¾ã㯠sem_perm.cuid
                  ã®ã©ã¡ããã¨ä¸è´ããå¿è¦ããããã
                  ã¾ãã¯ã¹ã¼ãã¦ã¼ã¶ç¹æ¨©ãæã£ã¦ããå¿è¦ãããã¾ãã

     IPC_RMID     ã»ããã©éåããã ã¡ã«ã·ã¹ãã ããåé¤ãã¾ãã å¼ã³åºãåããã»ã¹ã®å®å¹ã¦ã¼ã¶
                  ID ãã»ããã©éåã® sem_perm.uid ã¾ã㯠sem_perm.cuid ã¨ç‐
                  ããããã¾ãã¯ããã»ã¹ãã¹ã¼ãã¦ã¼ã¶ç¹æ¨©ãæã£ã¦ããå¿è¦ãããã¾ãã

     GETVAL       ã»ããã©çªå· semnum ã®å¤ãè¿ãã¾ãã

     SETVAL       ã»ããã©çªå· semnum ã®å¤ã arg.val ã«è¨å®ãã¾ãã ããããããã»ã¹ä¸‐
                  ã®ããã®ã»ããã©ã«å¯¾ããæªé©ç¨ã®çµäºæ調æ´å¤ã¯ã æ¶ããã¾ãã

     GETPID       ã»ããã©çªå· semnum ã«ã¤ãã¦æä½ãå®è¡ããæå¾ã®ããã»ã¹ã®ããã»ã¹ ID
                  ãè¿ãã¾ãã

     GETNCNT      ã»ããã©çªå· semnum ã®å¤ãç¾å¨ã®å¤ãã大ãããªãã®ãå¾ã£ã¦ãããã‐
                  ã»ã¹ã®æ°ãè¿ãã¾ãã

     GETZCNT      ã»ããã©çªå· semnum ã®å¤ã 0 ã«ãªãã®ãå¾ã£ã¦ããããã»ã¹ã®æ°ãè¿ãã¾ãã

     GETALL       éååã®ãã¹ã¦ã®ã»ããã©ã®å¤ã arg.array ãæãéååã¸åå¾ãã¾ãã

     SETALL       éååã®ãã¹ã¦ã®ã»ããã©ã®å¤ã arg.array ãæãéååã®å¤ã«è¨å®ãã¾ãã
                  ããããããã»ã¹ä¸ã®ããã®éåã«å±ãããã¹ã¦ã®ã»ããã©ã«å¯¾ããæªé©ç¨ã®
                  çµäºæ調æ´å¤ã¯ãæ¶ããã¾ãã

     struct semid_ds ã¯æ¬¡ã®ããã«å®ç¾©ããã¾ã:

     struct semid_ds {
             struct  ipc_perm sem_perm;      /* æä½ãã¼ããã·ã§ã³æ§é ä½ */
             struct  sem *sem_base;  /* éååã®æåã®ã»ããã©ã¸ã®ãã¤ã³ã¿ */
             u_short sem_nsems;      /* éååã®ã»ããã©ã®æ° */
             time_t  sem_otime;      /* æå¾ã®æä½æå» */
             long    sem_pad1;       /* SVABI/386 ã«ããã¨ãããå¿è¦ */
             time_t  sem_ctime;      /* æå¾ã®å¤æ´æå»
                                      * 1970/01/01 00:00:00 GMT
                                      * ããã®ç§åä½ã®çµéæé
                                      */
             long    sem_pad2;       /* SVABI/386 ã«ããã¨ãããå¿è¦ */
             long    sem_pad3[4];    /* SVABI/386 ã«ããã¨ãããå¿è¦ */
     };

æ»ãå¤
     å¦çãæ£å¸¸ã«å®äºããã¨ã cmd ã GETVAL, GETPID, GETNCNT, GETZCNT
     ã®ã©ããã§ããã¨ãã semctl() ã¯å¯¾å¿ããå¤ãè¿ãã¾ãã ããã§ãªãå ´å㯠0 ãè¿ãã¾ãã
     å¦çã«å¤±æããå ´åã¯ã-1 ãè¿ããã¨ã©ã¼ã示ãããã« errno ãè¨å®ãã¾ãã

ã¨ã©ã¼
     semctl() ã·ã¹ãã ã³ã¼ã«ã¯æ¬¡ã®å ´åã«å¦çã«å¤±æãã¾ã:

     [EINVAL]           semid ã«å¯¾å¿ããã»ããã©éåãããã¾ããã

     [EINVAL]           semnum
                        å¼æ°ããæå®ã®ã»ããã©éåã«å¯¾ãã¦æå¹ãªã»ããã©ã®ç¯å²åã«ããã¾ããã

     [EPERM]            å¼ã³åºãåããã»ã¹ã®å®å¹ã¦ã¼ã¶ ID ãã
                        ã»ããã©éåã®ææèã¾ãã¯ä½æèã®ã¦ã¼ã¶ ID ã¨ä¸è´ãã¾ããã

     [EACCES]           æä½ã¨ã»ããã©éåã®ã¢ã¼ãã®éã«ä¸ä¸è´ããã£ãããã«
                        ãã¼ããã·ã§ã³ãæå¦ããã¾ããã

     [ERANGE]           SETVAL ã¾ã㯠SETALL ããã»ããã©ã [0 .. SEMVMX]
                        ã®è¨±å®¹ç¯å²å¤ã«è¨å®ãããã¨ãã¾ããã

é¢é£é ç®
     semget(2), semop(2)

ãã°
     SETALL ã¯ãã¨ã©ã¼ãè¿ãåã«ããã¤ãã®ã»ããã©è¦ç´ ãæ´æ°ãããã¨ãããã¾ãã