Write a C program that receives the messages(From the above message queue as specified in (21)) and display them.
AIM:
Write a C program that receives the messages(From the above message queue as specified in (21) and display them.
Program:
#include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <stdio.h> #define MSGSZ 128 /* * Declare the message structure. */ typedef struct msgbuf { long mtype; char mtext[MSGSZ]; } message_buf; main() { int msqid; key_t key; message_buf rbuf; /* * Get the message queue id for the * "name" 1234, which was created by * the server. */ key = 1234; if ((msqid = msgget(key, 0666)) < 0) { perror("msgget"); exit(1); } /* * Receive an answer of message type 1. */ if (msgrcv(msqid, &rbuf, MSGSZ, 1, 0) < 0) { perror("msgrcv"); exit(1); } /* * Print the answer. */ printf("%s\n", rbuf.mtext); exit(0); } Execution Steps: [student@gcet ~]$cc message_send.c [student@gcet ~]$ mv a.out msgsend [student@gcet ~]$ ./msgsend msgget: Calling msgget(0x4d2,01666) msgget: msgget succeeded: msqid = 0 msgget: msgget succeeded: msqid = 0 msgget: msgget succeeded: msqid = 0 Message: "Did you get this?" Sent [student@gcet ~]$ cc message_rec.c [student@gcet ~]$ mv a.out msgrec [student@gcet ~]$./msgrec
Output:
[1] 2907 [student@gcet ~]$ Did you get this?
-
UpdatedApr 28, 2017
-
Views7,432
Write a Shell script to find factorial of a given integer.
Write in C the following Unix commands using system calls A). cat B). ls C). mv
Write a Shell script that displays list of all the files in the current directory to which the user has read, Write and execute permissions.
Write a Shell script that accepts a filename, starting and ending line numbers as arguments and displays all the lines between the given line numbers.
Write a C program to emulate the Unix ls-l command.
Write a Shell script to list all of the directory files in a directory.