【问题标题】:system: Resource temporarily unavailable, which one?系统:资源暂时不可用,哪个?
【发布时间】:2022-10-24 09:23:23
【问题描述】:

我搜索答案,到目前为止还没有找到一个明确的答案。

我正在测试启动许多调用“system()”的线程,如下所示。

for (int i = 0; i < 3000; ++i)
  pthread_create(&thread[i], NULL, thread_func, NULL);

for (int i = 0; i < 3000; ++i)
  pthread_join(thread[i], NULL);

...
void* thread_func(void* arg)
{
  if (system('test.sh') == -1)
  {
    perror("system");
    exit(1);
  }
  pthread_exit(NULL);
}

测试.sh

#!/bin/bash

sleep 100

当我运行程序时,它会在某个时候显示。

system: Resource temporarily unavailable

有没有办法知道哪个资源?我修复了最大进程问题,所以我认为这可能是由于其他原因。

【问题讨论】:

  • 更新limits.conf 后是否注销并重新登录?
  • 是的,我什至尝试重新启动仍然无法正常工作
  • OK,编辑“limits.conf”的方法不行。答案here 有效。

标签: linux process fork child-process ulimit


【解决方案1】:

此错误表示系统库函数调用的某些系统调用返回了 EGAIN。最有可能是分叉调用,由于多种原因,它可能会因 EAGAIN 失败:

   EAGAIN A system-imposed limit on the number of threads was encountered.  There are a  num‐
          ber of limits that may trigger this error:

          *  the  RLIMIT_NPROC  soft  resource limit (set via setrlimit(2)), which limits the
             number of processes and threads for a real user ID, was reached;

          *  the  kernel's  system-wide  limit  on  the  number  of  processes  and  threads,
             /proc/sys/kernel/threads-max, was reached (see proc(5));

          *  the maximum number of PIDs, /proc/sys/kernel/pid_max, was reached (see proc(5));
             or

          *  the PID limit (pids.max) imposed by the  cgroup  "process  number"  (PIDs)  con‐
             troller was reached.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 2018-08-04
    • 2021-05-07
    • 2018-02-24
    • 2016-01-25
    • 2012-04-25
    • 2018-03-11
    相关资源
    最近更新 更多