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?