Program, process and thread

Program

A program is a passive entity, an executable file with instructions to perform a specific task / to complete a job or operation on your computer.

Some key features of a program in the context of operating systems: -

  • Nature: Programs are static and inactive until executed.
  • Storage: Programs exist as files in secondary memory.
  • Execution: Programs are not directly executable by the computer. They need an interpreter or compiler to be executed.
  • Resources: Programs do not consume system resources while not running.
  • Examples: Microsoft Word, Photoshop, Web Browsers.

Process

A process is an active instance of a program currently being executed by the Operating System. It includes the program's code, data, and system resources needed for its execution.

Some key characteristics of a process: -

  • Nature: Processes are dynamic and active entities.
  • Lifecycle: The lifecycle of a process is dynamic and can change between different states like new, ready, running, waiting, terminated, etc.
  • Resources: Processes consume system resources like CPU, memory, and I/O devices during execution.
  • Interaction: Processes interact with the operating system and other processes through system calls.
  • Creation: Processes are created by the operating system when a program is executed.

Thread

A thread is a lightweight unit of execution within a process. It is a single sequential flow of control that can execute independently within a process.

Some key characteristics of threads:

  • Lightweight: Threads are lightweight compared to processes as they share resources like memory and files.
  • Components: Each thread has its program counter, register set and stack space.
  • Execution: Threads execute sequentially but give the illusion of parallel execution.
  • Sharing: Threads share the same memory and resources within a process.
  • Scheduling: Threads are scheduled by the operating system to execute on the CPU.