Lab Exercise Assignment on Operating Systems | CECS 326, Assignments of Operating Systems

Material Type: Assignment; Class: Operating Systems; Subject: Computer Engr & Computer Sci; University: California State University - Long Beach; Term: Fall 2005;

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-5rm
koofers-user-5rm 🇺🇸

4

(1)

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CECS 326 – Lab Exercise 10/18/05 (20 points) – Due 10/27/05
When there are concurrent processes trying to send output to the same monitor, their outputs are likely to be mixed up in
an unpredictable manner, rendering the output to be unreadable. In this lab exercise we will learn to use semaphore, a
mechanism available on Linux, to provide control of the access to shared resources (such as the monitor) by concurrent
processes. To help you learn about this mechanism, two sample program named semaphore.cpp and semdemo1.cpp are
provided for your reference. To understand this mechanism please reference manual pages for semget, semctl, and
semop.
Do the following for this assignment:
1. Create a subdirectory named ex-10-18-05 within your htdocs/cecs326 subdirectory. Set its permission to world
readable and world executable.
2. Copy the sample C++ programs mixedup_p.cpp, mixedup_c.cpp, semaphore.cpp and semdemo1.cpp from
~lam/htdocs/cecs326/samples into this subdirectory. Compile the programs semaphore.cpp and semdemo1.cpp into
semaphore and semdemo1 respectively, execute them and try to understand what the code in each program does.
When executing semdemo1, run one foreground and one background process of the same program. Then add a prolog
comment section and other comments throughout the programs as needed in these programs to explain what each of
the programs does.
3. Modifiy the two programs mixedup_p.cpp and mixedup_c.cpp to add the control using the semaphore mechanism so
that output from the loop in each of the three processes will appear on one line (i.e., no interleaving of output
generated in the loops in the three processes.)
4. Hand in a hardcopy of the revised mixedup_p.cpp and mixedup_c.cpp, the annotated semaphore.cpp and
semdemo1.cpp, and printouts of two different runs of the mixedup_p program.

Partial preview of the text

Download Lab Exercise Assignment on Operating Systems | CECS 326 and more Assignments Operating Systems in PDF only on Docsity!

CECS 326 – Lab Exercise 10/18/05 (20 points) – Due 10/27/

When there are concurrent processes trying to send output to the same monitor, their outputs are likely to be mixed up in an unpredictable manner, rendering the output to be unreadable. In this lab exercise we will learn to use semaphore, a mechanism available on Linux, to provide control of the access to shared resources (such as the monitor) by concurrent processes. To help you learn about this mechanism, two sample program named semaphore.cpp and semdemo1.cpp are provided for your reference. To understand this mechanism please reference manual pages for semget, semctl, and semop. Do the following for this assignment:

  1. Create a subdirectory named ex-10-18-05 within your htdocs/cecs326 subdirectory. Set its permission to world readable and world executable.
  2. Copy the sample C++ programs mixedup_p.cpp , mixedup_c.cpp, semaphore.cpp and semdemo1.cpp from ~lam/htdocs/cecs326/samples into this subdirectory. Compile the programs semaphore.cpp and semdemo1.cpp into semaphore and semdemo1 respectively, e xecute them and try to understand what the code in each program does. When executing semdemo1 , run one foreground and one background process of the same program. Then add a prolog comment section and other comments throughout the programs as needed in these programs to explain what each of the programs does.
  3. Modifiy the two programs mixedup_p.cpp and mixedup_c.cpp to add the control using the semaphore mechanism so that output from the loop in each of the three processes will appear on one line (i.e., no interleaving of output generated in the loops in the three processes.)
  4. Hand in a hardcopy of the revised mixedup_p.cpp and mixedup_c.cpp , the annotated semaphore.cpp and semdemo1.cpp , and printouts of two different runs of the mixedup_p program.