Process Creation
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
-
P1
execsP2
:graph LR P1 --> P2 P2--> 1[ ]
-
P1
forks, then child execsP2
:graph LR P1 --> P2 P1 --> 1[ ] P2 --> 2[ ]
-
The same as before by now
P1
issues await()
call.graph LR P1 --> P2 P1 -.-> 1[ ] P2 --> 1[ ] 1 --> 2[ ]
Unix Processes
- 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.
- Process 1 is
init
(nowsystemd
on Linux):- Parent of all other processes.
- Spawns daemon processes.
- Spawns process for user login.
- 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.
- Shell prompts for commands, then forks and execs to carry out those commands.
- 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.