fork'ing abort()

Posted by halkeye on Wed 24 Dec 2003 12:32 AM — 5 posts, 19,990 views.

Canada #0
Been wondering about fork and abort.

if i fork a process, can i abort and dump a core of the parent?

I'm trying to do crash/segviolation handling, while that is farily easy with the copyover/hotboot code, but i would like to have any crashes dump a core file too.

I figure if i do:
if (fork())
{
abort();
} else {
// code
}

Or will that kill both things?
Amended on Wed 24 Dec 2003 12:38 AM by halkeye
Australia Forum Administrator #1
Once you have forked you have two copies of the process. It is fine to abort one of them.
Australia Forum Administrator #2
Anyway, write a 11-line test program and see for yourself ...


int main (void)
{
if (fork())
  {
  printf ("This process is aborting...\n");
  abort(); 
  } 
else 
  {
  printf ("This process is still working...\n");
  }
return 0;
}  // end of main


You probably need a couple of include files, but that is the general idea.
Canada #3
While i should have thought to actually try it, it just slipped my mind.

After reading many man pages on signals and fork and such, i thought i remebered being told that a child process will not handle singals.

I know there has to be a way, as daemons use fork(), but still handle singals.

Here is the code i'm currently trying, though it doesn't work.


/*        signal( SIGPIPE, SIG_DFL );
        signal( SIGSEGV, SIG_DFL );
        signal( SIGTERM, SIG_DFL ); */
        if (fork())
        {
                abort();
        }
        else
        {
                signal( SIGPIPE, SIG_IGN );
                signal( SIGSEGV, SegVio );
                signal( SIGTERM, SigTerm );
                /* hotboot - Do Recovery Here */
        }


I'm sure i'm missing something blatently obvious...

I think it has todo with the fact that the parent no longer exists.
Amended on Wed 24 Dec 2003 04:36 AM by halkeye
Canada #4
dude, i'm dumb. It works, just i'm unable to send kill signals to it.

at least it appears to work.