我正在使用此函数调用clone()
clone (fun, (char*)stack + 0x500000, SIGCHLD | CLONE_FILES | CLONE_FS, arg);
fun是一个函数:int fun(void *), stack = malloc(0x500000),arg的类型为void *。
我想知道Invalid Argument perror的其他可能原因是什么。
我已经检查过堆栈不是NULL。
答案 0 :(得分:1)
man clone:
The child_stack argument specifies the location of the stack used by
the child process. Since the child and calling process may share mem‐
ory, it is not possible for the child process to execute in the same
stack as the calling process. The calling process must therefore set
up memory space for the child stack and pass a pointer to this space to
clone(). Stacks grow downward on all processors that run Linux (except
the HP PA processors), so child_stack usually points to the topmost
address of the memory space set up for the child stack.