Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

[C/POSIX] kill + signal

Name: Anonymous 2010-12-08 7:48

I need to make something in a way that when a program receives a SIGINT/SIGTERM all the processes in this program's process group that receives this signal get killed.

Will the following work?


//shit done in the main:
pid = fork();
signal(SIGINT, (__sighandler_t) murder);
signal(SIGTERM, (__sighandler_t) murder);
//moreblabla
void murder(void)
{
 lol(); // frees shared memory and semaphores;
 kill(0, 9);
}


Some guys told me that this should suffice, and that I should also consider substituting signal for sigaction.

What do you think?

Name: Anonymous 2010-12-08 8:22

Have you read your APUE today?

but seriously i dunno, you might need a setsid as well...

Name: Anonymous 2010-12-08 9:00

Get rid of the casts and make that function void murder(int sig) for starters.

Name: Anonymous 2010-12-08 9:48

>>3
why?

Name: Anonymous 2010-12-08 10:21

>>4
Because you're giving it the wrong function type.

Name: Anonymous 2010-12-08 10:43

>>5
But why?

Name: Anonymous 2010-12-08 10:59

>>6
Because of C's static type system.

Name: Anonymous 2010-12-08 11:08

OP and 3 here:
How would I use (int sig) in handler?

Name: Anonymous 2010-12-08 11:10

>>8
For example:
void murder(int sig)
{
 lol(); // frees shared memory and semaphores;
 kill(0, 9);
}


You don't have to. You could printf it if it mattered. Or you could ignore it if it isn't urgent.

Name: Anonymous 2010-12-08 11:13

>>8
and what about sigaction?

Name: Anonymous 2010-12-08 11:17

>>9
Ah, something like "you threw a X signal at me, thanks a lot, jerk"?

makes sense!

Name: Anonymous 2010-12-08 12:30

>>11
The process that sends the signal can't read english

Name: Anonymous 2010-12-08 13:49

>>12
That's implementation-defined.

Name: Anonymous 2010-12-08 17:49

killpg

This is all you need, little man...

Name: Anonymous 2011-02-03 1:52


Don't change these.
Name: Email:
Entire Thread Thread List