From: steves@sv001.UUCP (Steve Schlesinger 3711)
Newsgroups: comp.unix.shell
Subject: ksh stops forking processes
Date: 8 Apr 92 22:46:21 GMT

Can anyone explain what is happening here,
and how do I get around it?

The problem was observed on both i486 SVR4
and Solbourne SunOS 4.1

Below are 4 shell scripts:
	driver, dowatcher, watcher and sleeper.

When the following shell script is run:

	driver 40 12

When run under /bin/sh it runs as expected.

The results under ksh are not what are expected.

Briefly, ksh stops generating new processes
while sh generates the processes as desired 
and expected.

It is NOT a problem of reaching the kernel
MAXUP process limit since it is OK with /bin/sh.

====================================================
         driver
====================================================
#
#
#    NSLEEPERS is the number of sleeper processes that
#         are all started and put in the background
#
#    SLEEPTIME is how long each sleeper sleeps
#
#
NSLEEPERS=$1
SLEEPTIME=$2
#
#    the 'watcher' checks to see how many sleepers are
#         running
#
WATCHINT=`expr $SLEEPTIME / 6`
echo start >runwatcher		# watcher runs while file exists
dowatcher $WATCHINT 
#
#    create sleepers
#
N=1
while [ $N -le $NSLEEPERS ]
do
	echo "driver: start sleeper $N at " `date "+%T"`
	sleeper $N $SLEEPTIME &
	N=`expr $N + 1`
done
echo "driver: $NSLEEPERS started"
#
wait
rm -f runwatcher
echo "driver: done"
 
====================================================
         dowatcher
====================================================
#
#    just start watcher and return
#
#    this is needed because the caller wait's
#         for its children to finish
#
watcher $1 &
 
====================================================
         watcher
====================================================
#
#    check every WATCH seconds to see how many sleeps
#        are active
#
WATCH=$1
echo "watcher started at " `date "+%T"` "watch interval $WATCH seconds"
while [ -f runwatcher ]
do
	sleep $WATCH
	now=`date "+%T`
	sleepers=`ps -eaf | grep sleep | wc -l`
	echo "watcher: $sleepers sleepers at " $now
done
echo "watcher done"
 
====================================================
         sleeper
====================================================
#
#   just sleep for SLEEP seconds and report which sleeper
#      you are when you wake up
#
N=$1
SLEEP=$2
start=`date "+%T"`
#echo "sleeper: $N started at $start"
sleep $SLEEP
stop=`date "+ %T"`
echo "sleeper: $N finishes $stop -- started at $start"
 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#sh driver 40 12

