Process States & Lifecycle

Operating Systems Part 2

ยท

4 min read

Process States & Lifecycle

Process States & Lifecycle

New State

  • New process is created and stored in secondary memory, and is ready to be invoked.

Ready State

  • The created process is brought into active state by user opening an application or executing some program.
  • Ready Queue brings the process into the RAM.
  • This is done by LTS or Long Term Scheduler.
  • The job of LTS is to bring as many processes into the RAM as possible. Multiprogramming concept at play here.

Running State

  • Process in the RAM is dispatched or scheduled to run in the CPU.
  • The number of processes in running state will depend on the number of processors in the CPU. A uniprocessor CPU will execute one process at a time.
  • The process is still in the RAM, but has been given a location for the CPU to work on.

Terminated State

  • Process is deallocated from the RAM after it's execution is completed.
  • Terminated state means the process is completely executed.
  • The result of the computation will be stored in the secondary memory.

Wait/Block State

  • 1st case is when a higher priority process is encountered, the current running process is put on hold and the high priority process is executed first. Multitasking at play here.
  • The process is sent back to ready state as the high priority process is under execution.
  • 2nd case is Time Quantum. The CPU runs a process for a fixed amount of time, and keeps moving to next process. The process which aren't executed completely, get scheduled to be executed in future.
  • This is performed by Short Term Scheduler(STS). It helps in preemptive scheduling of processes.
  • 3rd case is when a process has to perform an I/O operation, it is scheduled to be executed in future and CPU moves to the next process. This is where process is put into Wait/Block state and this queue is also present in the RAM itself.
  • After the I/O operation is done, the process is put into Ready state, and is scheduled to be executed when its turn comes.
  • 4th case, which is the worst case, is when all processes have to perform some I/O operation and are sent to the wait/block state.
  • When this queue is filled, a new momentary state of Suspend/Wait is created, and this is where any new process that is sent to the Wait/Block state, it is put back into the Secondary memory.
  • If memory in wait/block queue frees and the process in Suspend state has completed all I/O operation, then it is brought back to Wait/Block queue, otherwise it is kept in Suspend state till the time being.
  • This work is done by Medium Term Scheduler(MTS).
  • 5th case, when the Ready state queue is full, and a process with very high priority arrives, then processes are momentarily put into the Suspend/Ready state, and are resumed back when the high priority process is executed and space is created in the Ready State queue. This is also done by Mid Term Scheduler(MTS).
  • Backing Store is done by MTS when Wait/Block queue is full and processes in Suspend/Wait state are waiting, so they are sent to the Suspend/Ready queue, and if the Ready Queue is also full, then the processes wait in the Suspend/Ready queue.

Process vs Threads

ProcessThreads
1. System calls involved in process.1. There is no system call involved.
2. OS treats different processes differently.2. All user level threads treated as single task for OS.
3. Different processes have different copies of data, file, code.3. Threads share same copy of code and data.
4. Context switching is slower.4. Context switching is faster.
5. Blocking a process will not block another process.5. Blocking a thread will block entire process.
6. Independent.6. Interdependent.

Conclusion

You can read other articles written by me through these links.

Operating System Series
1. Introduction & Types of OS
2. Process States & Lifecycle
3. System Calls
4. User Mode vs Kernel Mode
5. CPU Process Scheduling
6. Process Synchronization
7. Deadlocks
8. Memory Management
9. Disk Management & Scheduling
10. File System in OS
11. Protection & Security

System Design Series
Introduction To Parallel Computing
Deep Dive Into Virtualization
Insights Into Distributed Computing

Cloud Computing Series
1. Cloud Service Models
2. Cloud Deployment Models
3. Cloud Security
4. Cloud Architecture
5. Cloud Storage
6. Networking In The Cloud
7. Cloud Cost Management
8. DevOps In Cloud & CI/CD
9. Serverless Computing
10. Container Orchestration
11. Cloud Migration
12. Cloud Monitoring & Management
13. Edge Computing In Cloud
14. Machine Learning In Cloud

Computer Networking Series
1. Computer Networking Fundamentals
2. OSI Model
3. TCP/IP Model : Application Layer
4. TCP/IP Model : Transport Layer
5. TCP/IP Model : Network Layer
6. TCP/IP Model : Data Link Layer

Version Control Series
1. Complete Guide to Git Commands
2. Create & Merge Pull Requests
3. Making Open Source Contributions

Linux
Complete Guide to Linux Commands

Thanks For Reading! ๐Ÿ’™
Garvit Singh

ย