我试图在以--privileged开头的Docker容器中运行以下程序:

root@1df00aaf673d:~# cat > sysconf_test.c
#include <unistd.h>
#include <errno.h>
#include <stdio.h>

int main() {
    long n = sysconf(_SC_CHILD_MAX);
    printf("%ld %d\n", n, errno);
    return 0;
}
root@1df00aaf673d:~# gcc sysconf_test.c ; ./a.out
-1 0

the sysconf man page开头,“如果名称对应于最大或最小限制,并且该限制不确定,则返回-1且errno不变。”是否可以通过将选项传递给docker run命令来确定它?

最佳答案

我将回答我自己的问题:尽管手册页没有将其拼写出来,但sysconf似乎返回-1L为“unlimited”:

[root@llg00amn ~]# ulimit -u
120996
[root@llg00amn ~]# docker run -ti debian /bin/bash
root@5668a7acb957:/# ulimit -u
unlimited

ulimit设置为实际数字后,程序可以正常运行并返回正确的结果。

关于linux - 如何在Docker容器中获取最大子进程数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46100247/

10-09 21:13