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 6732639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:40:28+00:00 2026-05-26T10:40:28+00:00

Can a child process access(read and write) parent process’s heap address space? Following is

  • 0

Can a child process access(read and write) parent process’s heap address space?
Following is the program i tried at http://www.ideone.com/R5vDT which is running successfully:

int main(){
        int *p = (int*)malloc(sizeof(int));
        if(fork()){
        //parent process
                *p = 25;//Write
                printf("Parent %d: %d %p\n", getpid(), *p, p);//Read
        }else{
        //child process
                *p = 15;//write
                printf("Child %d: %d %p\n", getpid(), *p, p);//read
        }
        return 0;
}     

Output is:

Parent 30597: 25 0x9781008
Child 30600: 15 0x9781008

I have read about C-O-W (copy on write) but addresses pointed by p are same even after write operation. Should NOT the Operating System raise an exception because one process is accessing memory outside it’s address space?

  • 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-26T10:40:29+00:00Added an answer on May 26, 2026 at 10:40 am

    Well, the two processes have their own address spaces that to each of the process looks the same, even though they are not accessing the same memory. However, many operating systems implement something called copy-on-write, meaning that the memory isn’t copied at the time you call fork but rather when one of the processes modifies the memory. As long as no process is writing to the memory, they are reading from the same memory. When one of them tries to modify the memory, some type of exceptions is raised and the memory is copied so that they both have a private area of memory, inaccessible to any other process.

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

Sidebar

Related Questions

I have a parent and child process, and the parent can read output from
Can child process use the ptrace system call to trace its parent? Os is
I want to write a program, which will launch a child process. The child
In perl debugger I can use DB::get_fork_TTY() to debug both parent and child process
When creating a child process in C++ using Windows API, one can allow inheritance
On Windows I can do CreateProcess(..., CREATE_NEW_CONSOLE, ...) and my child process (which is
Question: How can I determine all processes in the child's Process Tree to kill
I have parent/child relationship set up via Node Reference. A Child record can have
My application has two node types: a parent node which can hold recursive child
Can I automatically validate complex child objects when validating a parent object and include

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.