watcher started at  14:58:01 watch interval 2 seconds
driver: start sleeper 1 at  14:58:02
driver: start sleeper 2 at  14:58:02
driver: start sleeper 3 at  14:58:02
driver: start sleeper 4 at  14:58:02
driver: start sleeper 5 at  14:58:02
driver: start sleeper 6 at  14:58:02
driver: start sleeper 7 at  14:58:02
driver: start sleeper 8 at  14:58:02
driver: start sleeper 9 at  14:58:02
driver: start sleeper 10 at  14:58:03
driver: start sleeper 11 at  14:58:03
driver: start sleeper 12 at  14:58:03
driver: start sleeper 13 at  14:58:03
driver: start sleeper 14 at  14:58:03
driver: start sleeper 15 at  14:58:03
driver: start sleeper 16 at  14:58:03
driver: start sleeper 17 at  14:58:03
driver: start sleeper 18 at  14:58:03
driver: start sleeper 19 at  14:58:04
driver: start sleeper 20 at  14:58:04
driver: start sleeper 21 at  14:58:04
driver: start sleeper 22 at  14:58:04
driver: start sleeper 23 at  14:58:04
driver: start sleeper 24 at  14:58:04
driver: start sleeper 25 at  14:58:04
driver: start sleeper 26 at  14:58:05
driver: start sleeper 27 at  14:58:05
driver: start sleeper 28 at  14:58:05
driver: start sleeper 29 at  14:58:05
driver: start sleeper 30 at  14:58:05
driver: start sleeper 31 at  14:58:05
driver: start sleeper 32 at  14:58:05
driver: start sleeper 33 at  14:58:05
driver: start sleeper 34 at  14:58:06
driver: start sleeper 35 at  14:58:06
driver: start sleeper 36 at  14:58:06
driver: start sleeper 37 at  14:58:06
driver: start sleeper 38 at  14:58:06
driver: start sleeper 39 at  14:58:06
driver: start sleeper 40 at  14:58:06
driver: 40 started
watcher:      27  sleepers at  14:58:04
watcher:      40  sleepers at  14:58:09
watcher:      40  sleepers at  14:58:11
watcher:      40  sleepers at  14:58:13
sleeper: 1 finishes  14:58:14 -- started at 14:58:02
sleeper: 2 finishes  14:58:14 -- started at 14:58:02
sleeper: 3 finishes  14:58:14 -- started at 14:58:02
sleeper: 4 finishes  14:58:14 -- started at 14:58:02
sleeper: 5 finishes  14:58:14 -- started at 14:58:02
sleeper: 6 finishes  14:58:14 -- started at 14:58:02
sleeper: 7 finishes  14:58:14 -- started at 14:58:02
sleeper: 8 finishes  14:58:14 -- started at 14:58:02
sleeper: 9 finishes  14:58:15 -- started at 14:58:02
sleeper: 10 finishes  14:58:15 -- started at 14:58:03
sleeper: 11 finishes  14:58:15 -- started at 14:58:03
sleeper: 12 finishes  14:58:15 -- started at 14:58:03
sleeper: 13 finishes  14:58:15 -- started at 14:58:03
sleeper: 14 finishes  14:58:15 -- started at 14:58:03
sleeper: 15 finishes  14:58:15 -- started at 14:58:03
sleeper: 16 finishes  14:58:15 -- started at 14:58:03
sleeper: 17 finishes  14:58:15 -- started at 14:58:03
watcher:      23  sleepers at  14:58:15
sleeper: 18 finishes  14:58:16 -- started at 14:58:04
sleeper: 19 finishes  14:58:16 -- started at 14:58:04
sleeper: 20 finishes  14:58:16 -- started at 14:58:04
sleeper: 21 finishes  14:58:16 -- started at 14:58:04
sleeper: 22 finishes  14:58:16 -- started at 14:58:04
sleeper: 23 finishes  14:58:16 -- started at 14:58:04
sleeper: 24 finishes  14:58:16 -- started at 14:58:04
sleeper: 25 finishes  14:58:17 -- started at 14:58:05
sleeper: 26 finishes  14:58:17 -- started at 14:58:05
sleeper: 27 finishes  14:58:17 -- started at 14:58:05
sleeper: 28 finishes  14:58:17 -- started at 14:58:05
sleeper: 29 finishes  14:58:17 -- started at 14:58:05
sleeper: 30 finishes  14:58:17 -- started at 14:58:05
sleeper: 31 finishes  14:58:17 -- started at 14:58:05
sleeper: 32 finishes  14:58:17 -- started at 14:58:05
watcher:       8  sleepers at  14:58:17
sleeper: 33 finishes  14:58:18 -- started at 14:58:05
sleeper: 34 finishes  14:58:18 -- started at 14:58:06
sleeper: 35 finishes  14:58:18 -- started at 14:58:06
sleeper: 36 finishes  14:58:18 -- started at 14:58:06
sleeper: 37 finishes  14:58:18 -- started at 14:58:06
sleeper: 38 finishes  14:58:18 -- started at 14:58:06
sleeper: 39 finishes  14:58:18 -- started at 14:58:06
sleeper: 40 finishes  14:58:18 -- started at 14:58:06
driver: done
watcher:       0  sleepers at  14:58:19
watcher done
 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#ksh driver 40 12

