2.9BSD Termination codes
Guy Harris
guy at sun.uucp
Mon May 27 08:28:27 AEST 1985
> I was trying to get the recently posted "insults" program running
> on my 11/70, and when the makefile tried "./kafka <whatever>.k"
> I get the message "*** Termination code 138". Whence comes this
> message?
When a program run by another program exits, it either returns an "exit
code" (labelled as an "Error code" by "make" if it isn't zero) if it
terminates normally by doing an "exit" system call", or a "termination code"
if it terminates due to a signal. The termination code has the signal
number in the lower 7 bits; the eighth bit is a flag indicating whether a
memory image was dumped. That information is what the shell uses to say
"Memory fault" - signal 11 - and, if a memory image was dumped, "core
dumped". Unfortunately, "make" does an extremely poor job of decoding this
information, unlike the shell; it just throws the raw bits (TM of Minnesota
Public Radio?) at you. 138 (decimal) == 128 + 10. The 128 is the eighth
bit, indicating that a memory image was dumped; the 10 indicates signal 10
which is SIGBUS. On most UNIXes, this indicates that the machine got a "bus
error", which, under normal circumstances, means the program tried to
reference a 16-bit quantity on an odd-byte boundary or something like that.
4.xBSD for the VAX also gives this signal if a program tries to write to a
write-protected portion of memory or read from a read-protected portion of
memory.
In short, it means that the "kafka" program blew up; my guess is that it
tried to reference a 16-bit quantity on an odd-byte boundary, since the VAX
allows that but the PDP-11 doesn't.
For the benefit of those of you who are sick of "Termination code NNN"
messages from "make", the following lump of code can be stuck into
"doname.c". The code is pretty much the same in the V7 "make" (which
appears in 4.xBSD) and the S3/S5 "make". Just replace the code that calls
"dosys" and prints a message if the return status is non-zero with this code.
The "#ifdef BSD4_2" reflects the fact that 4.2BSD provides a standard list
of "signal messages"; V7, 4.1BSD, and S{3,5} don't. You may have to adjust
the list of messages for your particular flavor of UNIX.
#include <sys/signal.h>
if( status = dosys(comstring, nohalt) )
{
if( status>>8 )
(void)printf("*** Error code %d", status>>8 );
else
{
#ifdef BSD4_2
extern char *sys_siglist[];
#else
static char *sys_siglist[] = {
"Signal 0",
"Hangup",
"Interrupt",
"Quit",
"Illegal instruction",
"Trace/BPT trap",
"Abort",
"EMT trap",
"Floating exception",
"Killed",
"Bus error",
"Memory fault",
"Bad system call",
"Broken pipe",
"Alarm call",
"Terminated",
"Signal 16",
"Signal 17",
"Child death",
"Power fail",
};
#endif
int coredumped;
coredumped = status & 0200;
status &= 0177;
if (status > NSIG)
(void)printf("*** Signal %d", status );
else
(void)printf("*** %s", sys_siglist[status] );
if (coredumped)
(void)printf(" - core dumped");
}
if(nohalt) (void)printf(" (ignored)\n");
else (void)printf("\n");
(void)fflush(stdout);
}
This code has compiled, but I haven't tested it, nor have I compiled it
except under 4.2BSD.
Guy Harris
More information about the Comp.unix
mailing list