title: Bring process to foreground
body: <p>I have a process (which reads and writes to terminal type) that has been exec'd by a background process. I can see it using ps.
  Trying to bring it to foreground, this is what I attempted:</p>
  
  <pre><code>int main()
  
  {
  
      FILE* fd = popen("pidof my_program","r");
  
      // ...
      // Some code to get the pid of my_program as mpid
      //...
  
      printf("pid of my_program is %d",mpid);
      signal(SIGTTOU, SIG_IGN);
      setpgid(mpid,0); // Set program group id to pid of process
      tcsetpgrp(0,mpid); // Give it terminal stdin access
      tcsetpgrp(1,mpid); // Give it terminal stdout access
      return 0;
  }
  </code></pre>
  
  <p>It isn't working though. Can someone help me on this?
  Thanks.</p>