Question: Q.1 : Write a program ( c or c++ ) in which we can implement the concept of Interprocess Communicaton ( IPC ) in between

Q.1 : Write a program ( c or c++ ) in which we can implement the concept of Interprocess Communicaton ( IPC ) in between two departments of cafeteria management system i.e. Receptionist ( who takes the order from customer ) and Food Making Team ( Who makes the order and parcel the meal ).

You have to implement the Interprocess Communication between Receptionist and Food making Team.

Receptionist act as Writer ( Who sends the customer order to Food Making Team )

Food Making Team act as Reader ( Who Recieves the Order Details from Receptionist and make Food Parcels )

For Help/clue:-

The Code for IPC (Writer and Reader) is as follows :-

MESSAGE QUEUE FOR WRITER PROCESS

// C Program for Message Queue (Writer Process)

#include

#include

#include

// structure for message queue

struct mesg_buffer {

long mesg_type;

char mesg_text[100];

} message;

int main()

{

key_t key;

int msgid;

// ftok to generate unique key

key = ftok("progfile", 65);

// msgget creates a message queue

// and returns identifier

msgid = msgget(key, 0666 | IPC_CREAT);

message.mesg_type = 1;

printf("Write Data : ");

gets(message.mesg_text);

// msgsnd to send message

msgsnd(msgid, &message, sizeof(message), 0);

// display the message

printf("Data send is : %s ", message.mesg_text);

return 0;

}

MESSAGE QUEUE FOR READER PROCESS

// C Program for Message Queue (Reader Process)

#include

#include

#include

// structure for message queue

struct mesg_buffer {

long mesg_type;

char mesg_text[100];

} message;

int main()

{

key_t key;

int msgid;

// ftok to generate unique key

key = ftok("progfile", 65);

// msgget creates a message queue

// and returns identifier

msgid = msgget(key, 0666 | IPC_CREAT);

// msgrcv to receive message

msgrcv(msgid, &message, sizeof(message), 1, 0);

// display the message

printf("Data Received is : %s ", message.mesg_text);

// to destroy the message queue

msgctl(msgid, IPC_RMID, NULL);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!