Results 1 to 2 of 2
Hi all,
fork creates two processes which share the same code space but different data space. Now, if you exec another process from the child, the new process over writes ...
- 09-11-2009 #1Just Joined!
- Join Date
- Mar 2008
- Location
- Chennai, India
- Posts
- 26
fork vs exec
Hi all,
fork creates two processes which share the same code space but different data space. Now, if you exec another process from the child, the new process over writes the code space of the calling process.
let us say P1 forks P2, P1 and P2 share same code space, now if P2 execs P3, which over writes code space of P2, which is shared by P1 also!!
How can P1 execute now?
This is a bit tricky. Hope I conveyed myself properly.
Cheers,
Sarma
- 09-11-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
exec doesn't overwrite the code space of the other process. The other process can continue to run without problems. You need to read some manuals on the Unix/Linux process model to better understand what's going on here. Also, Linux and Unix use a copy-on-write algorithm, so even with fork(), the child process doesn't change data pages until they are written to, when ONLY the written pages are copied and modified. This reduces memory utilization, and improves performance especially in cases where the data image is large. FYI, this copy-on-write virtual memory algorithm was originally patented by IBM.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote