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

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

ÀÌÀü¿¡ wrapper ÇÔ¼öµéÀÇ °³¹ßÀÌ Á¦°øµÇ¾úÁö¸¸, ÀÀ¿ëÇÁ·Î±×·¥¿¡¼­ ¸Þ¼¼Áö Å¥¸¦ ¸¸µé°í, È°¿ëÇϱâ À§ÇÑ °£´ÜÇÏ°í ¿ì¾ÆÇÑ Á¢±Ù¹æ¹ýÀ» °¡Áö°í ÀÖ´Ù. ÁÖ¾îÁø ¸Þ¼¼Áö Å¥¿Í ¿¬°üµÈ ³»ºÎ ±¸Á¶Ã¼¸¦ Á÷Á¢ Á¶Á¾Çϱâ À§ÇÑ Åä·Ð¿¡ µé¾î°¡ º¸ÀÚ.

¸Þ¼¼Áö Å¥ÀÇ ÅëÁ¦ µ¿ÀÛÀ» ¼öÇàÇϱâ À§ÇØ, msgctl() ½Ã½ºÅÛ È£ÃâÀ» »ç¿ëÇÑ´Ù.


  SYSTEM CALL: msgctl();
  PROTOTYPE: int msgctl ( int msgqid, int cmd, struct msqid_ds *buf );
    RETURNS: 0 on success
             -1 on error: errno = EACCES (No read permission and cmd is IPC_STAT)
                                  EFAULT (Address pointed to by buf is invalid with IPC_SET and
                                          IPC_STAT commands)
                                  EIDRM  (Queue was removed during retrieval)
                                  EINVAL (msgqid invalid, or msgsz less than 0)
                                  EPERM  (IPC_SET or IPC_RMID command was issued, but
                                          calling process does not have write (alter)
                                          access to the queue)
  NOTES:

³»ºÎ Ä¿³Î ÀÚ·á ±¸Á¶ÀÇ Á÷Á¢ÀûÀÎ Á¶Á¾Àº ¹ã ´Êµµ·Ï Àç¹Ì¸¦ °¡Á®´Ù ÁÙ ¼öµµ ÀÖ´Ù. ºÒÇེ·´°Ôµµ, ÇÁ·Î±×·¡¸ÓµéÀÇ ÀϺο¡°Ô ³²°ÜÁø ÀÓ¹«´Â À⵿»ç´ÏÀÎ IPC subsystemÀ» ÁÁ¾ÆÇÑ´Ù¸é Àç¹Ì·Î ºÐ·ùµÇ¾î Áú ¼ö ÀÖ´Ù. ¼±ÅÃµÈ ¸í·É¾î ÁýÇÕÀ» °¡Áö°í msgctl()¸¦ »ç¿ëÇÏ¿©, Àç³­À» ÀÏÀ¸Å³ °¡´É¼ºÀÌ ÀûÀº ¾ÆÀÌÅÛÀ» Á¶Á¾ÇÒ ¼ö ÀÖ´Â ´É·ÂÀ» °®´Â´Ù.

IPC_STAT

Å¥¿¡¼­ msqid_ds ±¸Á¶Ã¼¸¦ Á¶È¸ÇÏ¿© ¹öÆÛ ¾Æ±Ô¸ÕÆ®ÀÇ ÁÖ¼ÒÁö¿¡ ÀúÀåÇÑ´Ù.

IPC_SET

Å¥ÀÇ msqid_ds ±¸Á¶Ã¼ÀÇ ipc_perm ¸â¹öÀÇ °ªÀ» ÁöÁ¤ÇÑ´Ù. ¹öÆÛ ¾Æ±Ô¸ÕÆ®·Î ºÎÅÍ °ªÀ» ÃëÇÑ´Ù.

IPC_RMID

Ä¿³Î·Î ºÎÅÍ Å¥¸¦ Á¦°ÅÇÑ´Ù.

