S
sophia.agnes
Dear all,
consider the following program
#include<stdio.h>
#include<unistd.h>
main()
{
int pid,*i,j;
i = &j;
*i= 10;
pid = fork();
if(pid == 0)
{
printf("\n address of i = %p",i);
printf("\n initially i value in child = %d",*i);
*i = *i +10;
printf("\n after incrementation i value in child = %d",*i);
puts("Child terminated....");
}
else
{
wait( (int*) 0);
printf("\n address of i = %p",i);
printf("\n value of i in parent = %d",*i);
}
i am getting o/p as:-
address of i = 0xbfe6c01c
initially i value in child = 10
after incrementation i value in child = 20
Child terminated....
address of i = 0xbfe6c01c
value of i in parent = 10
the address of i is same in both parent and child process but
the change made in child process is not reflected in the
parent process why ?
consider the following program
#include<stdio.h>
#include<unistd.h>
main()
{
int pid,*i,j;
i = &j;
*i= 10;
pid = fork();
if(pid == 0)
{
printf("\n address of i = %p",i);
printf("\n initially i value in child = %d",*i);
*i = *i +10;
printf("\n after incrementation i value in child = %d",*i);
puts("Child terminated....");
}
else
{
wait( (int*) 0);
printf("\n address of i = %p",i);
printf("\n value of i in parent = %d",*i);
}
i am getting o/p as:-
address of i = 0xbfe6c01c
initially i value in child = 10
after incrementation i value in child = 20
Child terminated....
address of i = 0xbfe6c01c
value of i in parent = 10
the address of i is same in both parent and child process but
the change made in child process is not reflected in the
parent process why ?