Page 1 of 1

child process and parent process

Posted: Fri Jul 29, 2016 8:51 pm
by MeIn
Below is the code to send signals form parent process to child process. I want to send signals from child process to parent process in this code.
can someone help me for this.

Code: Select all

//sig_talk.c
#include <stdio.h>
#include <signal.h>

 /* routines child will call upon sigtrap */
void sigint();
void sigquit();

main()
{ int pid;

  /* get child process */
  
   if ((pid = fork()) < 0) {
        perror("fork");
        exit(1);
    }
    
   if (pid == 0)
     { /* child */
       
       signal(SIGINT,sigint);
       signal(SIGQUIT, sigquit);
       for(;;); /* loop for ever */
     }
  else /* parent */
     {  /* pid hold id of child */
       
       printf("\nPARENT: sending SIGINT\n\n");
       kill(pid,SIGINT);
       sleep(3); /* pause for 3 secs */
       printf("\nPARENT: sending SIGQUIT\n\n");
       kill(pid,SIGQUIT);
       sleep(3);
     }
}

void sigint()

{  signal(SIGINT,sigint); /* reset signal */
   printf("CHILD: I have received a SIGINT\n");
}

void sigquit()

{ printf("My DADDY has Killed me!!!\n");
  exit(0);
}

Re: child process and parent process

Posted: Fri Jul 29, 2016 10:32 pm
by doublemax
The key word that you need to Google for this is "inter process communication".

What i found:
http://advancedlinuxprogramming.com/alp ... 05-ipc.pdf
https://www.cs.cf.ac.uk/Dave/C/node23.html