¸Þ¼¼Áö Å¥¿¡ ´ëÇÑ ³»ºÎ ÀÚ·á ±¸Á¶(msqid_ds)¿¡ ´ëÇØ ¾ð±ÞÇß´ø ³»¿ëÀ» »ó±âÇÏÀÚ. Ä¿³ÎÀº ½Ã½ºÅÛ¿¡ Á¸ÀçÇÏ´Â °¢°¢ÀÇ Å¥¿¡ ´ëÇØ ÀÌ·¯ÇÑ ±¸Á¶Ã¼¸¦ Çϳª¾¿ °¡Áö°í ÀÖ´Ù. IPC_STAT ¸í·É¾î¸¦ »ç¿ëÇÏ¿© °Ë»ç¸¦ À§ÇØ ÀÌ ±¸Á¶Ã¼ÀÇ º¹»çº»À» Á¶È¸ÇÒ ¼ö ÀÖ´Ù. ³»ºÎ ±¸Á¶¸¦ Á¶È¸ÇÏ¿© ³Ñ°ÜÁø ÁÖ¼Ò·Î º¹»çÇÏ´Â ºü¸¥ wrapper ÇÔ¼ö¸¦ »ìÆ캸ÀÚ.:


int get_queue_ds( int qid, struct msgqid_ds *qbuf )
{
        if( msgctl( qid, IPC_STAT, qbuf) == -1)
        {
                return(-1);
        }
        
        return(0);
}

³»ºÎ ¹öÆÛ·Î º¹»çÇÒ ¼ö ¾ø´Ù¸é È£ÃâÇÑ ÇÔ¼ö¿¡°Ô -1ÀÌ ¹ÝȯµÈ´Ù. ¸ðµç °ÍÀÌ Àß µÇ¸é, 0°ªÀÌ ¹ÝȯµÇ°í ³Ñ°ÜÁø ¹öÆÛ´Â ³Ñ°Ü¹ÞÀº Å¥ È®ÀÎÀÚ(queue identifier,qid)¿¡ ÀÇÇØ ´ëÇ¥µÇ´Â ¸Þ¼¼Áö Å¥¿¡ ´ëÇÑ ³»ºÎ ÀÚ·á ±¸Á¶ÀÇ º¹»çº»À» °®´Â´Ù.

Å¥ÀÇ ³»ºÎ ÀÚ·á ±¸Á¶Ã¼ÀÇ º¹»çº»À» °¡Áö°í ÀÖÀ» ¶§, ¾î¶² Ư¼ºÀ» Á¶Á¾ÇÒ ¼ö ÀÖ°í, ±×°ÍµéÀ» ¾î¶»°Ô º¯°æ½Ãų ¼ö Àִ°¡? ÀÚ·á ±¸Á¶ ¾È¿¡¼­ ¿ÀÁ÷ ¼öÁ¤ÇÒ ¼ö ÀÖ´Â ¾ÆÀÌÅÛÀº ipc_perm ¸â¹öÀÌ´Ù. ÀÌ°ÍÀº ÁÖÀÎ(owner)¿Í »ý¼ºÀÚ(creator)¿¡ ´ëÇÑ Á¤º¸´Â ¹°·Ð, Å¥ÀÇ Çã°¡»çÇ×µµ Æ÷ÇÔÇÑ´Ù. ±×·¸Áö¸¸ ¼öÁ¤µÉ ¼öÀÖ´Â ipc_perm ±¸Á¶Ã¼ÀÇ ¸â¹öµéÀº mode,uid,gid »ÓÀÌ´Ù. ÁÖÀÎ(owner)ÀÇ user id, ÁÖÀÎ(owner)ÀÇ group id, Å¥ÀÇ Á¢±Ù Çã°¡»çÇ×(access permission)À» ¹Ù²Ü ¼ö ÀÖ´Ù.

Å¥ÀÇ ¸ðµå(mode)¸¦ ¹Ù²Ùµµ·Ï °í¾ÈµÈ wrapper ÇÔ¼ö¸¦ ¸¸µé¾î º¸ÀÚ. ¸ðµå(mode)´Â ¹®ÀÚ ¹è¿­·Î ³Ñ°ÜÁ®¾ß ÇÑ´Ù (i.e. "660").


int change_queue_mode( int qid, char *mode )
{
        struct msqid_ds tmpbuf;

	/* ³»ºÎ ÀÚ·á ±¸Á¶ÀÇ ÇöÀç º¹»çº»À» Á¶È¸ÇÑ´Ù */
        get_queue_ds( qid, &tmpbuf);

	/* ¿¾³¯ÀÇ ±â±³¸¦ »ç¿ëÇÏ¿© Çã°¡»çÇ×(permission)À» ¼öÁ¤ÇÑ´Ù */
        sscanf(mode, "%ho", &tmpbuf.msg_perm.mode);

	/* ³»ºÎ ÀÚ·á ±¸Á¶¸¦ ¼öÁ¤ÇÑ´Ù */
        if( msgctl( qid, IPC_SET, &tmpbuf) == -1)
        {
                return(-1);
        }
        
        return(0);
}

