-Interview Question
I was asked the disadvantages of thread
. And what are the scenario where we shouldn't use thread
instead use process
?
I couldn't think much except invalid memory access in some case.
-Interview Question
I was asked the disadvantages of thread
. And what are the scenario where we shouldn't use thread
instead use process
?
I couldn't think much except invalid memory access in some case.
Threads, spawned by the same process, all share the same memory. Processes all run in their own memory context.
In Linux (I don't know what the behavior under Windows is like) a newly spawned child process will usually received a copy of certain part the parent process' memory context an therefore is more expensive memory-wise at runtime and CPU-time/MMU wise at creation. Also context switching - (off)loading the process from or to the CPU (this happens, when a process or thread has nothing to do and is pushed to a queue in favor of processes or threads with actual work) - might be more expensive with a process.
On the other hand processes might be much more secure since their memory is isolated from the memory of their sibling processes.