Processes in Unix

Traditional login

Creation by cloning

Process creation: fork1

The fork clones the executing process, creating a replica of it.

The address spaces of the two processes are equal.

  • actually, just after the fork, they are the same.

  • typically, a copy-on-write approach is followed.

The states of execution are the same.

  • including the program counter.

Some process variables are different (PID, PPID, ...).

Process creation: fork2 and fork3

The value returned by the fork is different in parent and child processes.

  • in the parent, it is the PID of the child.

  • in the child, it is always 0.

This return value can be used as a boolean variable.

  • so we can distinguish the code running on the child and parent.

In general, used alone, the fork is of little interest.

In general, we want to run a different program in the child.

  • exec system call.

  • there are different versions of exec.

Sometimes, we want the parent to wait for the conclusion of the program running in the child.

  • wait system call.

In this code, we are assuming the fork doesn’t fail.

  • in case of an error, it returns -1.

Launching a program: fork + exec

Last updated