我想运行C代码中使用克隆里面的C代码,我得到了一个错误,我无法解决它,任何人在C++之前使用克隆,并可以提供帮助。错误克隆系统调用在c + +中的句子
我的代码:
int variable, fd;
using namespace std ;
int do_something() {
variable = 42;cout << "sana" << endl ;
close(fd);
_exit(0);
}
int main() {
void **child_stack;
char tempch;
variable = 9;
fd = open("test.file", O_RDONLY);
child_stack = (void **) malloc(16384);
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);
if (read(fd, &tempch, 1) < 1) {
perror("File Read Error");
exit(1);
}
printf("We could read from the file\n");
return 0;
}
和我得到了错误:
戴尔@ Ubuntu的:〜$ G ++ n.cpp -on n.cpp:在函数 '廉政的main()': (')'(')'(')'(void *)'[-fpermissive] /usr/include/x86_64-linux-gnu/bits无效从'int()()'转换为'int() /sched.h:83:12:错误:初始化'int clone(int()(void),void *,int,无效*,...)” [-fpermissive] 戴尔@ Ubuntu的:〜$
我相信你对child_stack **的使用导致了SEGFAULT。虽然不知道clone()的实现和期望,但我无能为力。 – drescherjm
谢谢你的评论:) – sana
我刚刚查找了clone()的原型。看起来你应该在两个地方用**替换**。 – drescherjm