Hewlett Packard Interview Question
Software Engineer / DevelopersProcesses are independent execution units that contain their own state information, use their own address spaces, and only interact with each other via interprocess communication mechanisms.
A single process might contains multiple threads; all threads within a process share the same state and same memory space, and can communicate with each other directly, because they share the same variables.
A thread is a stream of instructions in a process. A thread has its own stack , instruction pointer and address space but all these are in a virtual space which is process specific , so all thread can access each other's data. A thread thus can be termed as a light weight process.
A process is an instance of a computer program. Concurrency refers to a state where processor is involved in running several processes.
Also threads and processes differs in the way scheduling, priority and the way errno for syscalls are handled.
Processes are separately scheduled by the kernel whereas Threads within the processes are scheduled by the thread manager.
Thread doesn't have priority whereas the processes have the priority.
when system calls return error the errno is set per process within the thread specific data.
Also there is seperate entity called "kernel threads" which runs in the context of the kernel and are separetly scheduled similar to processes. These can reference each threads individaully unlike processes and user threads. But this is a kernel component and needs to be kernel modules to use it.
Thread is light weight process while Process is a heavy weight one..
- Abhi March 24, 2007A Process has its own memory space, runtime enivorment and process ID.
A Thread run inside a Process and shares its resources with other threads.