〜fork()函数调用与简单的fork()有何不同..我尝试了以下代码..在这个甚至孩子正在执行父部分的代码。
main()
{
pid_t pid = ~fork();
int a = 2;
int *ptr = (int*)malloc(sizeof(int));
*ptr = 2;
if(pid == 0)
{
a = a + 3;
*ptr = *ptr + 2;
printf("value at a and ptr in child process : %d and %d\n" , a , *ptr);
printf("address a and ptr in child process : %p and %p\n" , &a , ptr);
}
else
{
printf("value at a and ptr in parent process : %d and %d\n" , a , *ptr);
printf("address a and ptr in parent process : %p and %p\n" , &a , ptr);
}
}