Starting from:
$35

$29

Homework #6 Solution

PART 1:

‐‐‐‐‐‐‐

Create a set of 4 stand‐alone programs, as follows:




Program #0 ‐ Will always be called first and must create a set of semaphores. Program #0 must print the exact text "Executing process #0." when it runs. It must then terminate.




Program #1 ‐ Will be started sometime after program #0 and must adjust the semaphore(s) such that program #2 can run. Program #1 must print the exact text "Executing process #1." when it runs. It must then terminate. Program #1 doesn't do anything else.




Program #2 ‐ Will be started sometime after program #0 and must adjust the semaphore(s) such that program #3 can run. Program #2 must print the exact text "Executing process #2." when it runs.




It must then terminate. Program #2 doesn't do anything else. However, program #2 can only run AFTER program #1 runs! If program #2 runs before program #1 it must simply terminate itself.




Program #3 ‐ Will be started sometime after program #0 and should remove the semaphores from the system. Program #3 must print the exact text "Executing process #3." when it runs. It must then terminate. Program #3 doesn't do anything else. However, program #3 can only run AFTER program #2 runs! If program #3 runs before program #2 it must simply terminate itself.




PART 2:

‐‐‐‐‐‐‐

We will test your code using my program (a script) that will always call program #0 first, but will call the remaining programs in all possible permutations. Obviously, to get full credit only the correct permutation should result in the following output:




Executing process #0.

Executing process #1.

Executing process #2.

Executing process #3.




SUGGESTIONS:

‐‐‐‐‐‐‐‐‐‐‐‐

See man pages for semget, semop, and semctl.




See man pages for errno and include errno.h ‐ this will make things much easier! You can use errno to troubleshoot your code and to help determine how to tell when a process is attempted out‐of‐turn.




See my web site for a new file (errno.txt).







REQUIREMENTS:

‐‐‐‐‐‐‐‐‐‐‐‐

 
Your program must run in Streibel 109.




 
Your full name must appear as a comment at the beginning of your program.




 
Your source code must be named hw6‐yourname.c or hw6‐yourname.cpp




 
Email your source (subject hw6‐yourname) to rmarsh@cs.und.edu



More products