child process and parent process

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
MeIn
In need of some credit
In need of some credit
Posts: 1
Joined: Fri Jul 29, 2016 8:47 pm

child process and parent process

Postby MeIn » Fri Jul 29, 2016 8:51 pm

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);
}
Last edited by doublemax on Fri Jul 29, 2016 10:24 pm, edited 1 time in total.
Reason: Added code tags

User avatar
doublemax
Moderator
Moderator
Posts: 12508
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: child process and parent process

Postby doublemax » Fri Jul 29, 2016 10:32 pm

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
Use the source, Luke!


Return to “General Development”

Who is online

Users browsing this forum: No registered users and 4 guests