在C中引用fork()的库
什么是定义fork()的库。 我正在学习使用fork()。 我发现标准I / O库: stdio.h
足以让fork()工作,但这不适用于我的情况。
我在Windows 8 Pro
上的Code::Blocks
使用gcc
我的代码是:
#include #include #include #include #include int main(void) { pid_t process; process = fork(); if(process 0) { printf("\nParent Process Executed"); } if(process == 0) { printf("\nChild Process Executed"); } return 0 ; }
我得到的确切错误是:
useoffork.o:useoffork.c :(。text + 0xf):未定义引用`fork’
C标准库(glibc)实现fork()
,它最终调用UNIX / Linux特定的系统调用来创建进程,在Windows上,你应该使用winapi CreateProcess()
在MSDN中查看这个例子。
注意:Cygwin fork()
只是CreateProcess()
的包装器,请参见如何实现fork()?
我在Windows 8 Pro上的Code :: Blocks中使用gcc
你没有在Windows上使用fork
。 你可以使用cygwin或类似的东西。