Qualcomm Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
Difference Between threads and processes
* Processes do not share their address space while threads executing under same process share the address space.
*From the above point its clear that processes execute independent of each other and the synchronization between processes is taken care by kernel only while on the other hand the thread synchronization has to be taken care by the process under which the threads are executing
*Context switching between threads is fast as compared to context switching between processes
*The interaction between two processes is achieved only through the standard inter process communication while threads executing under the same process can communicate easily as they share most of the resources like memory, text segment etc
****************************************************************************************
When a process executes a fork call, a new copy of the process is created with its
own variables and its own PID. This new process is scheduled independently, and (in general) executes almost independently of the process that created it. When we create a new thread in a process, in contrast, the new thread of execution gets its own stack (and hence local variables) but shares global variables, file descriptors, signal handlers, and its current directory state with the process that created it.
************************************************************************************************
A process is an executing instance of an application. Eg: When you double-click the Microsoft Word icon, you start a process that runs Word. A thread is a path of execution within a process. Also, a process can contain multiple threads. Eg: When you start Word, the operating system creates a process and begins executing the primary thread of that process.
- victor November 05, 2012A thread can do anything a process can do. But since a process can consist of multiple threads, a thread could be considered a ‘lightweight’ process. Threads are used for small tasks, whereas processes are used for more ‘heavyweight’ tasks – basically the execution of applications.
Communication between threads is very fast because they share same address space which allow them to read from and write to the same data structutre and variables. Communication between process is called inter-process communication and is quite difficult and resource intensive.