Let look at Process and Thread, and User and Kernal Level Thread | Operating System EP-11
In this article, you will the difference between Processes and Threads in an operating system. Here, we are talking about a multiprocessing/ multitasking environment.
Let’s take a general overview of both things. A process is a heavyweight task while a thread is a lightweight task.
Process:
In the process, we fork the process, and by it, a duplicate process starts, which has its own Data, code, stack, and register
System calls are involved in the process (e.g. fork). Here operating system/kernel is responsible for making multiple processes.
Operating system treats different processes differently.
Different processes have different copies of data, files, and codes.
Context switching is slow.
Blocking a process will not lock the other process.
Independent in nature.
Thread:
- In the thread, if we create multiple threads of a task, then both threads will share the data, code while they have their own stack and registers.
There is no system call involved (generally at the user level). Here user or the API is responsible for making multiple threads.
All user-level threads are treated as single levels for the operating systems.
Threads share same copy of code and data.
Context switching is faster.
Blocking a thread will block the entire thread.
Interdependent in nature. Because they share memory and address.
Now let see difference between User-level and Kernel level threads in an operating system. Here, we are talking about multiprocessing/multitasking environment.
Remember one thing that, user-level thread and kernel-level thread always share code, file, and data while they have different stacks and registers, that’s why these are known as Lightweight processes.
User Level Thread:
User-level threads are managed by user-level libraries. It means that it is the responsibility of the application to create user level thread.
User-level threads are typically fast.
Context switching is faster.
If one user-level thread performs blocking operations then entire process get blocked.
Kernal Level Thread:
Kernel level threads are managed by the operating system. We have to use system calls for it.
Kernel-level threads are slower than user-level threads.
Context switching is slower.
If one kernel-level thread blocked, no effect on others.
Hybrid environment:
At present we use a hybrid environment, which means that we have both user-level thread and kernel-level thread.
Generally we use two user-level threads and map it with one kernel-level thread.
We can map it by using the many to one, one to many, many to many methods. Just like Linux-based operating systems in general use one-to-one methods, to map user-level thread and kernel-level thread.
Context switching time: Process > KLT > ULT