Infosys Interview Question
Software Engineer / DevelopersProcess is the execution state of a program. An application (or program) may consist of a single process or multiple processes. A thread is a path of execution with in a process. There can be one or more threads runnig within a process. A process has it's own address space, data segment, code segment, stack, state, register sets etc. A thread shares the process's address space but has its own stack, state and register set. Because of this context switching between processes is more costlier and resource intensive than context switching between threads. Since the threads share process's address space, it is easy for threads to communicate using shared memory area. For processes to communicate special inter process mechanisms like FIFO, pipes, shared memory regions etc need to be setup. This makes inter process communication costly. But threads also have its share of problems because of sharing address space. It can pollute the address space of the process. Threads require synchronization mecahinsms to avoid race conditions while accessing shared variables for communciation. One can go into other details like differences between threads and child processes also. But these are the major differences.
The next question after you answer this comes, if threads are advantageous than processes, why do we have processes? Anyone.
Threads are a way for a program(process) to fork (or split) itself into two or more simultaneously (or pseudo-simultaneously) running tasks. The term Thread and process are used interchangeably but in general process is a bigger Aspect of a thread. In the sense that a thread is smaller part of excution of a program or process.
process is a program under execution
- saneep March 13, 2007Thread is a tiny program.