POSIX fork() itself will not (significantly) increase overall memory usage. If the parent uses 1GiB of memory and fork()s, the child will use the same 1GiB worth of pages in the operating system. If you go ahead and change any part of that memory in the child or parent, the operating system will make a copy of the affected page(s) of virtual memory.
This is known as copy-on-write (CoW) memory.
In your example code (which differs in an important way from your question about fork()), you exec another system command via backticks, which actually invokes a new shell and starts a fresh process from that shell rather than directly from your program. The implied exec() here essentially creates a new process image. In this case the OS has nothing to copy, and hence will not be able to take advantage of CoW and will be forced to allocate fresh pages for all of the runtime memory you request, because your program asks it to. In other words, if the memory has already been allocated and initialized pre-fork(), it will remain so post-fork(), in both the child and parent process.
None of this is at all new or Perl-specific, by the way, so reading up on the underlying fork(2) and exec(3) manual pages on any POSIX system would probably provide some useful background.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||