blob: 6c5a5f0214656ce0b278a0d3173fe4857edb4e06 [file] [log] [blame]
lh758261d2023-07-13 05:52:04 -07001#include <stdio.h>
2#include <stdlib.h>
3#include <sys/ipc.h>
4#include <sys/msg.h>
5// structure for message queue
6struct msg_buffer {
7 long msg_type;
8 char msg[100];
9} message;
10main(int argc,char *argv[]) {
11 key_t my_key;
12 int msg_id;
13 int ret;
14 my_key = atoi(argv[1]); //create unique key
15 msg_id = msgget(my_key, 0666 | IPC_CREAT); //create message queue and return id
16 printf("Message id: %d\n", msg_id);
17 message.msg_type = 1;
18 printf("Write Message : ");
19 fgets(message.msg, 100, stdin);
20 ret = msgsnd(msg_id, &message, sizeof(message), 0); //send message
21 printf("Sent message ret is %d message is : %s \n", ret, message.msg);
22}