我想運行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