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

  • SEARCH
  • Home
  • 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 7643737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:31:13+00:00 2026-05-31T09:31:13+00:00

i am new to fork(),I read everywhere that when a fork() is called an

  • 0

i am new to “fork()”,I read everywhere that when a fork() is called an exact copy of current (calling) process is started.Now when I run following code ,there should be two different processes, having two different memory locations assigned to their vars and functions.

#include<stdio.h>
int i=10;
int pid;
 int main(){
  if((pid=fork())==0){
    i++;//somewhere I read that separate memory space for child is created when write is needed
    printf("parent address= %p\n",&i);// this should return the address from parent's memory space
  }else{
    i++;
    i++;
    printf("child address= %p\n",&i);// this should return the address of child's memory space 
  }
  wait(0);
  return(0);
 }
Why The output looks like:: 
child address::804a01c 
parent address::804a01c

Why both the address are the same for parent as well as child?

  • 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-31T09:31:14+00:00Added an answer on May 31, 2026 at 9:31 am

    having two different memory locations assigned to their vars and functions.

    Nope; Linux implements virtual memory, meaning that each process has its own complete address space. As a result, after a fork, both processes see the same addresses for their copies of in-memory objects.

    (As an aside: VM also causes code to be shared between the process in physical memory, and all data will only be copied-on-write.)

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

Sidebar

Related Questions

I read that node.js is single-threaded, so it doesn't fork a new process or
I have a program that fork() s a new process and then overwrites that
I'm developing a new gem (fork of nifty-generators). Right now my deployment consists on
A new process is created by fork/exec. Exec sets up the command line arguments
I read about the implementation of the Fork/Join framework that was introduced in Java
Can I initialize an IOLoop.instance and than fork new processes, which uses IOLoop.instance()? Something
I'm new to programming with linux and I was trying to understand how fork()
i am new to python. I am running the following code and it is
I'm new to c language and Linux. I have a problem related to fork(),getpid()and
I've read in various FAQs that git doesn't explicitly track renames/moves, preferring to look

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.