/* program on pipe */
# include <stdio.h>
# include <sys/types.h>
# include <stdlib.h>
# define MAXLINE 4096
int main()
{
int n,fd[2];
pid_t pid;
char line[MAXLINE];
if(pipe(fd)<0)
perror("pipe error..");
if((pid=fork())<0)
perror("fork error...");
else
if(pid>0)
{
close(fd[0]);
write(fd[1],"hello world\n",12);
}
else
{
close(fd[1]);
n=read(fd[0],line,MAXLINE);
write(1,line,n);
}
exit(0);
}
# include <sys/types.h>
# include <stdlib.h>
# define MAXLINE 4096
int main()
{
int n,fd[2];
pid_t pid;
char line[MAXLINE];
if(pipe(fd)<0)
perror("pipe error..");
if((pid=fork())<0)
perror("fork error...");
else
if(pid>0)
{
close(fd[0]);
write(fd[1],"hello world\n",12);
}
else
{
close(fd[1]);
n=read(fd[0],line,MAXLINE);
write(1,line,n);
}
exit(0);
}
No comments:
Post a Comment