Linux下一个进程可以创建的最大线程数是多少?
如何(如果可能的话)修改这个值?
Linux下一个进程可以创建的最大线程数是多少?
如何(如果可能的话)修改这个值?
当前回答
使用nbio 非阻塞i / o 库之类的,如果你需要更多的线程来做I/O调用那个块
其他回答
如果使用Suse操作系统,则需要选择其中一种方法
https://www.suse.com/support/kb/doc/?id=000015901
全球性的,
/etc/systemd/system.conf
DefaultTasksMax=Value
对于特定的ssh服务
/etc/systemd/system/sshd.service.d/override.conf
TasksMax=Value
Yes, to increase the threads number you need to increase the virtual memory or decrease the stack size. In Raspberry Pi I didn’t find a way to increase the virtual memory, if a decrease the stack size from default 8MB to 1MB It is possibly get more than 1000 threads per process but decrease the stack size with the “ulimit -s” command make this for all threads. So, my solution was use “pthread_t” instance “thread class” because the pthread_t let me set the stack size per each thread. Finally, I am available to archive more than 1000 threads per process in Raspberry Pi each one with 1MB of stack.
要检索它:
cat /proc/sys/kernel/threads-max
设置方法:
echo 123456789 | sudo tee -a /proc/sys/kernel/threads-max
123456789 = #线程
对于现在看到这个的人来说,在systemd系统上(在我的情况下,特别是Ubuntu 16.04),还有另一个由cgroup pid强制执行的限制。max参数。
默认设置为12288,可以在/etc/systemd/logind.conf中覆盖
其他建议仍然适用,包括pids_max、threads-max、max_maps_count、ulimits等。
取决于您的系统,只需编写一个示例程序[通过在循环中创建进程],并使用ps axo pid,ppid,rss,vsz,nlwp,cmd检查。当它不能再创建线程时,检查nlwp计数[nlwp是线程数],瞧,你得到了你的傻瓜证明的答案,而不是通过书籍