SIGBUS in exit?

SIGBUS in exit?

Post by Torsten Mu » Wed, 26 Oct 2005 19:14:31


I'm debugging a problem in an other people's program. This
contains the following lines:

if ((Pid = fork()) < 0)
RETURN_VAL(ERROR)
else
if (Pid != 0)
exit(0); /* parent goes bye-bye */

The fork call is successfull. During the exit call the parent process
gets a SIGBUS signal. What does this mean in this case?

System is HPUX 11.

T.M.
 
 
 

SIGBUS in exit?

Post by Rainer Tem » Wed, 26 Oct 2005 19:35:35


Hi Torsten,

let's assume, that the exit() code itself is clean ...
then you're left with funcionts that were registered
with atexit().

There are two ways to check this ...
- search the complete code for "atexit" and debug the
functions that are registered.
- replace exit() in this case with _exit() ...
a side-effect of this is, that FILE-buffers are _not_
flushed and that atexit-functions are _not_ called.
(If the SIGBUS disappears you have a hint of what went wrong)

The SIGBUS is (quite likely) generated due to a disaligned
access of data ... on some hardware (like the x86 family)
a 32-bit access to an address that is not 32-bit-aligned will
get a penalty of 1 or more waitstates.
... on other hardware like the Mips R3000 R4000 R10000 family
such an access is not possible ... therefore a SIGBUS will be
generated.
Look at the following code snippet:

long l,*lptr;
char *cptr;

cptr = (char *) &l;
cptr++;
lptr = (long *) cptr;
*lptr = 1;

This invokes a disaligned access to memory ... and might
result in a SIGBUS on the HPUX 11.

Regards ... Rainer