Contents

Processes and Threads | Operating System

What’s OS (Operating System)

Assume that we have a program written in Java, Python, C, etc. sort of high-level language, that a PC wouldn’t be able to execute. We need a compiler to translate those languages to 0, 1 binary codes for a PC to run.

When those programmes are being executed, they will consume some resources from the computer. How do we allocate the resources? Who will do this for the programs?

This is when an Operating System (OS) comes in.

The OS will help in loading that executable program and allocate the memory and the resources later to be used.

Process vs Program

A process is a running program that serves as the foundation for all computation. The procedure is not the same as computer code, although it is very similar.

In contrast to the program, which is often regarded as some ‘passive’ entity, a process is an ‘active’ entity.

Hardware status, RAM, CPU, and other attributes are among the attributes held by the process.

How a Process Work

featured-image.png
how a process work
When you start a programme, it’s first loaded and given an address space in the main memory from your hard disk. After it’s loaded in memory, it’s then scheduled onto the available CPU. And the programme instruction then would be executed sequentially.

Process vs Thread

S.NOProcessThread
1.Process means any program is in execution.Thread means a segment of a process.
2.The process takes more time to terminate.The thread takes less time to terminate.
3.It takes more time for creation.It takes less time for creation.
4.It also takes more time for context switching.It takes less time for context switching.
5.The process is less efficient in terms of communication.Thread is more efficient in terms of communication.
6. Multiprogramming holds the concepts of multi-process.We don’t need multi programs in action for multiple threads because a single process consists of multiple threads.
7.The process is isolated.Threads share memory.
8.The process is called the heavyweight process.A Thread is lightweight as each thread in a process shares code, data, and resources.
9.Process switching uses an interface in an operating system.Thread switching does not require calling an operating system and causes an interrupt to the kernel.
10.If one process is blocked then it will not affect the execution of other processes If a user-level thread is blocked, then all other user-level threads are blocked. 
11.The process has its own Process Control Block, Stack, and Address Space.Thread has Parents’ PCB, its own Thread Control Block, and Stack and common Address space.
12.Changes to the parent process do not affect child processes.Since all threads of the same process share address space and other resources so any changes to the main thread may affect the behavior of the other threads of the process.
13.A system call is involved in it.No system call is involved, it is created using APIs.
14.The process does not share data with each other.Threads share data with each other.

Resource: Difference between Process and Thread - GeeksforGeeks

Process

Processes are basically the programs that are dispatched from the ready state and are scheduled in the CPU for execution. PCB(Process Control Block) holds the concept of process. A process can create other processes which are known as Child Processes. The process takes more time to terminate and it is isolated means it does not share the memory with any other process.

The process can have the following states new, ready, running, waiting, terminated, and suspended.

Thread

Thread is the segment of a process which means a process can have multiple threads and these multiple threads are contained within a process. A thread has three states: Running, Ready, and Blocked.

The thread takes less time to terminate as compared to the process but unlike the process, threads do not isolate.

Multithreading

Why is The Threads Useful

  • Multiprocessing
  • Requires no synchronization
  • Operating System prevents processes from writing to another processes address space
  • Address spaces large
  • Porcesses can take up much more memory than threads (cost is always less or equal to process)
  • Resource sharing

/blog/posts/2022/processes-and-threads-operating-system/Multithreading.png
Multithreading