无效的参数错误使用的clone()

问题描述:

当我使用这个函数调用的clone()无效的参数错误使用的clone()

clone (fun, (char*)stack + 0x500000, SIGCHLD | CLONE_FILES | CLONE_FS, arg);

其中的乐趣是一个函数:int乐趣(void *的), 堆栈=的malloc(0x500000 ),而arg的类型是void *。

我想知道什么是无效的参数perror其他可能的原因。

我检查过的堆栈不是NULL。

+1

你检查堆栈!= NULL? – socketpair

+0

来自'perror()'的“无效参数”输出对应于宏EINVAL相同的错误编号。你读过'clone()'的手册页吗?它枚举了这个代码的很多原因,但其中大部分都与特定的错误标志组合有关。不是那个'child_stack'参数是零(NULL)。请注意,malloc()在失败时返回NULL。 –

+0

@socketpair我检查过的堆栈不是NULL。 – ballballbobo

人克隆:

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.