get_queue_ds wrapper ÇÔ¼ö¸¦ °£´ÜÈ÷ È£ÃâÇÏ¿© ³»ºÎ ÀÚ·á ±¸Á¶ÀÇ ÇöÀç º¹»çº»À» Á¶È¸ÇÑ´Ù. ¿¬°üµÈ msg_perm ±¸Á¶ÀÇ mode ¸â¹ö¸¦ º¯°æÇϱâ À§ÇØ sscanf()¸¦ È£ÃâÇÑ´Ù. »õ º¹»çº»À» ³»ºÎ ¹öÀü¿¡ ¾÷µ¥ÀÌÆ®Çϱâ Àü¿¡´Â ¾Æ¹«·± º¯È­µµ ÀϾÁö ¾Ê´Â´Ù. ÀÌ·¯ÇÑ ÀÏÀº IPC_SET ¸í·É¾î¸¦ »ç¿ëÇÏ¿© msgctl()¸¦ È£ÃâÇÏ¿© ¼öÇàÇÒ ¼ö ÀÖ´Ù.

ÁÖÀÇ! Å¥ÀÇ Çã°¡»çÇ×À» º¯°æÇÒ ¼ö ÀÖ°í, ±×·¸°Ô Çؼ­ º»ÀÇ¾Æ´Ï°Ô ½º½º·Î¸¦ Â÷´Ü½Ãų ¼ö ÀÖ´Ù. ±â¾ïÇ϶ó, ÀÌ·¯ÇÑ IPC °´Ã¼µéÀº Àû´çÈ÷ Á¦°ÅÇϰųª ½Ã½ºÅÛÀ» ÀçºÎÆÃÇÏÁö ¾ÊÀ¸¸é ¾ø¾îÁöÁö ¾Ê´Â´Ù. µû¶ó¼­ ipcs¸¦ °¡Áö°í Å¥¸¦ º¼ ¼ö ¾ø´Ù°í ÇÏ¿© Á¸ÀçÇÏÁö ¾Ê´Â´Ù´Â °ÍÀ» ÀǹÌÇÏÁö´Â ¾Ê´Â´Ù.

