Computer Science 330
Operating Systems
Fall 2020, Siena College
Lab 4: System V Shared Memory
Due: 11:59 PM, Monday, September 14, 2020
In this lab, you will see how to use System V shared memory
with Unix processes.
You may work alone or with a partner or two on this lab.
Learning goals:
- To learn about System V shared memory
- To use System V shared memory to implement communication between
Unix processes
- To gain experience using pointers
Getting Set Up
You will receive an email with the
link to follow to set up your GitHub repository, which will be named
shmem-lab-yourgitname, for this lab. Only one member of the
group should follow the link to set up the repository on GitHub,
then others should request a link to be granted write access.
Using Class Examples
Question 1: Using the virtualized Linux system that you can run under
OpenNebula, compile and run the forkbomb program. How many
processes can you create before you either get an error message (or
the system crashes)? (2 points)
Question 2: Draw a memory diagram showing all of the variables in
existence in the pthreadhello example when both child threads
are executing. (10 points)
fork() Practice
The Syracuse Sequence starting at a given positive integer n
is defined by repeated application of the function
f(n) = n/2 if n is even, 3n+1 if n is odd.
The sequence ends when the value reaches 1. It is not known if all
values of n eventually lead to 1, but no one has found a value for
which it doesn't or proven that one must exist.
Practice Program: Write a program forksyr.c that computes and
prints the Syracuse sequence within a child process created by
fork. Include a Makefile that compiles this program into
an executable called forksyr. (10 points)
Notes:
- Do some error checking. If your program is run without a
command-line argument, print a "Usage" line. If your program is
given a negative starting value for the sequence, print an
appropriate error message.
- If you store the values in the sequence with int values,
you will notice they could overflow the storage capabilities of the
data type. You can delay this somewhat by using long values.
Even then, you could overflow the values with certain starting values.
In this case, also print an error message.
Adding Shared Memory
Practice Program: Now, create a second version of your program that
uses System V shared memory. The child process will be responsible for
computing the entire sequence, but the parent process will be
responsible for printing it. Call your program
forksyrshared.c and include a Makefile that compiles
this program into forksyrshared. (25 points)
Once your program is working, add a call to sleep(2) (recall that
"2" here refers to the manual section, not the argument to pass) to
your program before you detach and free the shared memory segment. In
a separate window, use the ipcs command to see that your shared
memory segment is listed, and that it goes away when your program
terminates. Save this output and include it in a file ipcs.out
to be included in your submission.
Output Capture: ipcs.out for 3 point(s)
Submission
Commit and push!
Grading
This assignment will be graded out of 50 points.
Feature | Value | Score |
Question 1, forkbomb | 2 | |
Question 2, memory diagram | 10 | |
forksyr.c | 10 | |
forksyrshared.c | 25 | |
ipcs.out | 3 | |
Total | 50 | |
|