Sig handler causing core dump

Discussion in 'C Programming' started by Mark Brackett, Nov 3, 2004.

  1. I'm a newbie to C programming...so 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_progress = 0;
    void DieServer(int sig){
    int result;
    char dummy[0];
    if(dying_in_progress) raise(sig);
    dying_in_progress = 1;

    // Now do the clean up actions:
    if(debug==1) printf("SERVER PARENT->Received SIGEVENT %d.\n",sig);
    wait();
    close(client_sockfd);
    read(server_sockfd,dummy,0);
    result = close(server_sockfd);
    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?
    Mark Brackett, Nov 3, 2004
    #1
    1. Advertising

  2. Mark Brackett

    Artie Gold Guest

    Mark Brackett wrote:
    > I'm a newbie to C programming...so go easy. ;)


    OK. I'll be gentle.

    > I'm forking child processes, and registering a signal handler with the following:


    Whoops. There is no such thing as `forking' in standard C...

    > signal(SIGTERM, DieServer);
    > signal(SIGINT, DieServer);
    >
    > DieServer is the following:
    > volatile sig_atomic_t dying_in_progress = 0;
    > void DieServer(int sig){
    > int result;
    > char dummy[0];
    > if(dying_in_progress) raise(sig);
    > dying_in_progress = 1;
    >
    > // Now do the clean up actions:
    > if(debug==1) printf("SERVER PARENT->Received SIGEVENT %d.\n",sig);
    > wait();
    > close(client_sockfd);
    > read(server_sockfd,dummy,0);
    > result = close(server_sockfd);
    > 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?

    ....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

    http://it-matters.blogspot.com
    Artie Gold, Nov 3, 2004
    #2
    1. Advertising

  3. In article <>,
    Mark Brackett <> wrote:
    >I'm a newbie to C programming...so go easy. ;)
    >I'm forking child processes,

    <snip>
    >The wait() causes a core dump if there's no children. How do I fix this?


    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.programmer would be a better place to ask this.


    dave

    --
    Dave Vandervies
    Hmm, a quote for posterity: "calling strlen() is a lengthy operation."
    Is calling memmove() a 'moving experience?'
    --Mike Wahler in comp.lang.c
    Dave Vandervies, Nov 3, 2004
    #3
  4. (Dave Vandervies) wrote in message news:<cmbn54$ldi$>...
    > In article <>,
    > Mark Brackett <> wrote:
    > >I'm a newbie to C programming...so go easy. ;)
    > >I'm forking child processes,

    > <snip>
    > >The wait() causes a core dump if there's no children. How do I fix this?

    >
    > 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.programmer would be a better place to ask this.
    >
    >
    > dave


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

    --Mark Brackett
    Mark Brackett, Nov 4, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    0
    Views:
    697
  2. halfdog
    Replies:
    12
    Views:
    12,418
  3. Xaver Hinterhuber

    function causing core dump

    Xaver Hinterhuber, May 10, 2004, in forum: Python
    Replies:
    4
    Views:
    312
    Terry Reedy
    May 10, 2004
  4. Robert Brewer

    RE: function causing core dump

    Robert Brewer, May 10, 2004, in forum: Python
    Replies:
    5
    Views:
    329
    Peter Otten
    May 17, 2004
  5. matchstick86

    sig : process vs. process(sig)

    matchstick86, Oct 12, 2009, in forum: VHDL
    Replies:
    1
    Views:
    552
    power_hf2005
    Oct 13, 2009
Loading...

Share This Page