title: Access shared memory to child process with signal
body: <p>I need some help with my c program. Basically, in my c program, I wish my parent process calculates a+b and my child process calculates 3*(a+b). However, I don't how to access the shared memory after sending the signal. Any help is appreciated.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/ipc.h&gt;
  #include &lt;sys/shm.h&gt;
  
  void sigcont(int shmid); 
  
  int main (int argc, char *argv[]){
      int shmid;
      int *result;
      pid_t pid;
  
      int size_data = 2 * sizeof (int);
      shmid = shmget (IPC_PRIVATE, size_data, 0666 | IPC_CREAT);
      
      pid = fork ();
      if (pid == 0) {
          signal(SIGCONT, sigcont); 
          while (1);
      }
      else {
          sleep(1);
          result = (int *) shmat (shmid, NULL, 0);
          result[0] = atoi (argv[2]) + atoi (argv[1]);
          printf (&quot;Result in parent process %d: %d.\n&quot;, getpid() , result[0]);
          printf (&quot;Send a SIGCONT to process %d.\n\n&quot;, pid);
          shmdt (result);
          kill (pid, SIGCONT);
          wait(NULL);
          printf (&quot;\nThis is the End.\n&quot;);
      }
    return 0;
  }
  
  void sigcont(int shmid){
      printf(&quot;Get a SIGCONT.\n&quot;);
      printf(&quot;Result in child process ID: %d.\n&quot;, getpid());
      exit(0);
  }
  </code></pre>
  <p>What I have tried:</p>
  <ol>
  <li><p>Put one parameter in void sigcont(int shmid);
  As I am learning from <a href="https://www.geeksforgeeks.org/signals-c-set-2/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/signals-c-set-2/</a>. Do signal() and kill() must use in pair? I get Thus, I tried to pass a value to it. Not working.</p>
  </li>
  <li><p>Sigstop() and Sigcont()
  I tried to avoid using signal() in my child process so that I can access shmid directly. But I couldn't find a lot of examples of Sigstop() and Sigcont(). It fails as well.</p>
  </li>
  </ol>
  <p>It's really hard to get my desired result even it looks simple. Can anyone help with this? Any help is appreciated.</p>