0

So I have this parent process A which forks and creates some processes, B and C. C itself will create more, but I don't think it matters.

A forks:

char *argv_exec[] = {
    "/usr/bin/xfce4-terminal",
    "--geometry",
    "160x48",
    "-x",
    "./tv",
    NULL };

pid_tv = fork();

if (pid_tv == 0)
{   
    (void) execv(argv_exec[0], argv_exec);
    fprintf (stderr, "Errore nella execv.\n%s\n",
    strerror(errno) );
    anelito(0);
} 

While they all run together, I want to be able to send a signal from process B to its parent process A to make him do something - in this case kill all children and re-fork.

Process A sends its pid to process B in a message.

Parent A handles the signal:

if(signal(SIGQUIT,riparti)==SIG_ERR)
    ...
    void riparti(int s)
    { 
               kill_all_children();
               fork_all_children_again();
    }

Process B sends a SIGQUIT to A when it receives one (it bounces it) process B has:

signal(SIGQUIT,riparti);

void riparti(int a)
    {
          kill(pid_parent,SIGQUIT);
    }

Now when i press CTRL+\ on the window of process B once, all goes well. If i do it a second time, process A does not seem to receive the signal anymore.

sowdust
  • 87
  • 1
  • 9
  • Add the code you use for forking. – OneOfOne Sep 05 '13 at 01:03
  • I'm not sure, it should be working – OneOfOne Sep 05 '13 at 01:39
  • It's strange, I can send a SIGQUIT with Ctrl+\\ both from the child window and from the actual parent window (as I'd expect) but once I've done so once the other Ctrl+\\ I press do not seem to work anymore; the character ^\\ is printed on screen but nothing happens. I've also checked with sigpending() and no signal is sent after the first one! – sowdust Sep 05 '13 at 09:49

1 Answers1

1

I think you're killing the parent process from outside the fork code, you're actually sending that signal from process A, which in turn will kill the parent terminal.

OneOfOne
  • 95,033
  • 20
  • 184
  • 185
  • yes thanks! True, the actual command I was calling is /usr/bin/xfce4-terminal which in turn calls the program... however now that i pass the parent (A) pid into a message, I can only use the signal once. I'll edit the main message with more details – sowdust Sep 05 '13 at 01:21