AAE-CNAS-Labs/Topic-3-Forking/README.md

740 B
Raw Blame History

Topic 3 Forking

Task 1

Write a simple program, where you create one child process.

Parent proces should write a "I am a parent" message, while your child process should write "I am a child".

man 2 fork

Task 2

Please extend last program - make both processes display their process ID (PID) and their parent's PID.

man 2 getpid man 2 getppid

Task 3

Modify last program, so that it creates not one but 5 child processes.

Task 4

Go back to the code from Task 2 (with one child process)

Please check, what happens when

  1. parent finishes execution before its child

  2. child finishes execution before its parent

Use sleep(..) function to force a delaay.

You can check process state using ps -f <pid> command