Re: will system() waste memory?



Bin Chen <binary.chen@xxxxxxxxx> wrote:
Most call to system() is to run a brand new program but I want to know
if the parent run system() after allocated a large memory, will the
memory duplicated to the systemed program which is unnecessary?

If so, how can I do to avoid the wasted memory?

For this reason posix_spawn() has been introduced:

http://www.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html

See the discussion in the "Rationale" section.

You can assume system() uses the optimal implementation available on your
platform. system() might succeed in some cases where fork() + exec() would
fail.


--
Daniel
.



Relevant Pages

  • Re: Migrate pages from a ccNUMA node to another
    ... relatively stable memory working sets. ... > on the childs node for the child and parents node for the parent. ... we have beaten on the scheduler quite a bit and the "allocate ... > syscall you seem to be proposing, would be an addition to the ...
    (Linux-Kernel)
  • [patch -mm v2] mm: introduce oom_adj_child
    ... children that do not share memory with the parent. ... That change was necessary to fix an oom killer livelock which would occur ... of a vfork'd child prior to execvebefore the execution actually takes ...
    (Linux-Kernel)
  • Re: [RFC] libcg: design and plans
    ... > i.e. both B and C inherit/share their memory limit from their parent, ... In the create group API, specify the name of the group and the various ... If for example CPU is mounted at /cpu and Memory at /mem ... This kind of sharing has to be handled by the resource ...
    (Linux-Kernel)
  • Re: fork() children and share memory with them
    ... > children for every incoming connection. ... > communicate status information back to the parent, ... > Is there any way to make existing memory SHARED? ... if the amount of information you need to communicate is large or the number ...
    (comp.unix.programmer)
  • Re: What does the CLR do when you instantiate an object? - Continue
    ... > cast an object to one of its parent types then yes I'd agree with you. ... >child class in the memory, when I asked you whether you are confident to ... in the PARENT CONSTRUCTOR we have shown working examples ...
    (microsoft.public.dotnet.framework.clr)