#include<unistd.h> /* pipe() */
#include<stdio.h>
#include<sys/types.h> /* pid_t */
#define MAXLINE 4096
int main(void)
{
int n;
int fd[2];
pid_t pid;
char line[MAXLINE];
//创建管道
if(pipe(fd)<0)
printf("pipe error\n");
//创建子进程
if((pid=fork())<0)
printf("fork error\n");
else if(pid>0) /* parent*/
{
close(fd[0]);
write(fd[1], "ls -l", 6);
}else /* child*/
{
n = read(fd[0], line, MAXLINE);
if (line[strlen(line)-1] == '\n')
line[strlen(line)-1] = '\0';
system(line);
}