Thread: memory layout problem

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    50

    memory layout problem

    now imagine i have a program running

    let the name of this process be process A

    the following will be found in this process memory region

    Process A's data and code

    files_struct for process A

    file structure for stdin
    file structure for stdout
    file structure for stderr

    Now if process A calls fork and crates another process B

    which of the above are found inside process B's memory region

    Please help.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    which of the above are found inside process B's memory region
    None of it (or all of it, depending on your perspective). Process B will be an exact copy of process A's memory at the point of the fork. Exactly like this:

    Code:
    int a = 12, b;
    b = a;
    a and b do not share any memory, but they do have the exact same content.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    50
    after the fork code if process B has code which is different from that of A

    then will process B have it's own code and data segment

    and files_struct for process B

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Yes. Presuming differences in the subsequent code, they will diverge.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    50
    is there a good tutorial (Or a book that explains all of the above ) that shows me what happens to the memory layout when you make a pipe between processes and when you redirect input using dup system call.


    Please help.

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I doubt it, since nothing beyond the obvious happens. However, I do not really know much about the nitty gritty of segmentation other than that it is the responsibility of the compiler and the operating system.

    Why are you curious about this?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with custom dynamic memory allocation routines
    By BLauritson in forum C++ Programming
    Replies: 12
    Last Post: 03-11-2010, 07:26 AM
  2. Replies: 10
    Last Post: 09-22-2009, 11:38 AM
  3. Memory problem - malloc, pointers and vector
    By DrSnuggles in forum C++ Programming
    Replies: 18
    Last Post: 08-14-2009, 10:28 AM
  4. Problem with atl memory cleaning
    By Mariam1989 in forum Windows Programming
    Replies: 1
    Last Post: 11-11-2008, 12:35 PM
  5. Memory Problem - I think...
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 10-24-2001, 12:14 PM