Sig handler causing core dump

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Brackett

    Sig handler causing core dump

    I'm a newbie to C programming...s o go easy. ;)
    I'm forking child processes, and registering a signal handler with the following:
    signal(SIGTERM, DieServer);
    signal(SIGINT, DieServer);

    DieServer is the following:
    volatile sig_atomic_t dying_in_progre ss = 0;
    void DieServer(int sig){
    int result;
    char dummy[0];
    if(dying_in_pro gress) raise(sig);
    dying_in_progre ss = 1;

    // Now do the clean up actions:
    if(debug==1) printf("SERVER PARENT->Received SIGEVENT %d.\n",sig);
    wait();
    close(client_so ckfd);
    read(server_soc kfd,dummy,0);
    result = close(server_so ckfd);
    if(result==-1){
    if(debug==1) printf("SERVER PARENT->Could not close socket\n");
    perror("WARNING ");
    }
    signal(sig, SIG_DFL);
    raise(sig);
    }

    The wait() causes a core dump if there's no children. How do I fix this?
  • Artie Gold

    #2
    Re: Sig handler causing core dump

    Mark Brackett wrote:[color=blue]
    > I'm a newbie to C programming...s o go easy. ;)[/color]

    OK. I'll be gentle.
    [color=blue]
    > I'm forking child processes, and registering a signal handler with the following:[/color]

    Whoops. There is no such thing as `forking' in standard C...
    [color=blue]
    > signal(SIGTERM, DieServer);
    > signal(SIGINT, DieServer);
    >
    > DieServer is the following:
    > volatile sig_atomic_t dying_in_progre ss = 0;
    > void DieServer(int sig){
    > int result;
    > char dummy[0];
    > if(dying_in_pro gress) raise(sig);
    > dying_in_progre ss = 1;
    >
    > // Now do the clean up actions:
    > if(debug==1) printf("SERVER PARENT->Received SIGEVENT %d.\n",sig);
    > wait();
    > close(client_so ckfd);
    > read(server_soc kfd,dummy,0);
    > result = close(server_so ckfd);
    > if(result==-1){
    > if(debug==1) printf("SERVER PARENT->Could not close socket\n");
    > perror("WARNING ");
    > }
    > signal(sig, SIG_DFL);
    > raise(sig);
    > }
    >
    > The wait() causes a core dump if there's no children. How do I fix this?[/color]
    ....nor read(), nor close() nor wait().

    There *are* such things in POSIX, hence posting your question to
    news:comp.unix. programmer would be the best course of action.

    Gentle enough for you? ;-)

    See you over there.

    HTH,
    --ag

    --
    Artie Gold -- Austin, Texas

    Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

    Comment

    • Dave Vandervies

      #3
      Re: Sig handler causing core dump

      In article <dea053cf.04110 31441.5b526379@ posting.google. com>,
      Mark Brackett <brackett@ufl.e du> wrote:[color=blue]
      >I'm a newbie to C programming...s o go easy. ;)
      >I'm forking child processes,[/color]
      <snip>[color=blue]
      >The wait() causes a core dump if there's no children. How do I fix this?[/color]

      forking child processes, wait(), and a lot of what was in between that I
      snipped are beyond the scope of the C language and therefore inappropriate
      for comp.lang.c.

      I suspect that comp.unix.progr ammer would be a better place to ask this.


      dave

      --
      Dave Vandervies dj3vande@csclub .uwaterloo.ca
      Hmm, a quote for posterity: "calling strlen() is a lengthy operation."
      Is calling memmove() a 'moving experience?'
      --Mike Wahler in comp.lang.c

      Comment

      • Mark Brackett

        #4
        Re: Sig handler causing core dump

        dj3vande@csclub .uwaterloo.ca (Dave Vandervies) wrote in message news:<cmbn54$ld i$1@rumours.uwa terloo.ca>...[color=blue]
        > In article <dea053cf.04110 31441.5b526379@ posting.google. com>,
        > Mark Brackett <brackett@ufl.e du> wrote:[color=green]
        > >I'm a newbie to C programming...s o go easy. ;)
        > >I'm forking child processes,[/color]
        > <snip>[color=green]
        > >The wait() causes a core dump if there's no children. How do I fix this?[/color]
        >
        > forking child processes, wait(), and a lot of what was in between that I
        > snipped are beyond the scope of the C language and therefore inappropriate
        > for comp.lang.c.
        >
        > I suspect that comp.unix.progr ammer would be a better place to ask this.
        >
        >
        > dave[/color]

        Doh! Sorry for the faux pas....I'll try again over there. Thanks for
        the gently delivered heads-ups.

        --Mark Brackett

        Comment

        Working...