semctl

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



åå
       semctl - ã»ããã©ã¼ã®å¶å¾¡æä½ãè¡ãªã

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

       int semctl ( int semid, int semnun, int cmd, union semun arg )

説æ
       ãã®é¢æ°ã¯ semid ã§æå®ãããã»ããã©ã¼éå(semaphore set)(ã¾ã㯠ã»ããã©ã¼éåã®
       sumnunçªç® ã®ã»ããã©ã¼)ã« cmd æå®ãããå¶å¾¡æä½ãè¡ãªããéåã®æåã®ã»ããã©ã¼ã¯
       semnun ã®å¤ 0 ã§ç¤ºãããã

       arg ã®åã¯å±ç¨ä½(union)ã§ãã

       union semun {
            int val; /* used for SETVAL only */
            struct semid_ds *buf; /* for IPC_STAT and IPC_SET */
            ushort *array;  /* used for GETALL and SETALL */
       };

       cmd ã®å¤ã¯

       IPC_STAT    ã»ããã©ã¼éåã®ãã¼ã¿æ§é ä½ã®æå ±ã arg.buf
                   ã§æããããããã¡ã¼ã¸ã³ãã¼ããã semnum å¼ãæ°ã¯ç¡è¦ããããå¼ã³åºãããã‐
                   ã»ã¹ã¯ãã®ã»ããã©ã¼éåã«å¯¾ãã èª‐
                   ã¿è¾¼ã¿ã¢ã¯ã»ã¹ã®æ¨©éãæããªããã°ãªããªãã

       IPC_SET     arg.buf ã§æå®ããã semid_ds
                   æ§é ä½ã®ã¡ã³ãã¼ã®ããã¤ãã®å¤ãã»ããã©ã¼éåã®ãã¼ã¿æ§é ä½ã«æ¸ãè¾¼ãã
                   sem_ctime ã¡ã³ãã¼ã®å¤ãæ´æ°ãããã arg.buf
                   ã«ãã£ã¦æå®ãããã¦ã¼ã¶ã¼ã®ä¸ãã semid_ds æ§é ä½
                   ã®ãã¡èæ®ãããã¡ã³ãã¼ã¯ä»¥ä¸ã®éã

                        sem_perm.uid
                        sem_perm.gid
                        sem_perm.mode  /* only lowest 9-bits */

                   å¼ã³åºããããã»ã¹ã®å®å¹(effective)ã¦ã¼ã¶ã¼ID
                   ã¯ã¹ã¼ãã¼ã»ã¦ã¼ã¶ã¼ãã
                   ãã®ã»ããã©ã¼éåã®ä½æè(creator)ãææè(owner)ã§ãªããã°ãªããªãã
                   semnum å¼ãæ°ã¯ç¡è¦ãããã

       IPC_RMID    ã»ããã©ã¼éåã¨ãã®ãã¼ã¿æ§é ä½ããã ã¡ã«åé¤(remove)ãã
                   å¾ã¡ç¶æã«ããããã»ã¹ãç®è¦ãããã(ãã㯠errno ã« EIDRM ãè¨‐
                   å®ãããã¨ã©ã¼ã¨ãã¦è¿ããããã¨ã«ããã) å¼ã³åºãããã‐
                   ã»ã¹ã®å®å¹(effective)ã¦ã¼ã¶ã¼ID ã¯ã¹ã¼ãã¼ã¦ã¼ã¶ã¼ãã
                   ãã®ã»ããã©ã¼éåã®ä½æè(creator)ãææè(owner)ã§ãªããã°ãªããªãã
                   semnum å¼ãæ°ã¯ç¡è¦ãããã

       GETALL      éåã®å¨ã¦ã®ã»ããã©ã¼ã® semval ã®å¤ã arg.array ã«è¿ãã semnum
                   å¼ãæ°ã¯ç¡è¦ãããã å¼ã³åºããããã»ã¹ã¯ãã®ã»ããã©ã¼éåã«èª‐
                   ã¿è¾¼ã¿ã¢ã¯ã»ã¹ã®æ¨©å©ãæããªããã° ãªããªãã

       GETNCNT     ã·ã¹ãã ã»ã³ã¼ã«ã¯éåã® semnumçªç® ã®ã»ããã©ã¼ã® semncnt
                   ã®å¤ãè¿ã(éåã® semnumçªç® ã®ã»ããã©ã¼ã® semval
                   ã®å¢å ãå¾ã£ã¦ããããã»ã¹ã®æ°)ã å¼ã³åºãããã‐
                   ã»ã¹ã¯ãã®ã»ããã©ã¼éåã«èªã¿è¾¼ã¿ã¢ã¯ã»ã¹ã®æ¨©å©ãæããªããã°
                   ãªããªãã

       GETPID      ã·ã¹ãã ã»ã³ã¼ã«ã¯éåã® semnumçªç® ã®ã»ããã©ã¼ã® sempid
                   ã®å¤ãè¿ãã(éåã® semnumçªç® ã®ã»ããã©ã¼ã«æå¾ã« semop
                   ã³ã¼ã«ãå®è¡ããããã»ã¹ã® pid)ã å¼ã³åºãããã‐
                   ã»ã¹ã¯ãã®ã»ããã©ã¼éåã«èªã¿è¾¼ã¿ã¢ã¯ã»ã¹ã®æ¨©å©ãæããªããã°
                   ãªããªãã

       GETVAL      ã·ã¹ãã ã»ã³ã¼ã«ã¯éåã® semnumçªç® ã®ã»ããã©ã¼ã® semval
                   ã®å¤ãè¿ãã å¼ã³åºããããã»ã¹ã¯ãã®ã»ããã©ã¼éåã«èª‐
                   ã¿è¾¼ã¿ã¢ã¯ã»ã¹ã®æ¨©å©ãæããªããã° ãªããªãã

       GETZCNT     ã·ã¹ãã ã»ã³ã¼ã«ã¯éåã® semnumçªç® ã®ã»ããã©ã¼ã® semzcnt
                   ã®å¤ãè¿ã(éåã® semnumçªç® ã®ã»ããã©ã¼ã® semval ã®å¤ã 0
                   ã«ãªãã®ãå¾ã£ã¦ããããã»ã¹ã®æ°)ã å¼ã³åºãããã‐
                   ã»ã¹ã¯ãã®ã»ããã©ã¼éåã«èªã¿è¾¼ã¿ã¢ã¯ã»ã¹ã®æ¨©å©ãæããªããã°
                   ãªããªãã

       SETALL      éåã®å¨ã¦ã®ã»ããã©ã¼ã® semval ã« arg.array ã§æå®ãããå¤ãè¨å®ããã
                   ãã®éåã® semid_ds æ§é ä½ã® sem_ctime ã¡ã³ãã¼ã®å¤ãæ´æ°ããã
                   å¨ã¦ã®ããã»ã¹ã®ã»ããã©ã¼ã®å¤æ´ã«ã¤ãã¦ã®ã¢ã³ãã¥ã»ã¨ã³ããªã¯
                   æ¶å»(clear)ãããã semval ã®å¤ã 0 ã«ãªããå¢å ããå ´åã¯å¾ã¡ã‐
                   ã¥ã¼(queue)ã§åæ¢(sleep)ãã¦ãã ããã»ã¹ã¯åé(awake)ãããã semnum
                   å¼ãæ°ã¯ç¡è¦ãããã å¼ã³åºãããã‐
                   ã»ã¹ã¯ãã®ã»ããã©ã¼éåã«å¤æ´ã¢ã¯ã»ã¹ã®æ¨©å©ãæããªããã° ãªããªãã

       SETVAL      éåã® semnumçªç®ã® ã»ããã©ã¼ã® semval ã« arg.val ã®å¤ãè¨‐
                   å®ããããã®éåã«é¢é£ãã semid_ds æ§é ä½ã® sem_ctime
                   ã¡ã³ãã¼ã®å¤ãæ´æ°ããã å¨ã¦ã®ãã‐
                   ã»ã¹ã®ã»ããã©ã¼ã®å¤æ´ã«ã¤ãã¦ã®ã¢ã³ãã¥ã»ã¨ã³ããªã¯æ¶å»ãããã
                   semval ã®å¤ã 0 ã«ãªããå¢å ããå ´åã¯å¾ã¡ãã¥ã¼(queue)ã§åæ‐
                   ¢(sleep)ãã¦ãã ããã»ã¹ã¯åé(awake)ãããã å¼ã³åºãããã‐
                   ã»ã¹ã¯ãã®ã»ããã©ã¼éåã«å¤æ´ã¢ã¯ã»ã¹ã®æ¨©å©ãæããªããã° ãªããªãã

