A Unix Process Text
Resources Resources
Data Stack
Process Status
File File
UNIX kernel
pid = 25 Text
How Fork Works Resources Resources
Data Stack
Process Status
File File
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
UNIX kernel
pid = 25 Text
How Fork Works Resources Resources
Data Stack
Process Status
File File
pid = 26 Text
Data Stack
Process Status
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
UNIX kernel
pid = 25 Text
How Fork Works Resources Resources
Data
Text
Stack File File
Process Status
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
UNIX kernel
Data Stack
Process Status
cpid = 0
cpid = 26
pid = 26
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
pid = 25 Text
How Fork Works Resources Resources
Data
Text
Stack File File
Process Status
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
UNIX kernel
Data Stack
Process Status
cpid = 0
cpid = 26
pid = 26
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
pid = 25 Text
How Fork Works Resources Resources
Data
Text
Stack File File
Process Status
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
UNIX kernel
Data Stack
Process Status
cpid = 0
cpid = 26
pid = 26
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
pid = 25 Text
How Fork Works Resources Resources
Data
Text
Stack File File
Process Status
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
UNIX kernel
Data Stack
Process Status
cpid = 0
cpid = 26
pid = 26
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
pid = 25 Text
How Fork Works Resources Resources
Data
Text
Stack File File
Process Status
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
UNIX kernel
Data Stack
Process Status
cpid = 0
cpid = 26
pid = 26
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
pid = 25 Text
How Fork Works Resources Resources
Data
Text
Stack File File
Process Status
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
UNIX kernel
Data Stack
Process Status
cpid = 0
cpid = 26
pid = 26
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
pid = 25 Text
How Fork Works Resources Resources
Data Stack File File
Process Status
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
cpid = 26
UNIX kernel
pid = 25 Text
How Fork Works Resources Resources
Data Stack File File
Process Status
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
cpid = 26
UNIX kernel
pid = 25 Text
How Fork Works Resources Resources
Data Stack File File
Process Status
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
cpid = 26
UNIX kernel
pid = 25 Text
How Fork Works Resources Resources
Data Stack File File
Process Status
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid); <…>
cpid = 26
UNIX kernel
How Exec Works Resources Resources
Text
File File
Data Stack
Process Status
cpid = 0
UNIX kernel
pid = 26
<…> int cpid = fork( ); if (cpid = = 0) { exit(0); } <parent code> wait(cpid);
How Exec Works Resources Resources
Text
File File
UNIX kernel
Data Stack
Process Status
cpid = 0
foo
pid = 26
<…> int cpid = fork( ); if (cpid = = 0) { exec(“foo”); exit(0); } <parent code> wait(cpid);
How Exec Works Resources Resources
Text
File File
UNIX kernel
Data Stack
Process Status
cpid = 0
foo
pid = 26
<…> int cpid = fork( ); if (cpid = = 0) { exec(“foo”); exit(0); } <parent code> wait(cpid);
How Exec Works Resources Resources File File
foo
UNIX kernel
pid = 26
How Exec Works Resources Resources File File
pid = 26 Text
Data Stack
Process Status
<…> <…> <…> exit(0);
foo
UNIX kernel
How Exec Works Resources Resources File File
pid = 26 Text
Data Stack
Process Status
<…> <…> <…> exit(0);
UNIX kernel
How Exec Works Resources Resources File File
pid = 26 Text
Data Stack
Process Status
<…> <…> <…> exit(0);
UNIX kernel