CLONE_VM未声明(首次使用此功能)

Law*_*ong 4 c linux clone

我在linux c中使用克隆功能.

但是,当我尝试编译代码时,我遇到了错误CLONE_VM未声明(在此函数中首次使用).

我去google寻求解决方案,其中一个提到的网站#include <sched.h>必须包含在代码中.我已经包含#include <sched.h>在我的代码中,但编译错误仍然存​​在.

有帮助吗?:)

int c = clone(child,p+STACKSIZE-1,CLONE_VM|SIGCHLD,NULL) ;
Run Code Online (Sandbox Code Playgroud)

Lee*_*hem 7

将以下行添加到代码的开头

   #define _GNU_SOURCE             /* See feature_test_macros(7) */
   #include <sched.h>
Run Code Online (Sandbox Code Playgroud)

您可以找出需要哪些头文件和/或宏

  • man 2 syscall_name
  • man 3 library_function_name

顺便说一下,_GNU_SOURCE可以找到更多的含义man 7 feature_test_macros.