What is a process in Operating System?

0liverFlow
5 min readFeb 3, 2023

--

Process meaning

Whether you utilize Windows or a Unix-like Operating System, you have probably been confronted one day to processes. If not, no worries!

In this article, we are going to cover the following topics:

  • Process definition
  • Process Block Control (PCB)
  • Process scheduling
  • Preemptive and non-preemptive scheduling

Let’s commence guys!

Process definition

Simply put, a process is a running program.

A program is an executable file which contains a set of instructions that will be executed by the OS.

But what differentiate a program from a software ?

A software is nothing else than a set of programs.

Indeed, whenever you launch a software (for instance your browser), your OS creates a new process and saves its information in something called the Process Control Block or PBC.

No biggie, that’s what we are going walk through in the next section.

Process Control Block

As previously mentioned, the OS saves a process information in the PBC.

Alright! But what kind of information does the PBC contain about the process ?

Well, the PBC contains lots of information like the process id , the process states, the I/O status information, accounting information, the CPU registers and program counter.

Here is an image of the information contained in a PBC:

Process Control Block information

Nevertheless, we will be focusing on the PID and the process states in this article.

PID

The PID or Process IDentification which is a unique number that the OS assigned to a process when it is created. This number allows you to identify each process on your computer.

Super! Nevertheless, does the OS set a limit to the number of processes we can run?

Yes, that is the case for GNU/Linux systems for instance.

Why did they do that?

Mainly for security reasons. In fact, if you are allowed to run unlimited processes, there is a high likelihood that your system will eventually use up all of its available resources as you create more and more processes. As a result, your system will probably crash and i guess that’s not what you want.

How can i check the limited number of processes on a GNU/Linux OS ?

To do that, you have two choices:

  • In one hand, you can take a look at the file :/proc/sys/kernel/pid_max using the command: cat /proc/sys/kernel/pid_max
  • In the other hand, you can execute the following command line : sysctl kernel.pid_max

The image below is an illustration of how to check the maximum number of processes.

Check the maximum number of processes

Well, let us move on to discussing the process states.

Process states

When talking about process states, it is good to know that we distinguish five states:

  • New state: This state corresponds to the process creation. During this state, no ressources are allocated to the process.
  • Ready state: During this step, ressources are allocated to the process. In fact, the process is firstly loaded into RAM (Random Access Memory (RAM) or main memory, then placed in the queue of processes which are waiting for the CPU.
  • Running state: The CPU is allocated to the process so that it can start running.
  • Block/Wait state: Sometimes, when running a process, it might require resources like a keyboard input or waiting for a child process to finish. In such circumstances, the process will be placed in the queue of processes that are in waiting or block state in the main memory.
  • Terminated: The process has completed. One thing to note is that, during this state, the PCB of the process is also deleted.

The image below shows a summary of process different states:

Process different states

Preemptive Scheduling !? Non preemptive scheduling !?

No worries, these terminologies are explained below.

Process scheduling

Process Scheduling happens when the OS schedules processes of different states like ready, blocked, and running.

Process scheduling allows OS to allocate a quantum for each process.

A quantum is a time interval of CPU execution.

Another important reason for using a process scheduling system is that it keeps the CPU busy all the time. This allows you to get the minimum response time for programs.

Preemptive and non preemptive scheduling

Preemptive scheduling (running 2 ready, waiting 2 ready)

Preemptive scheduling is used when a process switches from running state to ready state or from the waiting state to ready state.

After consuming the resources that were allocated to it, the process is placed back again in the ready state if it has cpu burst time remaining.

Non preemptive scheduling (running 2 wait, terminated)

Non preemptive scheduling is used when a process switches from running state to waiting state or when a process terminates.

In contrary to preemptive scheduling, once the resources are allocated to a process, the process holds the CPU until it gets terminated or reaches a waiting state. In this type of scheduling, the process running is not interrupted because the non preemptive scheduling has to wait until the process completes its CPU burst time, then it can allocate the CPU to another process.

Let’s wrap up!

In this article, we have learnt so far that:

  • A process is a running program.
  • When a process is launched, the OS saves its information in the Process Block Control.
  • PID is a unique number identifying a process.
  • During its life cycle, a process can go through different states such as new, ready, running, wait/block, terminated.
  • A process scheduling does happen when OS schedules processes of different states.
  • A preemptive scheduling is used when a process switches from running state to ready state or when it switches from waiting state to ready state.
  • A non preemptive scheduling is used when a process switches from running state to waiting state or is terminated.

Well done guys 👏!

Hope you learnt something!

Do not forget to subscribe to the newsletter to keep up with the latest articles.

--

--

0liverFlow
0liverFlow

Written by 0liverFlow

Pentester | Enjoy breaking and building stuffs

No responses yet