这个程序不适用于gcc ......并且给出了一个链接器错误..对fork的未定义引用...
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
int a=10;
if (a==10 && fork())
printf("hello");
else
printf("world");
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
您正在使用的事实system("pause")(顺便说一句,当您可以简单地使用时getchar())这让我相信您在Windows上运行.除非您使用像CygWin这样的仿真层,fork否则在该平台上不可用.
To be honest, I'm not sure how you even managed to compile since Windows doesn't generally have unistd.h either unless perhaps you've installed SFU or MinGW (which, despite having unistd.h to ease the task of compiling code (less conditional compilation), does not provide more functionality than what you get with Windows).