Question

I am using the clone feature in linux c.

However, I encountered the error CLONE_VM undeclared (first use in this function) when I tried to compile my code.

I went to google for solutions and one of the site mentioned that #include <sched.h> must be included inside the code. I have already included #include <sched.h> in my code but the compilation error still persists.

Any help? :)

int c = clone(child,p+STACKSIZE-1,CLONE_VM|SIGCHLD,NULL) ;
Was it helpful?

Solution

Add the following lines to the beginning of your code

   #define _GNU_SOURCE             /* See feature_test_macros(7) */
   #include <sched.h>

You could find out which header files and/or macros are needed by

  • man 2 syscall_name
  • man 3 library_function_name

By the way, the implication of _GNU_SOURCE and more could be find out by man 7 feature_test_macros.

OTHER TIPS

sometime including #include <sched.h> will not work, so point sched.h file from linux. i.e. #include <linux/sched.h>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top