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

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

»õ·Î¿î ¸Þ¼¼Áö Å¥¸¦ ¸¸µé°Å³ª Á¸ÀçÇϴ ť¿¡ Á¢±ÙÇϱâ À§ÇØ, shmget() ½Ã½ºÅÛ È£ÃâÀÌ »ç¿ëµÈ´Ù.


  SYSTEM CALL: shmget();                                                          

  PROTOTYPE: int shmget ( key_t key, int size, int shmflg );                                             
    RETURNS: shared memory segment identifier on success                                                       
             -1 on error: errno = EINVAL (Invalid segment size specified)
                                  EEXIST (Segment exists, cannot create)
                                  EIDRM (Segment is marked for deletion, or was removed)
                                  ENOENT (Segment does not exist)
                                  EACCES (Permission denied)
                                  ENOMEM (Not enough memory to create segment)
  NOTES:

À̽ÃÁ¡¿¡¼­ ÀÌ·± Ưº°ÇÑ È£ÃâÀº °ÅÀÇ ¾Ë°íÀÖ´Â °Íó·³ º¸¿©¾ß ÇÑ´Ù. ÀÌ°ÍÀº ¸Þ¼¼Áö Å¥¿Í ¼¼¸¶ÆÛ ÁýÇÕÀÇ get È£Ãâ°ú ¸Å¿ì ºñ½ÁÇÏ´Ù.

shmget()ÀÇ Ã¹¹ø° ¾Æ±Ô¸ÕÆ®´Â Å°°ªÀÌ´Ù(ftok()È£Ãâ¿¡ ÀÇÇØ ¹ÝȯµÈ). ÀÌ Å°°ªÀº Ä¿³Î¾È¿¡ Á¸ÀçÇÏ´Â ´Ù¸¥ °øÀ¯ ¸Þ¸ð¸® ¼¼±×¸ÕÆ®ÀÇ Å°°ª°ú ºñ±³µÇ¾îÁø´Ù. À̶§, ¿­±â ³ª Á¢±Ù µ¿ÀÛÀº shmflg ¾Æ±Ô¸ÕÆ®ÀÇ ³»¿ë¿¡ ´Þ·ÁÀÖ´Ù.

IPC_CREAT

Ä¿³Î¾È¿¡ ÀÌ¹Ì Á¸ÀçÇÏÁö ¾Ê´Â´Ù¸é ¼¼±×¸ÕÆ®¸¦ ¸¸µç´Ù.

IPC_EXCL

IPC_CREAT¿Í ÇÔ²² »ç¿ëµÉ ¶§, ¼¼±×¸ÕÆ®°¡ ÀÌ¹Ì Á¸ÀçÇÏ¸é ½ÇÆÐÇÑ´Ù.

IPC_CREAT°¡ È¥ÀÚ »ç¿ëµÇ¸é, shmget()Àº »õ·Ó°Ô ¸¸µé¾îÁø ¼¼±×¸ÕÆ®ÀÇ ¼¼±×¸ÕÆ® È®ÀÎÀÚ¸¦ ¹ÝȯÇϰųª °°Àº Å°°ªÀ» °¡Áø ¼¼±×¸ÕÆ®°¡ Á¸ÀçÇÏ¸é ±× ¼¼±×¸ÕÆ®ÀÇ È®ÀÎÀÚ¸¦ ¹ÝȯÇÑ´Ù. IPC_EXCLÀÌ IPC_CREAT¿Í ÇÔ²² »ç¿ëµÈ´Ù¸é, »õ·Î¿î ¼¼±×¸ÕÆ®°¡ ¸¸µé¾î Áö°Å³ª ¼¼±×¸ÕÆ®°¡ Á¸ÀçÇϸé, -1°ªÀ» °¡Áö¸ç È£ÃâÀº ½ÇÆÐÇÑ´Ù. IPC_EXCLÀº ±× ÀÚü·Î´Â ¾µ¸ð°¡ ¾øÁö¸¸, IPC_CREAT¿Í Á¶ÇÕµÉ ¶§, Á¸ÀçÇÏÁö ¾Ê´Â ¼¼±×¸ÕÆ®°¡ Á¢±ÙÀ» À§ÇØ ¿­¸®´Â °ÍÀ» ¸·´Âµ¥ »ç¿ëµÈ´Ù.

´Ù½Ã Çѹø, ºÎ°¡ÀûÀÎ 8Áø ¸ðµå´Â ¸¶½ºÅ©¾È¿¡ ORµÉ ¼ö ÀÖ´Ù.

°øÀ¯ ¸Þ¸ð¸® ¼¼±×¸ÕÆ®¸¦ ¸¸µé°í À§Ä¡½ÃÅ°±â À§ÇÑ wrapper ÇÔ¼ö¸¦ ¸¸µé¾î º¸ÀÚ:


int open_segment( key_t keyval, int segsize )
{
        int     shmid;
        
        if((shmid = shmget( keyval, segsize, IPC_CREAT | 0660 )) == -1)
        {
                return(-1);
        }
        
        return(shmid);
}

¸í½ÃÀûÀÎ Çã°¡»çÇ×À¸·Î 0660À» »ç¿ëÇßÀ½¿¡ ÁÖ¸ñÇ϶ó. ÀÌ ÀÛÀº ÇÔ¼ö´Â °øÀ¯ ¸Þ¸ð¸® ¼¼±×¸ÕÆ®ÀÇ È®ÀÎÀÚ(int)¸¦ ¹ÝÈ­Çϰųª, ¿¡·¯½Ã -1À» ¹ÝȯÇÑ´Ù. Å°°ª°ú ¿ä±¸µÇ´Â ¼¼±×¸ÕÆ® Å©±â (¹ÙÀÌÆ® ´ÜÀ§)´Â ¾Æ±Ô¸ÕÆ®·Î ³Ñ°ÜÁø´Ù.

ÇÁ·Î¼¼½º°¡ ÁÖ¾îÁø ¼¼±×¸ÕÆ®ÀÇ À¯È¿ÇÑ IPC È®ÀÎÀÚ¸¦ °¡Áø ÈÄ, ´ÙÀ½ ´Ü°è´Â ÇÁ·Î¼¼½º°¡ ÀÚ½ÅÀÇ ÁÖ¼Ò °ø°£¿¡ ¼¼±×¸ÕÆ®¸¦ ±×¸®°Å³ª(map) ºÙÀÌ´Â(attach) °ÍÀÌ´Ù.


ÀÌÀü:³»ºÎ¿Í »ç¿ëÀÚ ÀÚ·á ±¸Á¶ ´ÙÀ½:½Ã½ºÅÛ È£Ãâ:shmat()

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

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