Process in Operating System

What is a Process in Operating System

The world of operating systems is a complex and fascinating one. It involves the coordination and management of various system resources to ensure efficient and reliable execution of tasks. One fundamental concept in operating systems is a process.

In this article, we will explore the concept of a process, its states, management, and significance in the realm of operating systems.

Process in Operating System for multi tasking

Understanding the Process States

A process can exist in different states during its lifetime. The common process states include:

  • New: This is the initial state when a process is being created.
  • Ready: The process is loaded into main memory and waiting to be assigned to a processor.
  • Running: The process is being executed by a processor.
  • Blocked: The process is unable to execute further until a certain event occurs, such as waiting for user input or completion of I/O operations.
  • Terminated: The process has completed its execution or has been forcefully terminated.

Process Scheduling

Process scheduling is a vital aspect of operating system design. It determines the order in which processes are executed by the processor.

Different scheduling algorithms, such as First-Come, First-Served (FCFS), Shortest Job Next (SJN), Round Robin (RR), and Priority Scheduling, are used to allocate CPU time to processes efficiently. These algorithms aim to optimize resource utilization and minimize process waiting times.

Process Creation

Processes are created in various ways, such as when a user initiates a program or when the operating system launches system processes during startup. The process creation involves allocating necessary resources, setting up the execution environment, and initializing the process control block. Once created, the process enters the new state and awaits execution.

Process life cycle

Process Termination

Process termination occurs when a process finishes executing its task or when it is explicitly terminated by the operating system. Upon termination, the operating system releases the allocated resources, updates the process’s state to “terminated,” and removes its PCB from the system.

Interprocess Communication

In modern operating systems, processes often need to communicate and share information with each other. Interprocess communication (IPC) mechanisms facilitate this exchange of data between processes. Common IPC methods include shared memory, message passing, pipes, and sockets. These mechanisms enable efficient coordination and collaboration among different processes.

States of Processes

A process can be in the following states –

  1. New
  2. Ready
  3. Run
  4. Wait
  5. Running
  6. Terminated

Apart from this a process in modern system can also be stated in the following two states –

  1. Suspended Ready
  2. Suspended Block

We will discuss these in detail below

Real life Scenario –

Let us consider we write a program to play a sound, when we execute this program this program creates a process for operating system. The operating system now queues up the command to implement and music is played. Simple !!!

Well, its not that simple even for a process to run in a modern OS there are many other stages in the life-cycle of a process, let’s discuss those in details.

Process Life Cycle

Process life cycle consists of the following stages –

  1. New – Whenever, a fresh process is created it gets available in the new state, it can collect relevant resources like data, I/O access etc in the mean time
  2. Ready – It gets assigned to ready stage where it waits to be assigned to a processor. This is a sort of a queue for all processes which are waiting for processor, such queue is called the Ready Queue.
  3. Running – The process is being executed by processor it gets into running stage.
  4. Waiting – Sometimes, cases happen when a process has to accept an additional input from user or maybe a higher priority process needs processor, in such cases the process goes to wait stage or waiting queue where all the processes are waiting for processor and complete their execution.
  5. Terminated – When process has completed executing its all instructions or when it’s ended by the user directly it goes to terminated stage.

Apart from this new age system also classify –

  1. Suspended Ready – If ready queue is full and has no space for new process then entry level process is in suspended Ready State
  2. Suspended Block – If the waiting queue is full

Process Elements

Every process has a process memory, which is generally divided into 4, this is done to make the most efficient functioning as possible –

  1. Stack – This houses all the temporary data and local variables like function parameters and addresses.
  2. Heap – When the process is in its run time, for dynamic memory allocation, for operations such as new(), delete(), malloc(), etc heap is used for fastest access at the run time.
  3. Text – Contains value of Program Counter and the contents of the processor’s registers which just the most low level instructions of the compiled program
  4. Data – Has static and global variables. 
Image of process in Memory

Process Control Block (PCB)

  • The Process Control Block (PCB) is a data structure used by the operating system to manage and keep track of processes.
  • It contains important information about a process, including its current state, program counter, CPU registers, memory allocation details, and more.
  • The PCB allows the operating system to effectively manage and switch between processes, ensuring fair allocation of resources.

Final Thoughts :

In simple words, a process is just a program that is running on your computer. It helps the operating system do many things at once, like opening apps, playing music, or browsing the internet – all at the same time.

Processes are created when you open a program and are removed when you close it. The operating system keeps everything organized so that each process gets the time and resources it needs without any trouble.

So, understanding how processes work gives us a better idea of how our computers run smoothly and handle so many tasks together.

FAQs

A program is just a set of instructions saved in a file. A process is what that program becomes when it starts running. So, a process is an active version of a program.

A process can be in different states like:

  • New (just created),
  • Ready (waiting to run),
  • Running (currently running),
  • Waiting (paused, waiting for something),
  • Terminated (finished running).

Process scheduling is the method used by the operating system to decide which process gets to use the CPU and for how long. This helps in multitasking and keeps everything running smoothly.

A process is a complete program with its own memory. A thread is a smaller part of a process that shares the same memory. Threads help a process do multiple things at the same time, like loading a video while showing the controls.