´ÙÀ½ À§·Î ÀÌÀü ¸ñÂ÷ ¸®´ª½º ÇÁ·Î±×·¡¸Ó¸¦ À§ÇÑ °¡À̵å

½Ã½ºÅÛ È£Ãâ:semget() (SYSTEM CALL:semget())

»õ·Î¿î ¼¼¸¶ÆÛ ÁýÇÕÀ» ¸¸µé°Å³ª Á¸ÀçÇÏ´Â ÁýÇÕ¿¡ Á¢±ÙÇϱâ À§ÇÏ¿©, semget() ½Ã½ºÅÛ È£ÃâÀ» »ç¿ëÇÑ´Ù.


  SYSTEM CALL: semget();                                                          

  PROTOTYPE: int semget ( key_t key, int nsems, int semflg );                                             
    RETURNS: semaphore set IPC identifier on success
             -1 on error: errno = EACCESS (permission denied)
                                  EEXIST (set exists, cannot create (IPC_EXCL))
                                  EIDRM (set is marked for deletion)
                                  ENOENT (set does not exist, no IPC_CREAT was used)
                                  ENOMEM (Not enough memory to create new set)
                                  ENOSPC (Maximum set limit exceeded)
  NOTES:

semget()ÀÇ Ã¹¹ø° ¾Æ±Ô¸ÕÆ®´Â ftok()ÀÇ È£Ãâ¿¡ ÀÇÇØ ¹ÝȯµÈ Å°°ªÀÌ´Ù. ÀÌ Å°°ªÀº Ä¿³Î¾È¿¡ Á¸ÀçÇÏ´Â ´Ù¸¥ ¼¼¸¶ÆÛ ÁýÇÕÀÇ Å°°ª°ú ºñ±³µÈ´Ù. À̶§ ¿­°Å³ª Á¢±ÙÇÏ´Â µ¿ÀÛÀº semflg ¾Æ±Ô¸ÕÆ®ÀÇ ³»¿ë¿¡ µû¶ó °áÁ¤µÈ´Ù.

IPC_CREAT
Ä¿³Î¾È¿¡ ÀÌ¹Ì Á¸ÀçÇÏÁö ¾Ê´Â´Ù¸é ¼¼¸¶ÆÛ ÁýÇÕÀ» ¸¸µç´Ù.
IPC_EXCL
IPC_CREAT¿Í °°ÀÌ »ç¿ëµÇ¾î, ¼¼¸¶ÆÛ°¡ ÀÌ¹Ì Á¸ÀçÇÏ¸é ½ÇÆÐÇÑ´Ù.
IPC_CREAT°¡ È¥ÀÚ »ç¿ëµÈ´Ù¸é, semget()Àº »õ·Î ¸¸µé¾îÁø ÁýÇÕÀÇ ¼¼¸¶ÆÛ ÁýÇÕ È®ÀÎÀÚ (the semaphore set identifier)¸¦ ¹ÝȯÇϰųª °°Àº Å°°ªÀ» °¡Áö°í ÀÌ¹Ì Á¸ÀçÇÏ´Â ÁýÇÕÀÇ È®ÀÎÀÚ¸¦ ¹ÝȯÇÑ´Ù. IPC_EXCL°¡ IPC_CREAT¿Í ÇÔ²² ¾²¿´´Ù¸é, »õ ÁýÇÕÀ» ¸¸µé°Å³ª ÀÌ¹Ì ÁýÇÕÀÌ Á¸ÀçÇÑ´Ù¸é -1 °ªÀ» °¡Áö°í È£Ãâ¿¡ ½ÇÆÐÇÑ´Ù. IPC_EXCLÀº ±× ÀÚü·Î´Â Àǹ̰¡ ¾øÁö¸¸, IPC_CREAT¿Í Á¶ÇÕµÇ¾î ¾²¿©Áú ¶§ Á¸ÀçÇÏÁö¾Ê´Â ¼¼¸¶ÆÛ¸¦ Á¢±Ù(access)Çϱâ À§ÇØ ¿­·ÁÁö´Â °ÍÀ» ¸·´Â ÀåÄ¡·Î »ç¿ëµÉ ¼ö ÀÖ´Ù.

½Ã½ºÅÛ V IPCÀÇ ´Ù¸¥ Çüŵéó·³ ºÎ°¡ÀûÀÎ 8Áø ¸ðµå°¡ ¼¼¸¶ÆÛ ÁýÇÕÀÇ Çã°¡»çÇ× ÇüÅ¿¡ ¸¶½ºÅ©·Î ORµÉ ¼ö ÀÖ´Ù.

nsems ¾Æ±Ô¸ÕÆ®´Â »õ ÁýÇվȿ¡¼­ ¸¸µé¾îÁ®¾ß ÇÏ´Â ¼¼¸¶ÆÛÀÇ °¹¼ö¸¦ ÁöÁ¤ÇÑ´Ù. ÀÌ°ÍÀº ¾Õ¿¡¼­ ¼³¸íÇß´ø °¡»óÀÇ Àμâ¹æÀÇ ÇÁ¸°ÅÍÀÇ °¹¼ö¸¦ ÀǹÌÇÑ´Ù. ÁýÇÕ¾ÈÀÇ ÃʤÀ´ë ¼¼¸¶ÆÛÀÇ °¹¼ö´Â linux/sem.h¿¡ Á¤ÀÇ µÇ¾îÀÖ´Ù.

	#define SEMMSL	32	/* <=512 id´ç ¼¼¸¶ÆÛÀÇ ÃÖ´ë °¹¼ö */
ÀÌ¹Ì Á¸ÀçÇÏ´Â ÁýÇÕÀ» ¸íÈ®È÷ ¿­°í ÀÖ´Ù¸é, nsems ¾Æ±Ô¸ÕÆ®´Â ¹«½ÃµÊ¿¡ ÁÖ¸ñÇضó.

¼¼¸¶ÆÛ ÁýÇÕÀ» ¸¸µé°í ¿©´Â wrapper ÇÔ¼ö¸¦ ¸¸µé¾î º¸ÀÚ:


int open_semaphore_set( key_t keyval, int numsems )
{
        int     sid;

        if ( ! numsems )
                return(-1);
        
        if((sid = semget( mykey, numsems, IPC_CREAT | 0660 )) == -1)
        {
                return(-1);
        }
        
        return(sid);
}

0600ÀÇ ¸í½ÃÀûÀÎ Çã°¡»çÇ×À» »ç¿ëÇÔ¿¡ ÁÖÀÇÇضó. ÀÌ ÀÛÀº ÇÔ¼ö´Â ¼¼¸¶ÆÛ ÁýÇÕ È®ÀÎÀÚ(int)¸¦ ¹ÝȯÇϰųª ¿¡·¯½Ã -1À» ¹ÝȯÇÑ´Ù. »õ ÁýÇÕÀÌ ¸¸µé¾îÁ³´Ù¸é, °ø°£À» ÇÒ´çÇϱâ À§ÇØ ¼¼¸¶ÆÛÀÇ °¹¼ö¿Í ¸¶Âù°¡Áö·Î Å°°ªÀÌ ³Ñ°ÜÁ®¾ß ÇÑ´Ù. ÀÌÀåÀÇ ³¡¿¡¼­ Ç¥ÇöµÉ ¿¹Á¦¿¡¼­, ¼¼¸¶ÆÛ ÁýÇÕÀÌ Á¸ÀçÇÏ´ÂÁö Á¸ÀçÇÏÁö ¾Ê´ÂÁö¸¦ °áÁ¤Çϱâ À§ÇÑ IPC_EXCL Ç÷¡±×ÀÇ »ç¿ë¿¡ ÁÖ¸ñÇضó.


ÀÌÀü:³»ºÎ ÀÚ·á ±¸Á¶ (Internal Data Structures) ´ÙÀ½:½Ã½ºÅÛ È£Ãâ:semop() (SYSTEM CALL:semop())

Copyright (c) 1996,1997 by Euibeom.Hwang & SangEun.Oh All Rights Reserved

Email To:Webmaster , Another address
LAST UPDATE Nov 25,1997
Created Nov 24,1997