Issue
please bear with me as I am not good at framing question. and upto best of my knowledge this is not repeated question. and for sure this is not home work.
When we call fork, a thread is created, which shares the heap memory with the parent process. what will happen if I overlay this thread's address space with a different process image (using exec)
1) each segment will be overwritten by corresponding segment of the new process or Is it like, full virtual address space will be overwritten by new process's full address space ?
2) extra heap memory would be assigned by OS for this new process ? & heap (shared before) will no more be accessible to new process ?
3) all this confusion is because I don't know whether executable (ready to load) has heap segments or not.
Solution
Fork creates memory that is marked as copy on write, so that the processes cannot affect each other through this path.
Exec releases access to the shared memory, leaving it to the other process. It then allocates entirely new memory for the new process image.
It's actually more complicated than this, to maintain open file descriptors and the like but this is a useful approximation.
EDIT: I think what you want to know on the 3rd point is: The new process is initialized with a new empty heap area. But it probably has some allocations performed by the runtime library prior to main() being called.
Answered By - Darron Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.