New Tutorials:   NUMPY    TKINTER    KOTLIN    JAVASCRIPT    SASS/SCSS    PL/SQL    Matplotlib    C++ Programs

Process in Operating System

A process is a program in execution which then forms the basis of all computation. The process is not as same as program code but a lot more than it. A process is an 'active' entity as opposed to the program which is considered to be a 'passive' entity. Attributes held by the process include hardware state, memory, CPU, etc.

Process memory is divided into four sections for efficient working :

  • The Text section is made up of the compiled program code, read in from non-volatile storage when the program is launched.

  • The Data section is made up of the global and static variables, allocated and initialized prior to executing the main.

  • The Heap is used for the dynamic memory allocation and is managed via calls to new, delete, malloc, free, etc.

  • The Stack is used for local variables. Space on the stack is reserved for local variables when they are declared.

The different Process States

Processes in the operating system can be in any of the following states:

  • NEW- The process is being created.

  • READY- The process is waiting to be assigned to a processor.

  • RUNNING- Instructions are being executed.

  • WAITING- The process is waiting for some event to occur(such as an I/O completion or reception of a signal).

  • TERMINATED- The process has finished execution.

Process Control Block

There is a Process Control Block for each process, enclosing all the information about the process. It is also known as the task control block. It is a data structure, which contains the following:

  • Process State: It can be running, waiting, etc.

  • Process ID and the parent process ID.

  • CPU registers and Program Counter. Program Counter holds the address of the next instruction to be executed for that process.

  • CPU Scheduling information: Such as priority information and pointers to scheduling queues.

  • Memory Management information: For example, page tables or segment tables.

  • Accounting information: The User and kernel CPU time consumed, account numbers, limits, etc.

  • I/O Status information: Devices allocated, open file tables, etc.

Process vs Program

Let us take a look at the differences between Process and Program:

Process Program
The process is basically an instance of the computer program that is being executed. A Program is basically a collection of instructions that mainly performs a specific task when executed by the computer.
A process has a shorter lifetime. A Program has a longer lifetime.
A Process requires resources such as memory, CPU, Input-Output devices. A Program is stored by hard-disk and does not require any resources.
A process has a dynamic instance of code and data A Program has static code and static data.
Basically, a process is the running instance of the code. On the other hand, the program is the executable code.

Process Scheduling

When there are two or more runnable processes then it is decided by the Operating system which one to run first then it is referred to as Process Scheduling.

A scheduler is used to make decisions by using some scheduling algorithm.

Given below are the properties of a Good Scheduling Algorithm:

  • Response time should be minimum for the users.

  • The number of jobs processed per hour should be maximum i.e Good scheduling algorithm should give maximum throughput.

  • The utilization of the CPU should be 100%.

  • Each process should get a fair share of the CPU.