The process is something that is currently under execution. So, an active program can be called a Process.
The execution of a process must follow a sequential order.
The process is not as same as the program but it is very different from it.
A process is an 'active' entity as opposed to the program which is considered to be a 'passive' entity.
A process can be defined as an entity that represents the basic unit of work to be implemented in the system.
For example, search something on the Internet using a browser, starting a video player to watch a video.
Thread
A thread is also called a Lightweight Process.
Each thread belongs to exactly one process and no thread can exist outside a process.
But, one process can contain multiple threads.
Each thread represents a separate flow of control, thread is a path of execution within a process.
A thread is a flow of execution through the process code, with its program counter that keeps track of which instruction to execute next, system registers that hold its current working variables, and a stack that contains the execution history.
Threads are generally used to improve the application through Parallelism.
In the operating system, there are two types of threads:
Kernel-level thread
User-level thread
Advantages and Disadvantages of Implementing Threads in Kernel Space
Advantages:
Multiple threads of the same process can be scheduled on different processors.
The routines of the kernel can also be multithreaded.
If a kernel-level thread is blocked, another thread of the same process can be scheduled by the kernel.
These threads are fully aware of all other threads.
Hence, Scheduler may decide to give more time to a process having a large number of threads than a process having a small number of threads.
-These threads are good for applications that frequently block.
Disadvantages:
Kernel manages and schedules threads as well as processes.
This requires a full Thread Control Block (TCB) for each thread to maintain information about threads.
Therefore, this creates significant overhead and increases complexity.
The implementation of threads at kernel space is more difficult and slow than implementing threads at user space.
These threads are slow and inefficient. Like operations of threads are hundreds of times slower than that of user-level threads.
A mode switch to kernel mode is required to transfer control from one thread to another in a process.
Advantages and Disadvantages of Implementing Threads in User Space
Advantages:
Implementing threads at user space is easier and faster to create than threads at the kernel level.
They can also be more easily managed.
These threads can be run on any operating system.
It does not need any support from the kernel-level threads.
The overall process is quick and effective because there is no requirement for a system call.
No need for the kernel-mode privileges for the thread to switch in user space.
The organization is straightforward because the threads are produced, switched, and controlled without interference from the kernel.
Do not require modification to operating systems.
Disadvantages:
It has poor scheduling due to a thread holding a lock.
These threads are invisible to the OS. Hence, they are not well integrated with the OS.
The entire process is blocked if one user-level thread performs a blocking operation.
There is a lack of coordination between threads and the kernel.
These threads require non-blocking systems call like a multithreaded kernel. Otherwise, the entire process will be blocked in the kernel.
One thread causes a page fault, the process blocks.
Multithreaded applications cannot use multiprocessing to their benefit.