Computer Science 330
Operating Systems
Spring 2012, Siena College
You may work individually or with a partner on this lab assignment.
Running Class Examples
Run the class examples that used fork and POSIX threads in the following three environments to answer the questions that follow in a file answers.txt.
A sample output of the what_shared program on the Mac as we saw in class is:
First, we create two threads to see better what context they share... Set this_is_global=1000 Thread 1, pid 67582, addresses: &global: 10A8, &local: B5EFC In Thread 1, incremented this_is_global=1001 Thread 2, pid 67582, addresses: &global: 10A8, &local: 280EFC In Thread 2, incremented this_is_global=1002 After threads, this_is_global=1002 Now that the threads are done, let's call fork.. Before fork(), local_main=17, this_is_global=17 In parent, pid 67582: &global: 10A8, &local: 5FBFEF5C In child, pid 67583: &global: 10A8, &local: 5FBFEF5C Child set local_main=13, this_is_global=23 In parent, local_main=17, this_is_global=17
On the Mac, we saw in class that the proctree_threads program could create a thread tree of height 10 without encountering any thread creation errors, but did encounter errors at height 11.
fork() Practice
Write the program for SG&G Programming Problem 3.14 on p. 134-135. Call your program forkfib.c. Include a Makefile that compiles this program into an executable called forkfib.
Notes:
Adding POSIX Shared Memory
Read Section 3.5.1 of SG&G to learn about POSIX shared memory. Then write the program for Exercise 3.18 on p. 137-138 of SG&G. Call your program forkfibshared.c and include a Makefile that compiles this program into forkfibshared.
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.
Now Using POSIX Threads
Write the program for Exercise 4.17 on p. 168-169 of SG&G. Call your program pthreadfib.c and include a Makefile that compiles this program into pthreadfib.
Submission and Evaluation
This lab is graded out of 40 points.
To submit this lab, place all of the files that you are to turn in (and nothing else) into a directory, change to that directory, and create a "tar file" to submit using a command similar to:
tar cvf lab2.tar *.out *.txt *.c Makefile
This will create a file lab2.tar in your directory. Send this tar file as an attachment to jteresco AT siena.edu by 9:20 AM, Friday, February 3, 2012.
Please include a meaningful subject line (something like "CS330 Lab 2 Submission") and use the exact filenames specified (for this lab and all semester) to make my job easier when gathering your submissions together for grading. You don't want to annoy your grader with misnamed or missing files just before he grades your assignment. Please do not include any additional files, such as emacs backup files, object files, or executable programs.
Grading Breakdown | |
answers.txt responses and | 9 points |
forkfib.c correctness | 6 points |
forkfib.c efficiency, style, and elegance | 2 points |
forkfib.c documentation | 2 points |
forkfibshared.c correctness | 6 points |
forkfibshared.c efficiency, style, and elegance | 2 points |
forkfibshared.c documentation | 2 points |
pthreadfib.c correctness | 6 points |
pthreadfib.c efficiency, style, and elegance | 2 points |
pthreadfib.c documentation | 2 points |
Makefile(s) to build executables | 1 point |