Skip to content

Instantly share code, notes, and snippets.

@r1walz
Last active November 5, 2018 21:07
Show Gist options
  • Save r1walz/f6b110c6232761ed689d76fb7006780c to your computer and use it in GitHub Desktop.
Save r1walz/f6b110c6232761ed689d76fb7006780c to your computer and use it in GitHub Desktop.
Snippet used to explain the fork.c code in unix fork lecture

My understanding of fork/buffer

The code that I will explain is available here.

Concept

Everything is copied (on write) to child on forking, hence, every process will have a different buffer! (but contents will be same as parent initially).

Explanation

The program is create a child (C.1) from parent process (C), then, prints the info about the child. Again forking from C.1 which results into C.1.1 being created and then printing info about C.1.1. Finally a fork happens from C.1.1 resulting into C.1.1.1 (bad naming convention, IKR). Last print statement again prints information about each child and parent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment