Processes Vs Threads
Process: It is an execution unit where a program runs. The OS helps to create, schedule, and terminates the processes which is used by CPU. The other processes created by the main process are called child process. A process operations can be controlled with the help of PCB(Process Control Block). PCB contains all the crucial information related to processing like process id, priority, state, and contents CPU register, etc.
Important properties of the process:
- Creation of each process requires separate system calls for each process.
- It is an isolated execution entity and does not share data and information.
- Processes use the IPC(Inter-Process Communication) mechanism for communication that significantly increases the number of system calls.
- Process management takes more system calls.
- A process has its stack, heap memory, and data map.
Thread: A process can have multiple threads, all executing at the same time. A thread is lightweight and can be managed independently by a scheduler. It helps to improve the application performance using parallelism. Threads share information like data, code, files, etc
Important properties of Thread:
- Single system call can create more than one thread
- Threads share data and information.
- Threads shares instruction, global, and heap regions. However, it has its register and stack.
- Thread management consumes very few, or no system calls because of communication between threads that can be achieved using shared memory.
| Parameter | Process | Thread |
|---|---|---|
| Definition | Process means a program is in execution. | Thread means a segment of a process. |
| Lightweight | The process is not Lightweight. | Threads are Lightweight. |
| Termination time | The process takes more time to terminate. | The thread takes less time to terminate. |
| Creation time | It takes more time for creation. | It takes less time for creation. |
| Communication | Communication between processes needs more time compared to thread. | Communication between threads requires less time compared to processes. |
| Context switching time | It takes more time for context switching. | It takes less time for context switching. |
| Resource | Process consume more resources. | Thread consume fewer resources. |
| Treatment by OS | Different process are tread separately by OS. | All the level peer threads are treated as a single task by OS. |
| Memory | The process is mostly isolated. | Threads share memory. |
| Sharing | It does not share data | Threads share data with each other. |
Comments
Post a Comment