AAE-CNAS-Labs/Topic-3-Forking
2021-03-31 14:52:07 +02:00
..
child_functions.c Renamed the directories to match moodle 2021-03-31 14:52:07 +02:00
child_functions.h Renamed the directories to match moodle 2021-03-31 14:52:07 +02:00
Makefile Renamed the directories to match moodle 2021-03-31 14:52:07 +02:00
README.md Renamed the directories to match moodle 2021-03-31 14:52:07 +02:00
task_2_1.c Renamed the directories to match moodle 2021-03-31 14:52:07 +02:00
task_2_2.c Renamed the directories to match moodle 2021-03-31 14:52:07 +02:00
task_2_3.c Renamed the directories to match moodle 2021-03-31 14:52:07 +02:00
task_2_4.c Renamed the directories to match moodle 2021-03-31 14:52:07 +02:00

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