Search code examples
clinuxclone

CLONE_VM undeclared (first use in this function)


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) ;

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.