Skip to content
UoL CS Notes

Process Creation

COMP124 Lectures

On most systems, processes are created (spawned) by other processes. The original process is the parent, and the new process is the child.

Hence we end up with a kind of ancestral tree of processes.

Unix

  • The exec() system call allows one program to execute another:
    • They stay in same process.
    • New program overwrites caller
  • The fork() call spawns a new process:
    • Child is identical to parent.
  • The wait() call suspends parent until child terminates.

Execution Scenarios

  1. P1 execs P2:

     graph LR
     P1 --> P2 
     P2--> 1[ ]
    
  2. P1 forks, then child execs P2:

     graph LR
     P1 --> P2 
     P1 --> 1[ ]
     P2 --> 2[ ]
    
  3. The same as before by now P1 issues a wait() call.

     graph LR
     P1 --> P2 
     P1 -.-> 1[ ]
     P2 --> 1[ ]
     1 --> 2[ ]
    

Unix Processes

  1. At startup, kernel creates process 0:
    • Kernel-level process, so can access kernel code and data structures directly.
    • Eventually becomes swapper, responsible for moving processes to/from disk.
    • Before this, it spawns other kernel-level processes.
  2. Process 1 is init (now systemd on Linux):
    • Parent of all other processes.
    • Spawns daemon processes.
    • Spawns process for user login.
  3. Unix processes:
    • When user logs on, the login process checks name and password against stored details, then execs shell.
    • User can alter their preferred choice of shell.
  4. Shell prompts for commands, then forks and execs to carry out those commands.
  5. At logout, shell process dies:
    • init/systemd is informed, and creates new login process.

Zombies and Orphans

Parent processes usually wait for their children to die. If the death of a child is not acknowledged by the parent (via wait call), the child becomes a zombie:

  • No resources, but still present in process table.

If parent dies before its children, the children become orphans

  • Get “adopted” by init process.

Daemons

  • Not associated with any user or terminal.
  • Run permanently in background.
  • Perform tasks requested of them by other processes.
    • Act as server process.
  • Carry out the background tasks of the OS:
    • Subsystem managers are background processes.
    • They need their own time on the CPU.