Áö±Ý±îÁö, ¾ð±ÞµÈ À¯¿ëÇÑ ¿¹Á¦µéÀº ¸Þ¼¼Áö Å¥¸¦ Á¶Á¾ÇÏ´Â wrapper ÇÔ¼öµéÀÌ¿´´Ù. ±×°ÍµéÀº ¸Å¿ì À¯¿ëÇÏÁö¸¸, ¾î¶² Àǹ̿¡¼´Â º¸´Ù ´õ ±íÀº °øºÎ¿Í ½ÇÇèÀ» º¸ÀåÇÏÁö´Â ¸øÇÏ°í ÀÖ´Ù. ÀÌ·± Á¡À» °³¼±Çϱâ À§ÇØ, IPC ¸Þ¼¼Áö Å¥¸¦ Á¶Á¾Çϱâ À§ÇÑ msgtool, »óÈ£ÀÛ¿ë ¸í·É¾î ¶óÀÎ À¯Æ¿¸®Æ¼(interative command line utility)¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù. ÀÌ°ÍÀº È®½ÇÈ÷ ±³À° °È¸¦ À§ÇÑ Àû´çÇÑ µµ±¸·Î¼ÀÇ ±â´ÉÀ» ÇÏÁö¸¸, Ç¥ÁØ ½© ½ºÅ©¸³Æ®¸¦ °æÀ¯ÇÏ¿© ¸Þ¼¼Áö Å¥ ±â´ÉÀ» Á¦°øÇÏ´Â °Í¿¡ ÀÇÇØ ½Ç ¼¼°èÀÇ °úÁ¦¿¡ Á÷Á¢ Àû¿ëÇÒ ¼ö´Â ¾ø´Ù.
msgtool s (type) "text"
¸Þ¼¼Áö Á¶È¸Çϱâ (Retrieving Messages)
msgtool r (type)
Çã°¡»çÇ× ¹Ù²Ù±â (Changing the Permissions(mode))
msgtool m (mode)
msgtool d
msgtool s 1 test msgtool s 5 test msgtool s 1 "This is a test" msgtool r 1 msgtool d msgtool m 660
ÇÑÆíÀ¸·Î, ÀÌ À¯Æ¿¸®Æ¼´Â ¾î¶² µ¿ÀÛÀÌ ¿äûµÇµçÁö¿¡ »ó°ü¾øÀÌ ¸Þ¼¼Áö Å¥°¡ Á¸ÀçÇÏÁö ¾ÊÀ¸¸é ¸Þ¼¼Áö Å¥¸¦ ¸¸µé °ÍÀÌ´Ù.
NOTE:ÀÌ ÅøÀº IPC Å° °ªÀ» ¹ß»ý½ÃÅ°±âÀ§ÇØ ftok()ÇÔ¼ö¸¦ »ç¿ëÇÔÀ¸·Î, µð·ºÅ丮 Ãæµ¹À» ¸¸³¯Áö ¸ð¸¥´Ù. ½ºÅ©¸³Æ® ³»ÀÇ ¾î´À ÇÑÁöÁ¡¿¡¼ µð·ºÅ丮¸¦ ¹Ù²Û´Ù¸é, ¾Æ¸¶µµ µ¿ÀÛÇÏÁö ¾ÊÀ» °ÍÀÌ´Ù. ¶Ç ´Ù¸¥ ÇØ°áÃ¥Àº msgtool¾È¿¡ "/tmp/msgtool/"°ú °°ÀÌ º¸´Ù Àý´ëÀûÀÎ °æ·Î(path)¸¦ ÇϵåÄÚµùÇϰųª Á¶ÀÛ»ó(operational)ÀÇ ¾Æ±Ô¸ÕÆ®¿¡ µû¶ó, ¸í·É¾î ¶óÀλ󿡼 ³Ñ°ÜÁø °æ·Î(path)¸¦ »ç¿ëÅä·Ï Çã¶ôÇÏ´Â °ÍÀÌ´Ù.
/***************************************************************************** ¸®´ª½º ÇÁ·Î±×·¡¸Ó¸¦ À§ÇÑ °¡À̵å - 6Àå ¿¡¼ ¹ßÃé (C)opyright 1994-1995, Scott Burkett ***************************************************************************** MODULE: msgtool.c ***************************************************************************** ½Ã½ºÅÛ V ½ºÅ¸ÀÏÀÇ ¸Þ¼¼Áö Å¥¸¦ »ç¿ëÇϱâ À§ÇÑ ¸í·É¾î ¶óÀÎ Åø *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #define MAX_SEND_SIZE 80 struct mymsgbuf { long mtype; char mtext[MAX_SEND_SIZE]; }; void send_message(int qid, struct mymsgbuf *qbuf, long type, char *text); void read_message(int qid, struct mymsgbuf *qbuf, long type); void remove_queue(int qid); void change_queue_mode(int qid, char *mode); void usage(void); int main(int argc, char *argv[]) { key_t key; int msgqueue_id; struct mymsgbuf qbuf; if(argc == 1) usage(); /* ftok() È£ÃâÀ» ÅëÇØ À¯ÀÏÇÑ Å°¸¦ ¸¸µç´Ù */ key = ftok(".", 'm'); /* ÇÊ¿äÇÏ´Ù¸é Å¥¸¦ ¸¸µé°í ¿¬´Ù */ if((msgqueue_id = msgget(key, IPC_CREAT|0660)) == -1) { perror("msgget"); exit(1); } switch(tolower(argv[1][0])) { case 's': send_message(msgqueue_id, (struct mymsgbuf *)&qbuf, atol(argv[2]), argv[3]); break; case 'r': read_message(msgqueue_id, &qbuf, atol(argv[2])); break; case 'd': remove_queue(msgqueue_id); break; case 'm': change_queue_mode(msgqueue_id, argv[2]); break; default: usage(); } return(0); } void send_message(int qid, struct mymsgbuf *qbuf, long type, char *text) { /* Å¥¿¡ ¸Þ¼¼Áö¸¦ º¸³½´Ù */ printf("Sending a message ...\n"); qbuf->mtype = type; strcpy(qbuf->mtext, text); if((msgsnd(qid, (struct msgbuf *)qbuf, strlen(qbuf->mtext)+1, 0)) ==-1) { perror("msgsnd"); exit(1); } } void read_message(int qid, struct mymsgbuf *qbuf, long type) { /* Å¥·Î ºÎÅÍ ¸Þ¼¼Áö¸¦ Àд´Ù. */ printf("Reading a message ...\n"); qbuf->mtype = type; msgrcv(qid, (struct msgbuf *)qbuf, MAX_SEND_SIZE, type, 0); printf("Type: %ld Text: %s\n", qbuf->mtype, qbuf->mtext); } void remove_queue(int qid) { /* Å¥¸¦ Áö¿î´Ù */ msgctl(qid, IPC_RMID, 0); } void change_queue_mode(int qid, char *mode) { struct msqid_ds myqueue_ds; /* ÇöÀç Á¤º¸¸¦ Àд´٠*/ msgctl(qid, IPC_STAT, &myqueue_ds); /* ¸ðµå¸¦ Àоî¿Í ¹Ù²Û´Ù */ sscanf(mode, "%ho", &myqueue_ds.msg_perm.mode); /* ¸ðµå¸¦ ¼öÁ¤ÇÑ´Ù */ msgctl(qid, IPC_SET, &myqueue_ds); } void usage(void) { fprintf(stderr, "msgtool - A utility for tinkering with msg queues\n"); fprintf(stderr, "\nUSAGE: msgtool (s)end\n"); fprintf(stderr, " (r)ecv \n"); fprintf(stderr, " (d)elete\n"); fprintf(stderr, " (m)ode \n"); exit(1); }
Copyright (c) 1996,1997 by Euibeom.Hwang & SangEun.Oh All Rights Reserved
Email To:Webmaster ,
Another address
LAST UPDATE Nov 21,1997
Created Nov 21,1997