Themuppeteer
Programmer
Can anyone explain what happens when I do this?
int* m=new int;
*m=1;
if(fork())
{
*m=0;
}
else
{
while( (*m)>0)
cout<<"looping\n";
}
I tried this and this is what I found:
in the first process,*m will be 0 while in the second
process, *m will stay 1.
If you do cout<<m<<endl; in both of them,you will see that the address is the same.
Are the 2 processes perhaps in different segmens in memory ?
What happens?
Thnx.
Greetz,
The Muppeteer.
themuppeteer@hotmail.com
Don't eat yellow snow...
int* m=new int;
*m=1;
if(fork())
{
*m=0;
}
else
{
while( (*m)>0)
cout<<"looping\n";
}
I tried this and this is what I found:
in the first process,*m will be 0 while in the second
process, *m will stay 1.
If you do cout<<m<<endl; in both of them,you will see that the address is the same.
Are the 2 processes perhaps in different segmens in memory ?
What happens?
Thnx.
Greetz,
The Muppeteer.
themuppeteer@hotmail.com
Don't eat yellow snow...