怎么查找缺少什么资源导致的pthread_create返回EAGAIN
我们在测试时发现日志中创建线程报错:Resource temporarily unavailable(errno = 11, EAGAIN)但是用limit查看资源很充足,物理内存2T
[####]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 16543461
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 500000
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 42768
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
我的问题是:怎么查找是什么资源导致某次调用失败。
我写了一个简单的测试程序,一直创建线程,然后用systemstap检测,检测脚本是probe kernel.function("SyS_clone").return
{
if ($return != 0)
{
print_backtrace();
exit();
}
}得出的结果是:
Returning from:0xffffffff81066bd0 : SyS_clone+0x0/0x20
Returning to:0xffffffff8172c9c9 : stub_clone+0x69/0x90
可惜什么都看不懂,请大侠们指点一下。
测试程序:#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
#include <pthread.h>
#include <iostream>
#include <string>
using namespace std;
void *func(void *)
{
while (true)
sleep(10);
return NULL;
}
int main(int argc, char **argv)
{
pthread_t tid;
int ret = 0;
int count = 0;
while (!ret)
{
ret = pthread_create(&tid, NULL, func, NULL);
count ++;
}
count--;
printf("max thread is : %d, errno is %d\n", count, ret);
return EXIT_SUCCESS;
} 不知道是不是address space用完了(每个线程需要一个独立的stack)?
测试得到的count(建议换成long)是多少? nswcfd 发表于 2016-02-26 17:45 static/image/common/back.gif
不知道是不是address space用完了(每个线程需要一个独立的stack)?
测试得到的count(建议换成long)是多 ...
是的,每个线程都需要自己独立的stack,要不然不同线程中的函数执行就会混乱
我自己的虚拟机上测试大概是3W多(root)和1.5W(普通用户)
页:
[1]