脚本错误“fork:重试:资源暂时不可用”..会重试失败的行吗?

脚本错误“fork:重试:资源暂时不可用”..会重试失败的行吗?

我正在运行一个后台 ping 调用的 ping 脚本。

#!/bin/bash for ip in $(seq 100 210); do ping x.x.x.$ip -c1 |grep "bytes from" |cut -d " " -f4|cut -d ":" -f1 & done fork: retry: Resource temporarily unavailable如果我在循环迭代期间 收到错误,该迭代是否会不可逆转地失败,或者我的脚本会在资源可用时自动尝试重新运行?

答案1

操作系统无法自行重新启动失败的命令。但是,您可以在脚本中构建这样的机制。当fork失败时,返回-1,并且不会创建子进程。出现上述错误的原因是伊加恩。检查资源限制(ulimit 和内存)。下面的手册页中的相关部分——

RETURN VALUE
        On  success,  the  PID  of the child process is returned in  the parent, 
and 0 is returned in the child.  On failure, -1 is returned in
 the parent, no child process is created, and errno is set appropriately.

EAGAIN fork() cannot allocate sufficient memory to copy the parent's page tables and 
allocate a task structure for the child.

EAGAIN It was not possible to create a new process because the caller's RLIMIT_NPROC 
resource limit was  encountered.   To  exceed  this  limit,  the
process must have either the CAP_SYS_ADMIN or the CAP_SYS_RESOURCE capability.

相关内容