SYSTEM CALL: semop(); PROTOTYPE: int semop ( int semid, struct sembuf *sops, unsigned nsops); RETURNS: 0 on success (all operations performed) -1 on error: errno = E2BIG (nsops greater than max number of ops allowed atomically) EACCESS (permission denied) EAGAIN (IPC_NOWAIT asserted, operation could not go through) EFAULT (invalid address pointed to by sops argument) EIDRM (semaphore set was removed) EINTR (Signal received while sleeping) EINVAL (set doesn't exist, or semid is invalid) ENOMEM (SEM_UNDO asserted, not enough memory to create the undo structure necessary) ERANGE (semaphore value out of range) NOTES:
sops ¾Æ±Ô¸ÕÆ®´Â sembuf ŸÀÔÀÇ ¹è¿À» °¡¸®Å²´Ù. ÀÌ ±¸Á¶´Â ´ÙÀ½°ú °°ÀÌ linux/sem.h¿¡ ¼±¾ðµÇ¾î ÀÖ´Ù.:
/* semop ½Ã½ºÅÛ È£ÃâÀº ÀÌ·¯ÇÑ ¹è¿À» °®´Â´Ù */ struct sembuf { ushort sem_num; /* ¹è¿¾È¿¡¼ÀÇ ¼¼¸¶ÆÛ À妽º */ short sem_op; /* ¼¼¸¶ÆÛ µ¿ÀÛ */ short sem_flg; /* µ¿ÀÛ Ç÷¡±× */ };
sem_op°¡ ¾ç¼öÀ̸é, ±×°ªÀº ¼¼¸¶ÆÛ¿¡ ´õÇØÁø´Ù. ÀÌ°ÍÀº ÀÀ¿ëÇÁ·Î±×·¥ÀÇ ¼¼¸¶ÆÛ ÁýÇÕ¿¡°Ô ÀÚ¿øÀ» µ¹·ÁÁشٴ °ÍÀ» ÀǹÌÇÑ´Ù. ÀÚ¿øµéÀº ´õ ÀÌ»ó ÇÊ¿äÇÏÁö ¾ÊÀ» ¶§ ¼¼¸¶ÆÛ ÁýÇÕ¿¡°Ô µ¹·ÁÁÖ¾î¾ß ÇÑ´Ù.
³¡À¸·Î, sem_op°¡ 0(zero)À̸é, È£ÃâÇÑ ÇÁ·Î¼¼½º´Â ¼¼¸¶ÆÛÀÇ °ªÀÌ 0ÀÌ µÉ¶§±îÁö ÀáÀ» Àß °ÍÀÌ´Ù. ÀÌ°ÍÀº ¼¼¸¶ÆÛ°¡ 100% È°¿ëµÉ ¶§±îÁö ±â´Ù¸°´Ù´Â °ÍÀ» ÀǹÌÇÑ´Ù. ÀÌ·¯ÇÑ ÁÁÀº ¿¹´Â 100% È°¿ë¿¡ µµ´ÞÇϵµ·Ï ¼¼¸¶ÆÛÀÇ Å©±â¸¦ µ¿ÀûÀ¸·Î Á¶Á¤ÇÏ´Â, ¼öÆÛÀ¯Àú(superuser)ÀÇ ±ÇÇÑÀ» °¡Áö°í ¼öÇàµÇ´Â ´ë¸ó(daemon)ÀÏ °ÍÀÌ´Ù.
sem_op È£ÃâÀ» ¼³¸íÇϱâ À§ÇÏ¿©, ¿ì¸®ÀÇ Àμâ¹æ ½Ã³ª¸®¿À¸¦ ´Ù½Ã Çѹø »ý°¢Çغ¸ÀÚ. Çѹø¿¡ ÇÑ°¡Áö Àϸ¸À» ¼öÇàÇÒ ¼ö ÀÖ´Â ¿ÀÁ÷ ÇÑ´ëÀÇ ÇÁ¸°Å͸¸ ÀÖ´Ù°í °¡Á¤ÇÏÀÚ. ¿ì¸®´Â ÇÑ°³ÀÇ ¼¼¸¶ÆÛ(ÇÑ°³ÀÇ ÇÁ¸°ÅÍ)¸¸À» °¡Áø ¼¼¸¶ÆÛ ÁýÇÕÀ» ¸¸µé°í ¼¼¸¶ÆÛÀÇ ÃʱⰪÀ» 1·Î ÃʱâÈÇÑ´Ù.(Çѹø¿¡ ÇÑ°¡Áö ÀÏ)
¿ì¸®°¡ ÀÌ ÇÁ¸°ÅÍ¿¡ ÀÛ¾÷À» º¸³»°íÀÚ ÇÒ ¶§¸¶´Ù, ÀÚ¿øÀÌ ÀÌ¿ë°¡´ÉÇÑÁö¸¦ È®ÀÎÇؾßÇÒ ÇÊ¿ä°¡ ÀÖ´Ù. ¿ì¸®´Â ¼¼¸¶ÆÛ·Î ºÎÅÍ ÇÑ°³ÀÇ ´ÜÀ§(unit)¸¦ ¾ò´Â °ÍÀ¸·Î ÀÌ·¯ÇÑ ÀÛ¾÷À» ¼öÇàÇÑ´Ù. µ¿ÀÛÀ» ¼öÇàÇϱâ À§ÇØ sembuf ¹è¿À» ÀûÀç(load)ÇÏÀÚ.:
struct sembuf sem_lock = { 0, -1, IPC_NOWAIT };
if((semop(sid, &sem_lock, 1) == -1) perror("semop");
ÀμâÀÛ¾÷ÀÌ ¿Ï·áµÇ¾úÀ» ¶§, ¼¼¸¶ÆÛ ÁýÇÕÀ¸·Î ÀÚ¿øÀ» µ¹·ÁÁÖ¾î¾ß ÇÑ´Ù. ±×·¡¾ß ´Ù¸¥ »ç¶÷ÀÌ ÇÁ¸°Å͸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù.
struct sembuf sem_unlock = { 0, 1, IPC_NOWAIT };
Copyright (c) 1996,1997 by Euibeom.Hwang & SangEun.Oh All Rights Reserved
Email To:Webmaster ,
Another address
LAST UPDATE Nov 25,1997
Created Nov 25,1997