我正在尝试在内部使用克隆的 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;
}
我得到了错误:
dell@ubuntu:~$ g++ n.cpp -on n.cpp: In function 'int main()': n.cpp:40:62: error: invalid conversion from 'int ( )()' to 'int ( ) (void*)' [-fpermissive] /usr/include/x86_64-linux-gnu/bits/sched.h:83:12: 错误:初始化参数 1 的 'int clone(int ( )(void ), void*, int, void*, ...)' [-fpermissive] dell@ubuntu:~$