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

Pages: 1-

[C] SIGINT + SIGTERM to parent and children

Name: Anonymous 2009-11-19 6:00

'sup guys?

I have a parent process that at some point forks into at least one child process.
I want to kill everything (parent+children) if the parent or any of its child processes get a SIGINT or SIGTERM.

How can I do this?

I know I have to use stuff from signal.h and probably a mutex(not sure on this?) to flag when it's time to die.

I would appreciate if you guys could help me.

Thank you.

Anon.

Name: Anonymous 2009-11-19 6:05

set up a signal handler which catches SIGINT and SIGTERM and then uses killpg(0, SIGKILL);.

something like:
void handler(int signal)
{
   killpg(0, SIGKILL);
}

i haven't tested it, but i'm pretty sure it'll work.

Name: Anonymous 2009-11-19 6:21

Suck on my cheesy noise badger

Name: Anonymous 2009-11-19 7:27

>>2
Do I have to set the handler in the begging of the parents' main and then in the begging of the child (right after the fork made in the parent)?

Much thankful for the assistance!

Name: Anonymous 2009-11-19 7:29

>>4
should be inherited by the children if you set it before the fork()'s

Name: Anonymous 2009-11-19 7:39

>>5
Many thank's!

Name: Anonymous 2009-11-19 7:54

OP here.

Something like:

void rip () {
 killpg(0, SIGKILL);
}

int main (void)
{
  signal (SIGTERM, handler);
  signal (SIGINT, handler);


?

Name: Anonymous 2009-11-19 8:02

>>7
i think you've got the name of the handler a little mixed up.

void rip() {
 killpg(0, SIGKILL);
}

int main()
{
  signal(SIGTERM, rip);
  signal(SIGINT, rip);
  //fork and whatever
}

Name: Anonymous 2009-11-19 8:04

void rip()
{
 killpg(0, SIGKILL);
}

int main()
{
  signal(SIGTERM, rip);
  signal(SIGINT, rip);
  //fork and whatever
}

Name: Anonymous 2009-11-19 8:08

OP here.

Yeah, I know I mixed up the names.
RIP makes more sense. :) Let me test this in a bit.

Name: Anonymous 2009-11-19 8:16

fork() my anus

Name: Anonymous 2009-11-19 11:34

>>11
I don't fork, however I like spooning with my hot japanese girlfriendo.

Name: Anonymous 2009-11-19 11:44

>>12
spooning leads to forking1

1. Seen on some pyjamas for sale at London's Carnaby Street.

Name: Anonymous 2009-11-19 11:57

>>12
Spooning to life sized pillows of the Morning Musume cast is not having a hot Japanese girlfriend

Name: Anonymous 2009-11-19 12:44

>>12
you can do both with spork()

Name: Anonymous 2009-11-19 13:07

>>15
xD

Name: Anonymous 2009-11-19 22:00

jesus christ just negate your signal and it goes to the damn group.

even on the text boards, no one knows how to read.

Name: ​​​​​​​​​​ 2010-10-25 6:55

Name: Anonymous 2010-12-17 1:35

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Anonymous 2011-02-03 6:48

Name: Anonymous 2011-02-18 13:44

<-- that's cool and all, but check my doubles over there<

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