¸Þ¼¼Áö Å¥ÀÇ ÅëÁ¦ µ¿ÀÛÀ» ¼öÇàÇϱâ À§ÇØ, 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:
int get_queue_ds( int qid, struct msgqid_ds *qbuf ) { if( msgctl( qid, IPC_STAT, qbuf) == -1) { return(-1); } return(0); }
Å¥ÀÇ ³»ºÎ ÀÚ·á ±¸Á¶Ã¼ÀÇ º¹»çº»À» °¡Áö°í ÀÖÀ» ¶§, ¾î¶² Ư¼ºÀ» Á¶Á¾ÇÒ ¼ö ÀÖ°í, ±×°ÍµéÀ» ¾î¶»°Ô º¯°æ½Ãų ¼ö Àִ°¡? ÀÚ·á ±¸Á¶ ¾È¿¡¼ ¿ÀÁ÷ ¼öÁ¤ÇÒ ¼ö ÀÖ´Â ¾ÆÀÌÅÛÀº 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); }
ÁÖÀÇ! Å¥ÀÇ Çã°¡»çÇ×À» º¯°æÇÒ ¼ö ÀÖ°í, ±×·¸°Ô Çؼ º»ÀÇ¾Æ´Ï°Ô ½º½º·Î¸¦ Â÷´Ü½Ãų ¼ö ÀÖ´Ù. ±â¾ïÇ϶ó, ÀÌ·¯ÇÑ 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); }
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