Skip to content

Instantly share code, notes, and snippets.

@inancguney19
inancguney19 / fork.c
Created April 2, 2023 11:14 — forked from MasterGeekMX/fork.c
C code to spawn a binary tree of processes using fork(). Tree depth is set by a variable passed as first argument at invocation.
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
void tree(int n){ //Creates a process tree
if (n==0) return; //We have reached a leaf, so we leave.
int rchild=fork(); //create right child
if (rchild!=0){ //we are the parent