The document provides instructions for 4 exercises on simple process management using C. Exercise 1 has the student write a program to create a parent and child process using fork, with each printing their PID. Exercise 2 extends this to create 10 processes, each printing their PID before sleeping for 5 seconds. The parent waits for all children to terminate. Exercise 3 modifies Exercise 2 so the parent terminates when the second child does. Exercise 4 creates a program to manage 10 continuously running child processes - 5 printing random numbers, 5 printing random numbers and their squares, replacing terminated children to maintain 10 processes.
The document provides instructions for 4 exercises on simple process management using C. Exercise 1 has the student write a program to create a parent and child process using fork, with each printing their PID. Exercise 2 extends this to create 10 processes, each printing their PID before sleeping for 5 seconds. The parent waits for all children to terminate. Exercise 3 modifies Exercise 2 so the parent terminates when the second child does. Exercise 4 creates a program to manage 10 continuously running child processes - 5 printing random numbers, 5 printing random numbers and their squares, replacing terminated children to maintain 10 processes.
The document provides instructions for 4 exercises on simple process management using C. Exercise 1 has the student write a program to create a parent and child process using fork, with each printing their PID. Exercise 2 extends this to create 10 processes, each printing their PID before sleeping for 5 seconds. The parent waits for all children to terminate. Exercise 3 modifies Exercise 2 so the parent terminates when the second child does. Exercise 4 creates a program to manage 10 continuously running child processes - 5 printing random numbers, 5 printing random numbers and their squares, replacing terminated children to maintain 10 processes.
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.