AAE-CNAS-Labs/Topic-2
2021-03-24 14:44:17 +01:00
..
child_functions.c Fixed a typo and finished task_2_4 2021-03-10 22:56:48 +01:00
child_functions.h Fixed a typo and finished task_2_4 2021-03-10 22:56:48 +01:00
Makefile Added Topic-2 2021-03-10 17:42:09 +01:00
README.md Added README.md files for each Topic and finished task_3_3 2021-03-24 14:44:17 +01:00
task_2_1.c Fixed a typo and finished task_2_4 2021-03-10 22:56:48 +01:00
task_2_2.c Added README.md files for each Topic and finished task_3_3 2021-03-24 14:44:17 +01:00
task_2_3.c Added README.md files for each Topic and finished task_3_3 2021-03-24 14:44:17 +01:00
task_2_4.c Fixed a typo and finished task_2_4 2021-03-10 22:56:48 +01:00

Topic 2 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