title: making a child to wait for parent in fork()
body: <p>This program gets a sentence in parent process and prints it in upper case in child process. I want the child to wait for the parent. I used sleep() to make the child process to wait. Is there any method of making a child to wait for the parent ? Can i implement that with signal() ? Thanks in advance!!!</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;unistd.h&gt;
  #include&lt;sys/types.h&gt;
  #include&lt;sys/wait.h&gt;
  #include&lt;sys/ipc.h&gt;
  #include&lt;sys/shm.h&gt;
  #include&lt;ctype.h&gt;
  #define size 50
  main()
  {
      int pid,shmid,i,key=1234;
      char *name,*shmaddr;
      if((shmid=shmget(key,size,IPC_CREAT | 0666)) &lt; 0)
      {
          perror("shmget():");
          exit(1);
      }
      pid=fork();
      if(pid &lt; 0)
      {
          perror("fork():");
          exit(1);
      }
      else if(pid == 0)
      {
          sleep(5); //making child to wait for parent
          printf("\t\tCHILD\n\n");
          if((shmaddr=shmat(shmid,NULL,0)) == (char*) -1)
          {
              perror("shmat():");
              exit(1);
          }
          name=shmaddr;
          i=0;
          while(name[i]!='\0')
          {
              printf("%c",toupper(name[i]));
              i++;
          }
          shmdt(shmaddr);
          printf("\n");
          exit(0);
      }
      else
      {
          printf("\t\tPARENT\n\n"); 
          if((shmaddr=shmat(shmid,NULL,0)) == (char*) -1)
          {
              perror("shmat():");
              exit(1);
          }
          name=shmaddr;
          i=0;
          while((name[i]=getchar()) != '\n')
          i++;
          name[i]='\0';
          shmdt(shmaddr);
          wait(NULL);
      }
  }
  </code></pre>