Operating Systems: Program Vs Process, What's the difference?

kathanvakharia

Kathan Vakharia

Posted on August 2, 2021

Operating Systems: Program Vs Process, What's the difference?

A Text Book Definition

A program in itself is just a text i.e. a passive entity.

When you run a program that is open an executable( .exe or a.out ), O.S creates an active entity known as process. A process is created for the program execution.

๐Ÿ’กA process is a program in execution

Confused, right? Let's take an example to make this distinction super obvious.

Understanding by Example ๐Ÿงถ

Image1

Let's say you wrote a C program, example.C

You compiled it into a.out using gcc example.C command.

It is important to note here is both of the files, example.C and a.out are programs only - a set of instructions.

Both files reside in the secondary memory i.e your hard disk.

Now when you type a.out in the terminal to execute the compiled file, your operating system creates a data structure( process ) for the program execution in the main/primary memory. It looks like the following,

Image 2

A good analogy is to think of processes like our body and program as our soul. The body cannot exist without a soul and the soul needs the body to take action!

The operating system's job is to give the set of instructions in a.out to CPU for execution one by one.

While executing a program,

  1. Stack space is used for function calling - to store activation records ( information about called function )
  2. Heap space is used for dynamic memory allocation - memory allocated using malloc, calloc function is present in this section of the process.

It is important to note that, the stack grows downwards and the heap grows upwards since before program execution operating system cannot predict the exact size of both.

โ— Don't confuse this heap portion with heap data structure, they both are completely different things.

That's it!

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
kathanvakharia
Kathan Vakharia

Posted on August 2, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Operating Systems: Process Control Blocks (PCB)
computerscience Operating Systems: Process Control Blocks (PCB)

September 25, 2021

Operating Systems: Introduction
computerscience Operating Systems: Introduction

July 28, 2021

ยฉ TheLazy.dev

About