6

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) ;
Lee Duhem
  • 14,695
  • 3
  • 29
  • 47
Lawrence Wong
  • 1,129
  • 4
  • 24
  • 40

2 Answers2

12

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.

Lee Duhem
  • 14,695
  • 3
  • 29
  • 47
1

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

  • For me it worked when I put "#define _GNU_SOURCE" then "#include " on *top* of the source code (above all other #includes). – ZeZNiQ Oct 04 '19 at 16:39