Presentation is loading. Please wait.

Presentation is loading. Please wait.

메시지 큐[5] – test1.c 메시지 제어: msgctl(2) #include <sys/msg.h>

Similar presentations


Presentation on theme: "메시지 큐[5] – test1.c 메시지 제어: msgctl(2) #include <sys/msg.h>"— Presentation transcript:

1 메시지 큐[5] – test1.c 메시지 제어: msgctl(2) #include <sys/msg.h>
msqid : 메시지 큐 식별자 cmd : 수행할 제어기능 buf : 제어 기능에 사용되는 메시지 큐 구조체 주소 cmd에 지정할 값 IPC_RMID : 메시지 큐 제거 IPC_SET : 메시지 큐 정보 중 msg_perm.uid, msg_perm.gid, msg_perm.mode, msg_qbytes 값을 세번째 인자로 지정한 값으로 변경 IPC_STAT : 현재 메시지 큐의 정보를 buf에 저장 #include <sys/msg.h> int msgctl(int msqid, int cmd, struct msqid_ds *buf);

2 [예제 10-3] 메시지 큐 삭제하기 (test2.c)
... 05 int main(void) { key_t key; int msgid; 08 key = ftok("keyfile", 1); msgid = msgget(key, IPC_CREAT|0644); if (msgid == -1) { perror("msgget"); exit(1); } 15 printf("Before IPC_RMID\n"); system("ipcs -q"); msgctl(msgid, IPC_RMID, (struct msqid_ds *)NULL); printf("After IPC_RMID\n"); system("ipcs -q"); 21 return 0; 23 } 키값 생성 메시지 큐 삭제

3 [예제 10-3] 실행결과 # ex10_3.out Before IPC_RMID
IPC status from <running system> as of 2009년 2월 18일 수요일 오후 2시 21분 47초 T ID KEY MODE OWNER GROUP Message Queues: q x100719c --rw-r--r root other After IPC_RMID

4 Pipe 함수를 사용해 부모 프로세스와 자식 프로세스 간에 대회가 가능한 양방향 통신이 되도록 프로그램을 작성하라
실습 Pipe 함수를 사용해 부모 프로세스와 자식 프로세스 간에 대회가 가능한 양방향 통신이 되도록 프로그램을 작성하라 FIFO를 사용해 클라이언트 프로세스가 파일의 내용을 보내주면 서버 프 로세스는 해당 내용을 화면으로 출력하고 파일로도 저장해주는 프로그램 을 작성하라. 클라이언트 프로세스는 명령행 인자로 파일명을 받는다. FIFO를 사용해 1:1 대화가 가능한 양방향 프로그램을 작성하라. 대화의 시작은 서버와 클라이언트 중 한쪽에서 먼저 시작하도록 한다. 메시지 유형을 1, 3, 3으로 지정해 보내고 3변 유형의 첫 번째 메시지를 수신하는 프로그램을 작성한다. 각 메시지는 다음과 같이 한다. 1번 메시지: Hanbit Message 1 2번 메시지: Hanbit Message 3-1 3번 메시지: Hanbit Message 3-2


Download ppt "메시지 큐[5] – test1.c 메시지 제어: msgctl(2) #include <sys/msg.h>"

Similar presentations


Ads by Google