{       sleep(1);       rnum=read(pipe_fd[0],r_buf,1000);       printf("child: readnum is %d\n",rnum);     }     close(pipe_fd[0]);          exit();   }   else if(pid>0)   {     close(pipe_fd[0]);//write     memset(r_buf,0,sizeof(r_buf));     if((writenum=write(pipe_fd[1],w_buf,1024))==-1)       printf("write to pipe error\n");     else       printf("the bytes write to pipe is %d \n", writenum);     writenum=write(pipe_fd[1],w_buf,4096);     close(pipe_fd[1]);   } } 
  输出结果: 
the bytes write to pipe 1000 the bytes write to pipe 1000  //注意,此行输出说明了写入的非原子性 the bytes write to pipe 1000 the bytes write to pipe 1000 the bytes write to pipe 1000 the bytes write to pipe 120  //注意,此行输出说明了写入的非原子性 the bytes write to pipe 0 the bytes write to pipe 0 ...... 
  结论: 
  写入数目小于4096时写入是非原子的! 
  如果把父进程中的两次写入字节数都改为5000,则很容易得出下面结论: 
  写入管道的数据量大于4096字节时,缓冲区的空闲空间将被写入数据(补齐),直到写完所有数据为止,如果没有进程读数据,则一直阻塞。 
  1.4 管道应用实例 
  实例一:用于shell 
  管道可用于输入输出重定向,它将一个命令的输出直接定向到另一个命令的输入。比如,当在某个shell程序(Bourne shell或C shell等)键入who│wc -l后,相应shell程序将创建who以及wc两个进程和这两个进程间的管道。考虑下面的命令行: 
$kill -l 
  运行结果见 附一。 
$kill -l | grep SIGRTMIN 
  运行结果如下: 
30) SIGPWR31) SIGSYS32) SIGRTMIN33) SIGRTMIN+1 34) SIGRTMIN+235) SIGRTMIN+336) SIGRTMIN+437) SIGRTMIN+5 38) SIGRTMIN+639) SIGRTMIN+740) SIGRTMIN+841) SIGRTMIN+9 42) SIGRTMIN+1043) SIGRTMIN+1144) SIGRTMIN+1245) SIGRTMIN+13 46) SIGRTMIN+1447) SIGRTMIN+1548) SIGRTMAX-1549) SIGRTMAX-14 
		    
                       
		      
		      
		   |