title: fork()/exec() in XWindow application
body: <p>How to execute <code>xterm</code> from XWindow program, insert it into my window, but continue execution both while xterm is active and after it was closed?</p>
  
  <p>In my XWindows (XLib over XCB) application I want to execute <code>xterm -Into &lt;handle&gt;</code>. So that my window contains <code>xterm</code> window in it. Unfortunately something wrong is happening. </p>
  
  <p>pseudo code:</p>
  
  <pre><code>if (fork() == 0) {
      pipe = popen('xterm -Into ' + handle);
      while (feof(pipe)) gets(pipe);
      exit(0);
  }
  </code></pre>
  
  <p>I tired <code>system()</code> and <code>execvp()</code> as well. Every thing is fine until I exit from <code>bash</code> that runs in <code>xterm</code>, then my program exits. I guess that connection to X server is lost because it is shared between parent and child.</p>
  
  <p>UPDATE: here is what is shown on terminal after program exits (or rather crashes).</p>
  
  <pre><code>XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0"
     after 59 requests (59 known processed) with 1 events remaining.
  [xcb] Unknown sequence number while processing queue
  [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
  [xcb] Aborting, sorry about that.
  y: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
  Aborted
  </code></pre>