克隆导致分段错误
代码 :
#define STACKSIZE 16384
int variable ;
using namespace std ;
int do_something(void *) {
variable = 42;
return 0 ;
}
int main() {
void *child_stack;
variable = 9;
child_stack = (void *) malloc(STACKSIZE);
printf("The variable was %d\n", variable);
clone(do_something, child_stack,CLONE_VM|CLONE_FILES,NULL );
sleep(1);
printf("The variable is now %d\n", variable);
free(child_stack);
return 0;
}