ksh bugs
Steve Price
rsp at PacBell.COM
Sat Sep 2 08:03:37 AEST 1989
I'd appreciate it if someone could confirm the (to me) unexpected
behaviours of the following ksh script. The problems are explained
in the header commentary section.
I have run this on AT&T 3B15, AT&T 3B2/400, and Convergent Technologies
Mighty Frame will very similar buggy(?) results.
########################## KSH BUGS TEST ##################################
#
# USAGE: copy this script as "ksh.bugs"; $ chmod 755 ksh.bugs; $ ksh.bugs
#
# Steve Price
# pacbell!pbhyf!rsp
# (415)823-1951
# 09/01/89
#
# A test script, illustrating bugs in ksh.
#
# There seem to to be 2 bugs, one with kill one with wait:
#
# 1)
# Kill does not print the correct PID when called from a ksh shell script
# which waits upon the process killed. The PID killed is not the PID
# printed in the kill message.
#
# GIVEN: $PID=2134, "kill $PID" is called on line 6 of ksh shell, shellname,
# and "wait $PID" is on line 7 of shellname then this msg is printed:
# shellname[7]: 2137 Terminated;
# the PID actually killed is overlayed with the line number of the ksh line
# that called wait. If the wait was called by line 156, when
# PID 2134 is killed the ksh prints:
# shellname[156]: 2156 Terminated.
# (A further unexpected fact: After executing the shell by its name
# on the commandline, if the ksh repeat command "r" is used to run
# the shell, NO ERROR WILL RESULT. Typing the shell by name will
# produce the error every time; repeating it thereafter by "r" will
# never produce the error. Why?)
#
# 2)
# Wait does not return the correct exit status of a waited on PID
# (if the process waited on is not called immediately before wait.)
# If a process is waited on and terminated by a kill command, 0
# will be returned by wait, if the waited on process is not the
# last process placed in the background before wait. This is
# an error because it makes it impossible to distinquish a terminated
# process from a successfully completing process.
#
# If the waited upon process IS the last backgrounded process before the
# wait, a kill of that process causes wait to return 143, which is fine.
#
##############################################################################
#
# Correctly working wait; returns nonzero when waited upon process killed.
#
sleep 40 &
SPID=$!
print -u2 "SLEEP PID: $SPID"
print -u2 "Killing $SPID. BUG 1. Mislabeled PID after kill:"
kill $SPID
wait $SPID
print -u2 "WAIT PID: $?"
print -u2 "Correct return code (nonzero) after waited upon process killed\n"
#
# BUG 2
# Incorrect return from wait after waited upon process killed
#
sleep 80 &
S2PID=$!
print -u2 "2nd SLEEP PID: $S2PID"
sleep 30 & # note, this process confuses wait
print -u2 "Killing $S2PID. The PID reported terminated is in error, per bug 1:"
kill $S2PID
wait $S2PID
print -u2 "WAIT PID: $?"
print "BUG 2: WRONG return code (zero) after waited upon process killed"
#
## end of shell ########## KSH BUGS TEST ##################################
--
Steve Price
pacbell!pbhyf!rsp
(415)823-1951
"'Nothing will come from nothing' without information" -- Shakespeare & Bateson
More information about the Comp.unix.wizards
mailing list