CIS307: Homework 2: Using Unix System Services and Pthreads

This homework is given February 6 and is due February 23 by 5pm.

This homework is just a vehicle for using a lot of Unix system services, thus becoming familiar with them, and for using Pthreads. Look up the Stevens book and its code to see how system services work. For pthreads, use the man pages and the class notes. The homeworks requires you to write two separate programs.

PROGRAM 1

Your program generates three children. Thus we have the following processes PARENT, CHILD1, CHILD2, and CHILD3.
Your program is called with as parameters the names of six text files, say, fn1, fn2, fn3, fn4, fn5, fn6.
Fn1 and fn2 already exist. Fn3 and fn4 are created by the second process (first child). Fn5 and fn6 are created by the third process (second child).

Define a function selfid that prints out the process id of the current process and of its parent. Define a global integer variable called "self".

PARENT:

CHILD1:

CHILD2:

CHILD3:

As comment in your program explain:

PROGRAM 2

Write a program with a global integer variable "shrd". The program creates two threads and goes to sleep for RUN_DURATION seconds.

Thread 1 does the following:

Thread 2 does the following:

EXTRA CREDIT

Determine the time it takes to fork and the time it takes to start a thread. Do measuraments that are both precise and accurate.

ingargiola@cis.temple.edu