Memory allocated to the parent and the child processes

Each process is given a memory space like so :
rfdfgdf
When a process creates another process, the child process is given a memory space of its own too, but where? is it inside the memory space allocated to the parent or outside it? and if it's inside the parent's memory space, does it mean that the child shares a part (or the whole) of the parent's memory space with the parent?

Replies

  • Nayan Goenka
    Nayan Goenka
    When your child process was defined, it was already allocated some memory while compiling the code for the first time. So that comes into role. However if a process invokes another one, and in a loop, that is multiple times, then it will check if the child process is independent or dependent. If the child process is actually another module, it will have its private working like other processes. But if it is completely dependent on your main process, then it will acquire memory within the boundary or stack of main process and register itself as primary allocated memory for main process. So it all depends on type of process for which it takes corresponding memory location.
  • rukawa
    rukawa
    Nayan Goenka
    When your child process was defined, it was already allocated some memory while compiling the code for the first time. So that comes into role. However if a process invokes another one, and in a loop, that is multiple times, then it will check if the child process is independent or dependent. If the child process is actually another module, it will have its private working like other processes. But if it is completely dependent on your main process, then it will acquire memory within the boundary or stack of main process and register itself as primary allocated memory for main process. So it all depends on type of process for which it takes corresponding memory location.

    Say for example the child is completely dependant on the parent (I think this means that the child does exactly the same work as the parent), does it mean that all its memory space will be within the boundaries of the parent's memory space?
  • Nayan Goenka
    Nayan Goenka
    rukawa
    Say for example the child is completely dependant on the parent (I think this means that the child does exactly the same work as the parent), does it mean that all its memory space will be within the boundaries of the parent's memory space?


    Yes. While compiling itself the main program will have reserved some space for the child program. And apart from that, you cannot put a program into infinite loop. So there is some boundary. And the main program analyses it and allocated proper amount of memory beforehand. If the program uses linked list, then it is simpler. It goes into any memory block alloted and the main program keeps track of its pointer.
  • Anoop Kumar
    Anoop Kumar
    does it mean that all its memory space will be within the boundaries of the parent's memory space?
    YES.
    I don't think it is a complex scenario.
    When a process needs more memory (or say created a child process), system allocate this memory dynamically.
    If you watch closely running browser for long time it is consuming more and more memory. while webpages you are Login in are completely untouched by other browser sessions.

    One more basic example is Arraylist which grows dynamically when you add more elements.
  • rukawa
    rukawa
    Thank you for your answers. Say now the child is independent from the parent, like the shell for example, it creates a process in order to execute the command typed by the user and prints the output when the child is done. Does the child in this case have a bit of memory space that is out of the boundaries of the parent's own memory space?
    And what happens if the parent dies and leaves an orphan?
  • Nayan Goenka
    Nayan Goenka
    If the parent dies and leaves the child an orphan, You child program is useless. It wont run itself since it is invoked by the parent program. So no question of memory usage.

    All memory of a program executing has a confined block of usage. In case of iterative programs and functions, the main program maintains a record of the pointer. So nothing escapes.

You are reading an archived discussion.

Related Posts

During our development of a table top sterilizer, I wanted to use a MEMS pressure sensor. This sensor was key to the satisfactory functioning of the whole device. The entire...
This robot is purely an engineering marvel By just rotating at a speed of 500 Rpm the task it promises to accomplish is simply outstanding. This robot can clean gutters...
AS I had posted in Audi A8 feed this is the near future lighting system from the AutoGiant Audi coming up with the new Matrix LED lighting system.It is a...
Conky is known for making the desktop looks beautiful. Check mine : ​ ​However, for amateur users it was bit complex to add scripts in /home directory & adding conky...
Hey guys, I m feeling good to inform here that I m trying to make a windows form application which will be a dedicated application to surf on CrazyEngineers.com. This...