Program vs Process

What is a program and process? 

A process refers to a program that is currently in execution. To illustrate, consider a .cpp file, which is a source code file written in C++. This file must be compiled into machine language by a compiler, resulting in an executable file. The executable file contains the code in a format that the computer can directly execute, making it a program. The source code file (.cpp) itself is not a program because it needs to be compiled first. Once compiled, the executable file is what gets stored on disk and is used to create a process when it is run. OS is responsible for converting a program into a process. When you click on the TikTok app icon on your phone, it starts as a program residing on the disk. Clicking on it prompts the operating system to convert this program into a running process.

JOURNEY OF A PROGRAM TO PROCESS

1. Loading the Program
  • What Happens: The operating system (OS) loads the program from the storage (like a hard disk) into the main memory (RAM).  
2. Setting Up Memory: 
  • What Happens: The OS allocates memory for the process, including different regions like the stack and heap.
  • Stack: Allocates memory for the stack, which is used to manage function calls, local variables, and the execution flow.
  • Heap: Allocates memory for the heap, which is used for dynamic memory allocation (where the process can request, and release memory as needed during execution).
    
3. Creating the Process
What Happens: The OS creates a new process structure in its process table.
Process Control Block (PCB): The OS sets up a Process Control Block (PCB) for the new process. The PCB contains important information about the process, such as its state, program counter, CPU registers, memory management information, and I/O status.         
                                                        
4. Schedule the Process
What Happens: The process is then scheduled to run on the CPU according to the operating system’s scheduling algorithm.


YouTube links for further understanding...









Comments

Post a Comment

Popular posts from this blog

Indexed allocation

Thrashing

Basics of paging