PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 22, 2022

[FIXED] When is heap memory made separate for a process? What happens in the exec system call?

 July 22, 2022     exec, fork, heap-memory, linux, multithreading     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing