title: Why doesn't the shell prompt occur after I "cat" a FIFO special file or create a FIFO special file in my program?
body: <p>I'm learning named pipes in Linux and write the following program to try it out.</p>
  
  <p>The following program creates a FIFO special file named "test.fifo", then it creates two child processes to read and write from that named pipe.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;wait.h&gt;
  
  int main() {
      pid_t pid[2];
  
      // Create FIFO special file
      mkfifo("test.fifo", 0644);
  
      pid[0] = fork();
      if (pid[0] &lt; 0) {
          printf("Fail to fork child process #0\n");
          return 1;
      } else if (pid[0] == 0) {
          // Open FIFO special file in read mode
          int in = open("test.fifo", O_RDONLY);
  
          // Read data
          char buf[256];
          read(in, buf, 256);
          printf("Child process #0 received: %s\n", buf);
  
          // Close pipe
          close(in);
          return 0;
      }
  
      pid[1] = fork();
      if (pid[1] &lt; 0) {
          printf("Fail to fork child process #1\n");
          return 1;
      } else if (pid[1] == 0) {
          // Open FIFO special file in write mode
          int out = open("test.fifo", O_WRONLY);
  
          // Write data
          char buf[256] = {0};
          strcpy(buf, "Hello world");
          write(out, buf, 256);
  
          // Close pipe
          close(out);
          return 0;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Sometimes this program runs normally. But sometimes after this program runs, my shell prompt disappears.</p>
  
  <pre><code>MyUserName@MyHostName:~$ ./a.out
  MyUserName@MyHostName:~$ Child process #0 received: Hello world
  (This is an empty line, no shell prompt occurs)
  </code></pre>
  
  <p>I try to type and run the command <code>ls</code> in the empty line, and the command works. So it seems that the program has exited successfully, and it's just that the shell prompt doesn't occur.</p>
  
  <p>The same thing will happen if I run the command <code>cat test.fifo</code>.</p>
  
  <pre><code>MyUserName@MyHostName:~$ cat test.fifo
  (This is an empty line, no shell prompt occurs)
  </code></pre>
  
  <p>What's happening and why is this happening?</p>