【问题标题】:Invalid Argument error when using clone()使用 clone() 时出现无效参数错误
【发布时间】:2016-08-18 05:25:03
【问题描述】:

我正在使用这个函数调用 clone()

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

其中 fun 是一个函数:int fun(void*), stack = malloc (0x500000), arg 是 void* 类型。

我想知道无效参数错误的其他一些可能原因。

我已检查堆栈不为 NULL。

【问题讨论】:

  • 你检查过那个堆栈吗!= NULL ?
  • perror() 的“无效参数”输出与宏 EINVAL 对应的错误号相同。您是否阅读过clone() 的手册页?它列举了此代码的大量原因,但其中大多数与特定的错误标志组合有关。一个不是 child_stack 参数为零(NULL)。请注意,malloc() 在失败时返回 NULL
  • @socketpair 我检查了堆栈不为 NULL。

标签: c linux


【解决方案1】:

克隆人:

  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.

【讨论】:

    猜你喜欢
    • 2018-07-05
    • 1970-01-01
    • 2012-08-28
    • 2020-06-30
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    • 2012-10-21
    • 1970-01-01
    相关资源
    最近更新 更多