watcher started at  14:58:32 watch interval 2 seconds
driver: start sleeper 1 at  14:58:33
driver: start sleeper 2 at  14:58:33
driver: start sleeper 3 at  14:58:33
driver: start sleeper 4 at  14:58:33
driver: start sleeper 5 at  14:58:33
driver: start sleeper 6 at  14:58:33
driver: start sleeper 7 at  14:58:34
driver: start sleeper 8 at  14:58:34
driver: start sleeper 9 at  14:58:34
driver: start sleeper 10 at  14:58:34
driver: start sleeper 11 at  14:58:34
driver: start sleeper 12 at  14:58:34
driver: start sleeper 13 at  14:58:35
driver: start sleeper 14 at  14:58:35
driver: start sleeper 15 at  14:58:35
driver: start sleeper 16 at  14:58:35
driver: start sleeper 17 at  14:58:35
driver: start sleeper 18 at  14:58:36
driver: start sleeper 19 at  14:58:36
driver: start sleeper 20 at  14:58:36
driver: start sleeper 21 at  14:58:36
driver: start sleeper 22 at  14:58:36
driver: start sleeper 23 at  14:58:36
driver: start sleeper 24 at  14:58:37
driver: start sleeper 25 at  14:58:37
driver: start sleeper 26 at  14:58:37
driver: start sleeper 27 at  14:58:37
driver: start sleeper 28 at  14:58:37
driver: start sleeper 29 at  14:58:38
driver: start sleeper 30 at  14:58:38
>>>   ksh stops generating sleepers
watcher:      15  sleepers at  14:58:35
watcher:      31  sleepers at  14:58:40
watcher:      31  sleepers at  14:58:42
watcher:      31  sleepers at  14:58:44
sleeper: 1 finishes  14:58:45 -- started at 14:58:33
sleeper: 2 finishes  14:58:45 -- started at 14:58:33
sleeper: 3 finishes  14:58:45 -- started at 14:58:33
sleeper: 4 finishes  14:58:45 -- started at 14:58:33
sleeper: 5 finishes  14:58:45 -- started at 14:58:33
sleeper: 6 finishes  14:58:46 -- started at 14:58:33
sleeper: 7 finishes  14:58:46 -- started at 14:58:34
sleeper: 8 finishes  14:58:46 -- started at 14:58:34
sleeper: 9 finishes  14:58:46 -- started at 14:58:34
sleeper: 10 finishes  14:58:46 -- started at 14:58:34
sleeper: 11 finishes  14:58:46 -- started at 14:58:34
watcher:      19  sleepers at  14:58:46
sleeper: 12 finishes  14:58:47 -- started at 14:58:34
sleeper: 13 finishes  14:58:47 -- started at 14:58:35
sleeper: 14 finishes  14:58:47 -- started at 14:58:35
sleeper: 15 finishes  14:58:47 -- started at 14:58:35
sleeper: 16 finishes  14:58:47 -- started at 14:58:35
sleeper: 17 finishes  14:58:48 -- started at 14:58:36
sleeper: 18 finishes  14:58:48 -- started at 14:58:36
sleeper: 19 finishes  14:58:48 -- started at 14:58:36
sleeper: 20 finishes  14:58:48 -- started at 14:58:36
sleeper: 21 finishes  14:58:48 -- started at 14:58:36
sleeper: 22 finishes  14:58:48 -- started at 14:58:36
watcher:       8  sleepers at  14:58:48
sleeper: 23 finishes  14:58:49 -- started at 14:58:37
sleeper: 24 finishes  14:58:49 -- started at 14:58:37
sleeper: 25 finishes  14:58:49 -- started at 14:58:37
sleeper: 26 finishes  14:58:49 -- started at 14:58:37
sleeper: 27 finishes  14:58:49 -- started at 14:58:37
sleeper: 28 finishes  14:58:49 -- started at 14:58:37
sleeper: 29 finishes  14:58:50 -- started at 14:58:38
sleeper: 30 finishes  14:58:50 -- started at 14:58:38
>>>    ksh resumes generating sleepers after first 30
>>>    sleepers finish
driver: start sleeper 31 at  14:58:50
driver: start sleeper 32 at  14:58:50
driver: start sleeper 33 at  14:58:50
driver: start sleeper 34 at  14:58:50
driver: start sleeper 35 at  14:58:51
driver: start sleeper 36 at  14:58:51
driver: start sleeper 37 at  14:58:51
driver: start sleeper 38 at  14:58:51
driver: start sleeper 39 at  14:58:51
driver: start sleeper 40 at  14:58:51
driver: 40 started
watcher:       0  sleepers at  14:58:50
watcher:      10  sleepers at  14:58:54
watcher:      10  sleepers at  14:58:56
watcher:      10  sleepers at  14:58:58
watcher:      10  sleepers at  14:59:00
sleeper: 31 finishes  14:59:02 -- started at 14:58:50
sleeper: 32 finishes  14:59:02 -- started at 14:58:50
sleeper: 33 finishes  14:59:02 -- started at 14:58:50
sleeper: 34 finishes  14:59:02 -- started at 14:58:50
watcher:       6  sleepers at  14:59:02
sleeper: 35 finishes  14:59:03 -- started at 14:58:51
sleeper: 36 finishes  14:59:03 -- started at 14:58:51
sleeper: 37 finishes  14:59:03 -- started at 14:58:51
sleeper: 38 finishes  14:59:03 -- started at 14:58:51
sleeper: 39 finishes  14:59:03 -- started at 14:58:51
sleeper: 40 finishes  14:59:04 -- started at 14:58:51
driver: done
watcher:       0  sleepers at  14:59:04
watcher done



===============================================================================
Steve Schlesinger, NCR/Torrey Pines Development Center             619-597-3711
11010 Torreyana Rd, San Diego, CA 92121    steve.schlesinger@sandiegoCA.ncr.com
                                           ucsd.edu!sv001!steves
===============================================================================
Newsgroups: comp.unix.shell