11. Difference Between Single-Threaded and Multi-Threaded Processes
What is the difference between single-threaded and multi-threaded processes in Linux? Discuss the advantages of using multiple threads within a process compared to using multiple processes.
In single threaded process, all resources are being utilized by one thread only whereas in multithreaded process, all resources are being shared between them. In a multithreaded system,the main thread creates the new threads. The primary advantage of multi threaded process is that when the process has a lot to do, threads can run simultaneously on multiple processors, potentially speeding up the computation. Though we can use multiple processes also, but threads are lightweight and it is easier for threads to communicate via shared memory, whereas the process needs to communicate over a channel like a network or a pipe.
A process with one thread is called single-threaded and a process with more than one thread is called multi-threaded.
All processes start out as single-threaded. this starting thread is usually called the main thread.
The main thread may start new threads, making the process multi-threaded , similar to the way a process can call fork() to start a new process.
The primary advantage of multi-threaded process is that when the process has a lot to do, threads can run simultaneously on multiple processors, potentially speeding up computation, although you can also achieve simultaneous computation with multiple processes , threads start faster than processes and it's often easier or more efficient for threads to intercommunicate using their shared memory than it for processes to communicate over a channel , such as a network connection or a pipe.