-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path026.c
More file actions
40 lines (33 loc) · 1.33 KB
/
026.c
File metadata and controls
40 lines (33 loc) · 1.33 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
/*
..........................................................................................................................................
Name : 026.c
Author : SHRUTI VERMA
Description : Write a program to send messages to the message queue. Check $ipcs -q
Date : 18 Sep 2025
..........................................................................................................................................
*/
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/msg.h>
#include<sys/ipc.h>
int main() {
int key, msgid;
key = ftok("file.txt", 'a');
msgid = msgget(key, IPC_CREAT|0744);
msgsnd(msgid, "hello there", sizeof("hello there"), 0);
printf("message sent\n");
char buf[100];
msgrcv(msgid, buf, sizeof(buf), 0, 0);
printf("message received : %s\n", buf);
}
/*----------------------------------OUTPUT---------------------------------------
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ gcc 026.c -o 026.out
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ./026.out
message sent
message received : hello there
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
0x61056ed5 2 vumma 744 12 1
*/