
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

Cooperating processes often need to communicate between them. One mechanism Linux provides for interprocess communication is message queues. A message queue must first be aquired from the operating system by calling msgget. Control operations, e.g., remove, can be performed on an existing message queue by calling msgctl. Processes with appropriate permissions may send and/or receive messages via the message queue by calling msgsnd and msgrcv. A very useful function named ftok() can be used to convert a file name into a key for msgget call. Please consult the man pages of these system calls for details. For this exercise you need to write three C++ programs named master.cpp , sender.cpp , and receiver.cpp , which should be compiled into master , sender , and receiver , respectively. Together they should do the following: The master program should first acquire a message queue from the operating system, followed by creating two child processes, with one to execute sender , and the other to execute receiver. It then waits for both child processes to return. The message queue should be created using a filename that user enters in the command and the 1st^ letter in the name as follows: Linux> master prog1 # assume a file named prog1 exists in the current directory With the above command, master should create a message queue by calling msgget(“prog1”,’p’), IPC_EXCL|IPC_CREAT|0600); The sender program should prompt user for a line of input, then send the input line to receiver via the message queue created by the parent process. Make sure that the prompt identifies that sender is the process making the prompt. The receiver program retrieves a message from the message queue, and outputs the line on the screen. Make sure the output identifies that the line is printed by receiver. Upon termination of both child processes, master then outputs a line indicating its termination, and then exits. Do the following for this assignment: