Find the answer to your Linux question:
Results 1 to 3 of 3
Hello, I have deamon-like perli script which calls other shell scripts/programs. In top I see that for each such call new processes is created with parent pid equal to perl ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2012
    Posts
    1

    Memory management for child processes


    Hello,

    I have deamon-like perli script which calls other shell scripts/programs. In top I see that for each such call new processes is created with parent pid equal to perl script pid. I also see that child process has almost same amount of VIRT and RES memory in top as parent process. For example:

    PID PPID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    3317 1 root 18 0 1631m 700m 3440 S 16.1 8.9 73:51.95 bmc_hm.pl
    18607 3317 root 19 0 1631m 696m 204 R 0.0 8.9 0:00.00 bmc_hm.pl


    Does this means that Linux will need all this memory (child + parent process) or this memory is shared in some way?

    Thanks,
    Michal

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by mgorniew View Post
    Hello,

    I have deamon-like perli script which calls other shell scripts/programs. In top I see that for each such call new processes is created with parent pid equal to perl script pid. I also see that child process has almost same amount of VIRT and RES memory in top as parent process. For example:

    PID PPID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    3317 1 root 18 0 1631m 700m 3440 S 16.1 8.9 73:51.95 bmc_hm.pl
    18607 3317 root 19 0 1631m 696m 204 R 0.0 8.9 0:00.00 bmc_hm.pl


    Does this means that Linux will need all this memory (child + parent process) or this memory is shared in some way?

    Thanks,
    Michal
    If they're using shared libraries, it is likely that they are then sharing memory. The memory utilization is not well represented by the ps output. Try the pmap program. Here is an example showing the memory map of the bash process being used by my current login shell:

    Code:
    # pmap -d $$
    3791:   -bash
    Address   Kbytes Mode  Offset           Device    Mapping
    08047000     580 r-x-- 0000000000000000 003:00003 bash
    080d8000      24 rw--- 0000000000090000 003:00003 bash
    080de000     284 rw--- 00000000080de000 000:00000   [ anon ]
    423b9000      84 r-x-- 0000000000000000 003:00003 ld-2.3.4.so
    423ce000       4 r---- 0000000000015000 003:00003 ld-2.3.4.so
    423cf000       4 rw--- 0000000000016000 003:00003 ld-2.3.4.so
    423d2000    1168 r-x-- 0000000000000000 003:00003 libc-2.3.4.so
    424f6000       4 r---- 0000000000124000 003:00003 libc-2.3.4.so
    424f7000      12 rw--- 0000000000125000 003:00003 libc-2.3.4.so
    424fa000       8 rw--- 00000000424fa000 000:00000   [ anon ]
    42523000       8 r-x-- 0000000000000000 003:00003 libdl-2.3.4.so
    42525000       8 rw--- 0000000000001000 003:00003 libdl-2.3.4.so
    426e4000      12 r-x-- 0000000000000000 003:00003 libtermcap.so.2.0.8
    426e7000       4 rw--- 0000000000002000 003:00003 libtermcap.so.2.0.8
    b7e70000       4 r-x-- 0000000000000000 003:00005 ISO8859-1.so
    b7e71000       8 rw--- 0000000000000000 003:00005 ISO8859-1.so
    b7e73000      24 r--s- 0000000000000000 003:00005 gconv-modules.cache
    b7e79000       4 r---- 0000000002b14000 003:00005 locale-archive
    b7e7a000     200 r---- 0000000000d84000 003:00005 locale-archive
    b7eac000    2048 r---- 0000000000000000 003:00005 locale-archive
    b80ac000      36 r-x-- 0000000000000000 003:00003 libnss_files-2.3.4.so
    b80b5000       8 rw--- 0000000000008000 003:00003 libnss_files-2.3.4.so
    b80b7000       8 rw--- 00000000b80b7000 000:00000   [ anon ]
    b80d2000       8 rw--- 00000000b80d2000 000:00000   [ anon ]
    bf9be000      84 rw--- 00000000bffeb000 000:00000   [ stack ]
    ffffe000       4 r-x-- 0000000000000000 000:00000   [ anon ]
    mapped: 4640K    writeable/private: 460K    shared: 24K
    Read the man page ("man pmap") for full usage. Here is a more thorough write-up of pmap:

    Virtual Threads: Understanding memory usage on Linux

  3. #3
    Linux Newbie Syndacate's Avatar
    Join Date
    May 2012
    Location
    Hell..no literally, this state is hell..
    Posts
    192
    If it's any similar to the way C uses POSIX child processes (which I'm assuming is what Perl will use at its core) then yes, they share memory.

    Children processes have access to all the memory that the parent had up to the point that the fork was created and the child process was spawned. The children processes also have access to any pipes, buffers, etc. that are open to the parent process. So when you open a child process, all the variables on the stack get copied from the parent process over to the child process. The child process from there has its own stack. Any variables in static/constant memory are shared between the two, and any memory that was allocated by the parent process on the heap prior to the fork is accessible...though I can't remember if that memory is copied or shared (I believe it's copied, though I'm not sure).

    So yeah, they utilize much of the same memory, but something that the child allocates isn't accessible to the parent. Now if this is managed with a separate pool or they're fenced within one pool I'm not sure.

    Hope that helps...hope it's accurate...been awhile since I took an OS course...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •