我正在尝试运行我的第一个“进程”程序,但出现以下错误:
./fork.c: line 4: syntax error near unexpected token `('
./fork.c: line 4: `int main()'
Run Code Online (Sandbox Code Playgroud)
我很确定代码是正确的:
#include <sys/types.h>
#include <stdio.h>
int main() {
pid_t pid;
printf("Hello fork()\n");
switch(pid=fork()) {
case -1: printf("Error by fork().....\n"); exit(0);
case 0: printf("I'm the child process \n"); break;
default: printf("I'm the dad \n"); break;
}
exit(0);
}
Run Code Online (Sandbox Code Playgroud)
怎么了?