当我运行下面的代码时,它给了我一个奇怪的输出
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main (int argc, char ** argv)
{
int pid1, pid2;
if ((pid1=fork())<0)
{
printf("Error\n");
exit(1);
}
if (pid1=!0)
printf("A\n");
printf("B %d", getpid());
if ((pid2=fork())<0)
{
printf("Error\n");
exit(2);
}
printf("A\n");
return 0;
}
应该是这样的
A
A
BA
BA
A
A
但是输出是
A
A
BA
BA
BA
BA
我不知道为什么。任何建议或解释请。