sowdust
sowdust

Reputation: 87

C unix: sending a signal to a process with kill isn't the same that from keybord..why?

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.

Upvotes: 0

Views: 615

Answers (1)

OneOfOne
OneOfOne

Reputation: 99361

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.

Upvotes: 1

Related Questions