Program v/s Process v/s Thread

Program v/s Process v/s Thread

Three basic concepts that require clear understanding when we study operating systems or programming in general is the difference between a program, a process and a thread.


What is a Program?

A program is an executable file residing on the disk (secondary storage) in a directory. It is also termed as a set of instructions stored in the secondary storage device that are intended to carry out a specific job. It is read into the primary memory and executed by the kernel.

Therefore, a program is termed as a ‘passive entity’ which exists in the secondary storage persistently even if the machine reboots.

Few examples:

  • On a Microsoft Windows® system: The ‘Calculator’ program is stored at “:\windows\system32\calc.exe”.
  • On a Linux system: The ‘ls’ program is available at: “/bin/ls”.

What is a process?

An executing instance of a program is called a process. Some operating systems use the term ‘task‘ to refer to a program that is being executed.

A process is termed as an ‘active entity’ since it is always stored in the main memory and disappears if the machine is power cycled. Several process may be associated with a same program.

On a multiprocessor system, multiple processes can be executed in parallel. On a uni-processor system, though true parallelism is not achieved, a process scheduling algorithm is applied and the processor is scheduled to execute each process one at a time producing an illusion of concurrency.

Example: Executing multiple instances of the ‘Calculator’ program. Each of the instances are termed as a process.


What is a thread?

A thread is called a ‘lightweight process’. It is similar to a real process but executes within the context of a process and shares the same resources allotted to the process by the kernel.

A process has only one thread of control – one set of machine instructions executing at a time. A process may also be made up of multiple threads of execution that execute instructions concurrently. Multiple threads of control can exploit the true parallelism possible on multiprocessor systems. On a uni-processor system, a thread scheduling algorithm is applied and the processor is scheduled to run each thread one at a time.

All the threads running within a process share the same address space, file descriptor, stack and other process related attributes. Since the threads of a process share the same memory, synchronizing the access to the shared data within the process gains unprecedented importance.


What is the relationship of a thread, a process and a program?

The below image portrays the relationship between a process and threads. A process can be composed of several threads executing in parallel.

The image below depicts the relationship between a program and processes. A program can be subdivided into multiple processes executing in parallel.

Consider an example: Microsoft Word is a massive program that when loaded into the primary memory in-turn loads several processes which in-turn create several threads

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值