è¿ãå¤
       失æããå ´åã¯ã·ã¹ãã ã»ã³ã¼ã«ã¯ -1 ãè¿ãã errno ã«ãã®ã¨ã©ã¼ã示ãã
       ããã§ãªããã°ã·ã¹ãã ã»ã³ã¼ã«ã¯ cmd ã«ãã£ã¦ä»¥ä¸ã®è² ã§ãªãå¤ãè¿ã:

       GETNCNT    semncnt ã®å¤ã

       GETPID     sempid ã®å¤ã

       GETVAL     semval ã®å¤ã

       GETZCNT    semzcnt ã®å¤ã

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

       EACCES     å¼ã³åºããããã»ã¹ã cmd
                  ãå®è¡ããã®ã«å¿è¦ãªã¢ã¯ã»ã¹è¨±å¯ãæã£ã¦ããªãã

       EFAULT     arg.buf ã¾ã㯠arg.array
                  ã§æããã¦ããã¢ãã¬ã¹ã«ã¢ã¯ã»ã¹ãããã¨ãã§ããªãã

       EIDRM      ã»ããã©ã¼éåãåé¤(remove)ãããã

       EINVAL     cmd ã¾ã㯠semid ã«ç¡å¹ãªå¤ãæå®ãããã

       EPERM      cmd å¼ãæ°ã« IPC_SET ã¾ã㯠IPC_RMID ãæå®ãããå¼ã³åºãããã‐
                  ã»ã¹ã®å®å¹(effective)ã¦ã¼ã¶ã¼ID ã
                  ãã®ã³ãã³ããå®è¡ãã権å©ãæã£ã¦ããªãã

       ERANGE     cmd å¼ãæ°ã« SETALL ã¾ã㯠SETVAL
                  ãæå®ããã(éåã®ã»ããã©ã¼ã®ã©ããã®) semval ã«è¨å®ãããå¤ã 0
                  ããå°ããããå®è£å¤ SEMVMX ããã大ããã

注æ
       IPC_INFO 㨠SEM_STAT 㨠SEM_INFO å¶å¾¡ã³ã¼ã«ã¯ ipcs(8) ãã‐
       ã°ã©ã ã«ãã£ã¦å²å½ãããè³æºã«ã¤ãã¦æå ±ãæä¾ããããã«ä½¿ç¨ãããã å°æ¥çã«ã¯ãããã¯
       proc ãã¡ã¤ã«ã»ã·ã¹ãã ã使ç¨ãããã®ã«ä¿®æ£ããã ãããããªãã

       以ä¸ã¯ semctl ã³ã¼ã«ã«å½±é¿ããã»ããã©ã¼éåã®ã·ã¹ãã å¶é:

       SEMVMX     semval ã®æå¤§å¤ : å®è£ä¾å(32767)ã

æºæ
       SVr4, SVID.  SVr4 ã«ã¯ä»ã« EINVAL, EOVERFLOW ã¨ã©ã¼ã«ã¤ãã¦ã®è¨è¿°ãããã

é¢é£é ç®
       ipc(5), shmget(2), shmat(2), shmdt(2).



Linux 0.99.13                  November 1, 1993                      SEMCTL(2)