Process Life Cycle

Explain the life cycle of a process with proper diagram. 

A unix process is created in the idle state, and is then moved between ready to run, running, and possibly waiting (or sleeping), until it exits and becomes a zombie. Once a process, usually the parent process, reaps the exit status of the zombie, then the process is destroyed.The test program uses fork to create several children processes. Each receives an integer tag. The children then sleep for a bit then exit. The parent process sleeps after creating the children, waiting a short time after the children all exit before proceeding. The parent will then gather the output status of all the children, by repeated calls to wait, then wait again, then exit.

States of a UNIX Process

  • User running: Process executes in user mode
  • Kernel running: Process executes in kernel mode
  • Ready to run in memory: process is waiting to be scheduled
  • A sleep in memory: waiting for an event
  • Ready to run swapped: ready to run but requires swapping in
  • Preempted: Process is returning from kernel to user-mode but the system has scheduled another process instead
  • Created: Process is newly created and not ready to run
  • Zombie: Process no longer exists, but it leaves a record for its parent process to collect.

 

The life cycle of a normal Linux process covers before it is killed and removed from kernel process table.

  • A new process is created through fork() and if a new executable is to be run then exec() family of functions is called after fork().  As soon as this new process is created, it gets queued into the queue of processes that are ready to run.
  • If only fork() was called then it is highly likely that new process runs in user mode but if exec() is called then the new process will run in kernel mode until a fresh process address space is created for it.
  • While the process is running, a higher priority process can pre-empt it through an interrupt. In this case, the pre-empted process again goes into queue of processes that are ready to run. This process is picked up by the scheduler at some later stage.
  • A process can enter into kernel mode while running. This is possible when it requires access some resource like text file which is kept on hard disk. As operations involving access to hardware may take time, it is highly likely that process will go to sleep and will wake up only when the requested data is available.  When the process is awakened, it does not mean that it will start executing immediately, it will again queue up and will be picked for execution by scheduler at appropriate time.
  • A process can be killed through many ways. It can call exit() function to exit or can process Linux signals to exit. Also, some signals cannot be caught and cause the process to terminate immediately.
  • There are different types of Linux process. Once the process is killed, it does not get completely eliminated. An entry containing some information related to it is kept in the Kernel process address table till the parent process explicitly calls wait() or waitpid() functions to get the exit status of child process. Until parent process does this, the terminated process is known as zombie process.

Leave Comment

Important Topics

Title
Unix
Features of Unix
Block Diagram of Unix System
Architecture of Unix Operating System
Linux Operating System
Linux Vs Unix
Unix vs Windows
Shell and types of Shell
Kernal
Advantages and disadvantages of Unix
Unix File System
Types of File
Process
Daemon Process
Process Life Cycle
Fork System Call
Grep
Piping in Unix
Users and types of Users
User Management Systems
SUDO Users
Basic Shell Commands in Linux