-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path029.c
More file actions
49 lines (40 loc) · 1.54 KB
/
029.c
File metadata and controls
49 lines (40 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
..........................................................................................................................................
Name : 029.c
Author : SHRUTI VERMA
Description : Write a program to remove the message queue.
Date : 18 Sep 2025
..........................................................................................................................................
*/
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/msg.h>
#include<sys/ipc.h>
#include<sys/wait.h>
int main() {
struct msqid_ds msg;
int key, msgid;
key = ftok("file.txt", 'a');
msgid = msgget(key, IPC_CREAT|0744);
msgctl(msgid, IPC_STAT, &msg);
printf("Message queue id : %d\n", msgid);
sleep(10);
printf("Removing message queue with id : %d\n", msgid);
msgctl(msgid, IPC_RMID, &msg);
}
/*----------------------------------OUTPUT---------------------------------------
terminal 1
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ gcc 029.c -o 029.out
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ./029.out
Message queue id : 4
Removing message queue with id : 4
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ipcs -q
terminal 2
------ Message Queues --------
key msqid owner perms used-bytes messages
0x61056ed5 4 vumma 744 0 0
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
*/