Search code examples
clinuxoperating-systemforksystem

How do I make a skewed tree using fork() in C?


I am looking to create a skewed tree with 3 nodes, 2 of which will have 1 child and the last node will be childless. I do not really understand how to proceed with this.

Example


Solution

  • This seems like the normal use of fork(), basically. Here's some pseudocode:

    // start in process 3
    int pid = fork();
    if (pid == 0) {
       int pid2 = fork();
       if (pid2 == 0) {
           // process 1
       } else {
           // process 2
       }
    } else {
       // process 3
    }