在C中引用fork()的库

cip*_*her 6 c fork

什么是定义fork()的库.我正在学习使用fork().我发现标准I/O库:stdio.h 对于fork()来说已经足够了,但这并不适用于我的情况.

我使用gccCode::BlocksWindows 8 Pro

我的代码是:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<malloc.h>
#include <time.h>

int main(void)
{

    pid_t process;
    process = fork();

    if(process< 0)
    {
        printf("fork failed");
    }
    if(process > 0)
    {
        printf("\nParent Process Executed");
    }

    if(process == 0)
    {
        printf("\nChild Process Executed");
    }
    return 0 ;
}
Run Code Online (Sandbox Code Playgroud)

我得到的确切错误是:

useoffork.o:useoffork.c :(.text + 0xf):未定义引用`fork'

iab*_*der 5

C 标准库 (glibc) 实现了fork()最终调用 UNIX/Linux 特定的系统调用来创建进程,在 Windows 上,您应该使用 winapi,请参阅MSDNCreateProcess()中的此示例。

注意:Cygwinfork()只是一个包装器,CreateProcess()请参阅How is fork() Implemented?