Fork |
Thread |
- A fork is used for giving a new process which itself is the
copy of current process having code segment same as current process
with separate memory space.
|
- A process can have multiple threads ,and the execution of all
the threads of any process takes place parallely
|
- There is no shareing of memory between the two processes
(because they both have different behaviour),So both the processes
are assigned separate memory.
|
- There is no separate memory for threads ,memory and all other
resouces are shared between the threads.So we can easily access
shared data
|
- Forks look same as the parent process but they have different
process id and separate memory
|
- Threads have unique thread id and same process id
|
- The file lock that the parent process has set ,the child
process does not inherit it
|
- File locks set by parent process is also inherited by
thread
|
- Forking result in more overhead when compared to threads
because we have to assign new separate memory and environment for
the process
|
- Thread has less overhead when compared to forking because
thread does not require any separate memory and environment for the
process execution
|
- fork are the copy of parent process so it look same as the
parent process
|
- Thread is a light weigted process
|
- forking is faster as their is no need of context switching
|
- Threads are slow because we need to perform context switching
between the threads while execution. It is faster in case of
multithreaded system
|
- The portability of fork is more when compared to threads
|
- Threads are less portable than fork
|
- Debugging of code is easy on fork
|
- Debugging is hard in threads
|
- The crash of one process does not affect other process
|
- The crash in one affect the other because they have same memory
space
|
- forking is more secure than threading due to separate memory
space
|
- Threading is less secure than fork because of shared
memory
|
- Inter process communivcation is costly in forks
|
- Interprocess communication between threads is easy and less
costly
|
- Forking is easy to program when compared to threads
|
- Threads are hard to program
|