[net.unix-wizards] fork failures within shell scripts

stu@jpusa1.UUCP (Stu Heiss) (07/20/86)

I've been using a spooling/unbatching scheme for incoming news that can
(and does) lose an article due to inability to fork under heavy load.
The fragment in question looks like:

cd $Xqtdir
ls -tr 2>/dev/null |
while :
do
	read FILE
	case "$FILE" in
	'')
		/bin/rm $LOCKFILE
		exit 0
		;;
	news.*)
		# invoke inews with the article
		$lib/rnews < $FILE 2>>$errlog; /bin/rm $FILE
		;;
	esac
done

and the problem is if inews fails to fork but rm does, the article gets
dropped.  This brings up the more general question of how can you tell,
within a shell script, whether the last process was able to fork?  I
can't tell from the manuals whether this is possible or not.  Anybody
know how to do this or get around this problem?  You cant do something
simple like:

		inews < file && rm file

since inews will return various error codes normally.  What to do?

-- 
Stu Heiss {ihnp4!jpusa1!stu}

gwyn@brl-smoke.ARPA (Doug Gwyn ) (07/20/86)

The SVR2 Bourne shell goes into an exponential backoff retry mode
when an attempt to fork fails.  Sometimes this is a good idea and
sometimes it is incredibly stupid (consider what happens on an
overloaded system running several shell scripts; as soon as one
fails to fork, it will probably never succeed until long after
the load drops back to normal).