linux - 如何知道当前进程数以及哪个进程派生了最多进程?

标签 linux shell process

fork: retry: Resource temporarily unavailable

我正在调查是哪个进程导致了这个问题,并且想知道这个机制是如何工作的。

#!/bin/bash
#test.sh
for i in `seq 1 13000`; do
        echo $i
        sleep 60&
done

在我运行这个脚本(./test.sh)之后,消息如下所示。

...
12265
12266
12267
12268
./test.sh: fork: retry: Resource temporarily unavailable
./test.sh: fork: retry: Resource temporarily unavailable
./test.sh: fork: retry: Resource temporarily unavailable
./test.sh: fork: retry: Resource temporarily unavailable
./test.sh: fork: Resource temporarily unavailable

ps -elf |wc 大约是 133xx 行。 ulimit -u 为 1030977。

fork: retry: Resource temporary unavailable 是否显示由于进程数达到 1030977?如果为真,我如何知道当前计数以及如何知道哪个进程 fork 了大多数进程?

最佳答案

在/etc/security/limits.conf 中为用户或所有用户增加“nproc”参数的值

示例:

@student        hard    nproc           2048

检查:nproc 值可以根据需要增加。 这里的模板是:

    <domain>        <type>  <item>  <value>
    "@student" -- Replace it with user for which limit has to be applied. For root user, username is "root"
    "hard" for enforcing hard limits
    "nproc" for max number of processes
    Last column is value.

要查找哪个进程正在派生最多的进程,请使用命令“pstree”。为了确定计数,请使用以下方法。

$ps | gawk '{count[$NF]++}END{for(j in count) print ""count[j]":",j}'|sort -rn|head -n 5

示例:

#ps | gawk '{count[$NF]++}END{for(j in count) print ""count[j]":",j}'|sort -rn|head -n 5
3: bash
1: sudo
1: sort
1: ps
1: CMD

关于linux - 如何知道当前进程数以及哪个进程派生了最多进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50753061/

相关文章:

c++ - 使用互斥量调节两个进程之间的 IPC

python - 让子进程保持事件状态并继续向其发出命令? Python

linux - 现有目录的SVN设置

linux - 基于 Web 浏览器的 Xpra 客户端?

linux - 在 Linux 上,如何使用 POSIX shell 禁用鼠标一秒钟,而不是等待第二个并立即做一些工作?

shell - 在awk中,如何在打印$2时忽略错误行,但错误行中不存在$2

c# - 尝试以编程方式运行容器时从 Docker 退出代码 125

Linux 和 Mac 中的 C#

linux - 仅主页从 http 到 https 的重定向规则

multithreading - 如何在 Perl 中列出和终止线程/进程而不使用外部命令?