CSE 3544 · Processes in UNIX

Fork Lab

Paste a C program that uses fork(). Every process is simulated, so you see the process tree, what each process prints, and the full output.

Program

Tab indents · Ctrl/⌘ + Enter runs
Output goes to

Terminal: printf output is flushed at every newline, like running ./a.out directly.

0processes in total
0new processes created
0direct children of main
0lines printed

Process tree

Click a process to see only its output
created by fork() orphan: parent exited first Z zombie: never reaped by wait() Small number beside a node = lines it printed

Output

Each output line and how many times it appears

This is one possible order. Processes run at the same time, so the real order can change from run to run; the lines and their counts do not. Underline colour shows which process printed each piece.

Processes

PIDs are simulated, starting at 1000
PIDParentCreated atPrintedExit

What is simulated: fork, wait, waitpid, exit, atexit, sleep, getpid, getppid, exec* (shown as a note), printf family with real C formatting, scanf, malloc/free, arrays, pointers, structs and unions. Stdout buffering is modelled, so text printed without a newline before fork() is copied into the child, just as on a real machine. Infinite loops stop after a step limit. This is a teaching simulator; for exact results on edge cases, compile with gcc.