Sig handler causing core dump

M

Mark Brackett

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?
 
A

Artie Gold

Mark said:
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
would be the best course of action.

Gentle enough for you? ;-)

See you over there.

HTH,
--ag
 
D

Dave Vandervies

I'm a newbie to C programming...so go easy. ;)
I'm forking child processes,
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
 
M

Mark Brackett

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top