ÀÌ Á¡À» ¼³¸íÇϱâ À§ÇØ, ´Ù¼Ò Àç¹ÌÀÖ´Â ÀÏÈ­¸¦ ¼Ò°³ÇÏ°Ú´Ù. South Florida ´ëÇп¡¼­ À¯´Ð½º ³»ºÎ¸¦ °¡¸£Ä¡´Â µ¿¾È, ³ª´Â ¾ÆÁÖ ´çȲ½º·´°í ¾î¸®µÕÀýÇÑ Â÷´Ü(Blocking)¿¡ Á÷¸éÇß´Ù. Áö³­¹ã¿¡ ³ª´Â ÀÏÁÖÀÏ°£ÀÇ ¼ö¾÷¿¡¼­ »ç¿ëµÈ ¿¬±¸¹Ú¾÷À» Å×½ºÆ®ÇÏ°í ÄÄÆÄÀÏÇϱâ À§ÇØ ¿¬±¸½Ç ¼­¹ö¿¡ Á¢¼ÓÇß´Ù. Å×½ºÆ®¸¦ ÇÏ´Â µ¿¾È¿¡ ³ª´Â ÄÚµå¾È¿¡ ¸Þ¼¼Áö Å¥ÀÇ Çã°¡»çÇ×(permission)À» º¯°æÇϴ ŸÀÔÀ» ¸¸µé¾ú´Ù´Â »ç½ÇÀ» ±ú´Þ¾Ò´Ù. ³ª´Â °£´ÜÇÑ ¸Þ¼¼Áö Å¥¸¦ ¸¸µé¾ú°í, ¾Æ¹«·± »ç°í¾øÀÌ ÁÖ°í ¹ÞÀ» ¼ö ÀÖ´ÂÁö¸¦ Å×½ºÆ® Çß´Ù. ±×·¸Áö¸¸, ³»°¡ Å¥ÀÇ ¸ðµå¸¦ "660"¿¡»ç "600"À¸·Î ¼öÁ¤ÇÏ·Á°í ÇßÀ» ¶§, ³» ÀÚ½ÅÀÇ Å¥·Î ºÎÅÍ ³ª ÀÚ½ÅÀ» ¸·¾Æ¹ö¸®´Â °á°ú¸¦ ÃÊ·¡Çß´Ù. °á°úÀûÀ¸·Î ³ª´Â ³» ¼Ò½º µð·ºÅ丮ÀÇ °°Àº ¿µ¿ª¿¡¼­ ¸Þ¼¼Áö Å¥ ¿¬±¸ÀÛ¾÷À» Å×½ºÆ® ÇÒ ¼ö ¾ø¾ú´Ù. ³»°¡ IPC Å°¸¦ ¸¸µé±â À§ÇØ ftok() ÇÔ¼ö¸¦ »ç¿ëÇ߱⿡, ³»°¡ Å¥¿¡ Á¢±ÙÇÏ·Á°í ÇÒ ¶§ ³ª´Â Àû´çÇÑ Çã°¡»çÇ×(permission)À» °®°í ÀÖÁö ¸øÇß´Ù. ¼ö¾÷ÀÌ ÀÖ´Â ¾Æħ¿¡ °á±¹ ³ª´Â Áö¿ª ½Ã½ºÅÛ °ü¸®ÀÚ¿¡°Ô ¸Þ¼¼Áö Å¥°¡ ¹«¾ùÀÎÁö¿Í ¿Ö ±×°¡ ³ª¸¦ À§ÇØ ipcrm ¸í·É¾î¸¦ ¼öÇà½ÃÄÑ¾ß ÇÏ´ÂÁö¸¦ Çѽ𣵿¾È ¼³¸íÇÏ°í Á¢¼ÓÀ» ³¡³Â´Ù.
Å¥·ÎºÎÅÍ ¼º°øÀûÀ¸·Î ¸Þ¼¼Áö¸¦ ¹ÞÀº ÈÄ, ¸Þ¼¼Áö´Â Á¦°ÅµÈ´Ù. ¾Õ¿¡¼­µµ ¾ð±ÞÇß´ø °Íó·³, IPC °´Ã¼´Â ¸í¹éÈ÷ Á¦°ÅµÇ°Å³ª ½Ã½ºÅÛÀ» ÀçºÎÆÃÇÏÁö ¾Ê´Â ÇÑ ½Ã½ºÅÛ¿¡ ³²¾Æ Àִ´Ù. ±×·¯¹Ç·Î, ¿ì¸®ÀÇ ¸Þ¼¼Áö Å¥´Â ¿©ÀüÈ÷ Ä¿³Î¾È¿¡ Á¸ÀçÇÏ°í ´ÜÀÏ ¸Þ¼¼Áö°¡ »ç¶óÁø ÈÄ¿¡µµ °è¼Ó »ç¿ëÇÒ ¼ö ÀÖ´Ù. ¸Þ¼¼Áö Å¥ÀÇ »ý¸í ÁÖ±â(life cycle)¸¦ ¿Ï¼ºÇϱâ À§ÇØ IPC_RMID ¸í·É¾î¸¦ »ç¿ëÇÏ¿© msgctl()¸¦ È£Ãâ¿¡ ÀÇÇØ Á¦°ÅµÇ¾î¾ß ÇÑ´Ù.:


int remove_queue( int qid )
{
        if( msgctl( qid, IPC_RMID, 0) == -1)
        {
                return(-1);
        }
        
        return(0);
}

ÀÌ wrapper ÇÔ¼ö´Â Å¥°¡ »ç°í¾øÀÌ Á¦°ÅµÇ¸é 0À» ¹ÝȯÇÏ°í ¾Æ´Ï¸é -1À» ¹ÝȯÇÑ´Ù. Å¥ÀÇ Á¦°Å´Â ÀÚ¿¬ÀûÀ¸·Î atomicÇÏ°í ¾î¶² ¸ñÀû¿¡¼­°Ç Å¥¿¡ ´ëÇÑ ¾î¶² ÀÏ·ÃÀÇ Á¢±Ùµµ ÇüÆí¾øÀÌ ½ÇÆÐÇÒ °ÍÀÌ´Ù.


ÀÌÀü:½Ã½ºÅÛ È£Ãâ:msgsnd() ´ÙÀ½:msgtool:»óÈ£ÀÛ¿ë ¸Þ¼¼Áö Å¥ Á¶Á¾ÀÚ

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

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