【发布时间】:2015-08-20 03:03:27
【问题描述】:
我用 C 语言编写了这个基础的分叉程序。但是编译器向我发出错误。代码是
#include<stdio.h>
#include<sys/stat.h>
#include<ctype.h>
void childProcess(){
printf("From child process with process id %d\n", getpid());
}
void parentProcess(){
printf("Parent Process with id %d\n", getpid());
pid_t pid = fork();
if (pid == 0){
childProcess();
} else if (pid > 0){
printf("Parent spawned process %d\n", pid);
} else{
printf("Forking isn't supported!\n");
}
}
int main(){
parentProcess();
}
错误是
C:\Users\ADMINI~1\AppData\Local\Temp\ccORJc6N.o forking.c:(.text+0x3e): undefined reference to `fork'
【问题讨论】: