Docsity

CECS 326 Lab Exercise: Interprocess Communication using Message Queues, Lab Reports of Operating Systems

Toggle sidebar
bg1
CECS 326 – Lab Exercise 9/22/05 (20 points) – Due 9/29/05
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:
1. Create a subdirectory named ex-9-22-05 within your htdocs/cecs326 subdirectory. Set its permission to world
readable and world executable.
2. Copy two sample C++ programs named use_msgQ.cpp and use_msgQ_w_ftok.cpp from
~lam/htdocs/cecs326/samples into this subdirectory. Compile these programs and execute them and try to
understand what they do. Then add a prolog comment section and other comments throughout the program as
needed in these two programs to explain what each program does.
3. Develop three C++ programs (master.cpp, sender.cpp, and receiver.cpp) as described above. Make sure your
programs are adequately documented.
4. Hand in a hardcopy of the annotated use_msgQ.cpp and using_msgQ_w_ftok.cpp and your three C++ programs
master.cpp, sender.cpp, and receiver.cpp, and demo the execution of your master program.

Partial preview of the text

Download CECS 326 Lab Exercise: Interprocess Communication using Message Queues and more Lab Reports Operating Systems in PDF only on Docsity!

CECS 326 – Lab Exercise 9/22/05 (20 points) – Due 9/29/

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:

  1. Create a subdirectory named ex-9-22-05 within your htdocs/cecs326 subdirectory. Set its permission to world readable and world executable.
  2. Copy two sample C++ programs named use_msgQ.cpp and use_msgQ_w_ftok.cpp from ~lam/htdocs/cecs326/samples into this subdirectory. Compile these programs and execute them and try to understand what they do. Then add a prolog comment section and other comments throughout the program as needed in these two programs to explain what each program does.
  3. Develop three C++ programs (master.cpp, sender.cpp, and receiver.cpp) as described above. Make sure your programs are adequately documented.
  4. Hand in a hardcopy of the annotated use_msgQ.cpp and using_msgQ_w_ftok.cpp and your three C++ programs master.cpp , sender.cpp , and receiver.cpp , and demo the execution of your master program.