Hello,
running the following script on Linux ends up in an infinite loop:
#!/bin/ksh
ulimit -u 10
for (( i = 0; i < 10; i++ )); do
cat /dev/zero > /dev/null &
done
The shell seems to be spinning in xec.c:sh_fork() (line 2256 in my sources):
while(_sh_fork(parent=fork(),flags,jobid) < 0);
...and _sh_fork() returns always -1 in this situation because we have reached
RLIMIT_NPROC limit and fork returns always -1.
Here's my attempt to fix the problem -- give up if errno is EAGAIN, which is
the way e.g. bash seems to solve the situation.
Regards.
---
diff -up ksh-20080202/src/cmd/ksh93/sh/xec.c.eagain
ksh-20080202/src/cmd/ksh93/sh/xec.c ---
ksh-20080202/src/cmd/ksh93/sh/xec.c.eagain 2008-01-25
20:35:25.000000000 +0100 +++ ksh-20080202/src/cmd/ksh93/sh/xec.c
2008-06-25 10:21:02.000000000 +0200 @@ -2249,7 +2249,13 @@ pid_t sh_fork(int
flags, int *jobid) sh.trapnote &= ~SH_SIGTERM; job_fork(-1);
sh.savesig = -1;
- while(_sh_fork(parent=fork(),flags,jobid) < 0);
+ parent = fork();
+ if (parent < 0 && errno == EAGAIN)
+ {
+ /* Linux -- we probably reached the NPROC limit */
+ errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_nofork);
+ }
+ while(_sh_fork(parent,flags,jobid) < 0);
sig = sh.savesig;
sh.savesig = 0;
if(sig>0)
--
Tomáš Smetana
Base OS Software Engineer, Red Hat
RH IRC: #brno #devel #base-os; Freenode IRC: #fedora-devel
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers