Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Operating Systems (04JEZOQ)

LAB 2 simple process management


Exercise 1: write a C program that creates a parent and a child process using
the fork system call. The child process must print its PID, whereas the parent
process must print both its PID and the PID of the child.

Exercise 2: write a C program that creates 10 processes using the fork


system call. Each process must print its PID, wait for 5 seconds and than end
its execution. The father process waits until all children terminate and then
ends its execution.
Hint: Use sleep(msec) to pause the execution of a program for a given
time.

Exercise 3: modify the solution of exercise 2 so that the parent process


terminates when the second created child terminates.

Exercise 4: create a C program that manages 10 child processes. The


process wants to have 10 child processes always running. 5 processes have
to continuously generate a random number and print it on the screen, 5
processes have to continuously generate a random number and print it and its
square on the screen. Every time a child process terminates it must be
replaced by a new child of the same type.

You might also like