3

When we execute a process from a terminal, The termainal process does a fork and then exec. During fork, it creates its own copy which contains process specific information which in this case is Bash for example. Copying this memory can take some time even for some small processes which can delay the execution then Why do we copy memory during fork? How does it make sense to copy a large amount of data from a big process for a small process?

sahil shekhawat
  • 1,208
  • 12
  • 14
  • 2
    Linux does not copy all the memory straight away. It merely copies the mappings. The memory is shared between parent and child until there is a write to the memory. Only at that point is a copy of that particular page of memory is made. Search for "copy on write" for more details. – kaylum May 28 '16 at 06:48
  • Thanks a lot! If this is a duplicate, I can close this question, if not, can you please add this as an answer? – sahil shekhawat May 28 '16 at 06:51
  • The manual says that `fork` creates a "child process". Please look up what a child process is. HTH. – babon May 28 '16 at 08:19
  • @cunev Please stop being rude and actually read the question. HTH HAND. – user253751 May 28 '16 at 10:18
  • 1
    The linked answer here does not answer the question. The linked answer is HOW. The poster's question is WHY. Of course, if you post operating system questions with the "C" tag, that's what you're going to get. – user3344003 May 28 '16 at 15:05

0 Answers0