Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3623758
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:25:23+00:00 2026-05-18T23:25:23+00:00

I am confused about something. I have read that when a child is created

  • 0

I am confused about something. I have read that when a child is created by a parent process, the child gets a copy of its parent’s address space. What does it mean by copy?
If I use the code below, then it prints the same value for variable ‘a’ which is on the heap in both tthe child and parent. So what is happening here?

int main ()
{
        pid_t pid;
        int *a = (int *)malloc(4);
        printf ("heap pointer %p\n", a);
        pid = fork();
        if (pid < 0) {
                fprintf (stderr, "Fork Failed");
                exit(-1);
        }
        else if (pid == 0) {
                printf ("Child\n");
                printf ("in child heap pointer %p\n", a);
        }
        else {

                wait (NULL);
                printf ("Child Complete\n");
                printf ("in parent heap pointer %p\n", a);
                exit(0);
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:25:24+00:00Added an answer on May 18, 2026 at 11:25 pm

    The child gets an exact copy of the parents address space, which in many cases is likely to be laid out in the same format as the parent address space. I have to point out that each one will have it’s own virtual address space for its memory, such that each could have the same data at the same address, yet in different address spaces. Also, Linux uses copy on write when creating child processes. This means that the parent and child will share the parent address space until one of them does a write, at which point the memory will be physically copied to the child. This eliminates unneeded copies when execing a new process. Since you’re just going to overwrite the memory with a new executable, why bother copying it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am really confused about object relationships! I have two classes Person and Address.
I'm confused about something in the SSL renewal process using WHM/cPanel for an existing
I have read about POCO (Plain old CLR (or C#) object) here ,and confused
I have read something about them via official doc and some posts, but I'm
I'm a bit confused about the memory leaks in PHP. I've read that PHP
I'm using rails 3.2.3 and have a questions about queries. I've read that it
I'm a newbie to Java and I'm confused about something: In the simple hello
I'm a bit confused about the right way to write a code. I read
I'm really confused about this, tried to read a lot about diagrams but I
I have a question about writing your own init methods in objective-c. I've read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.