Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
5
Добавлен:
26.05.2014
Размер:
908 б
Скачать
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

main()
{
 pid_t pid1,pid2;
 int fd1,fd2;
 int fd[2];
 int buf1,buf2;
 int in,out;
 switch (pid1=fork())	{	
	case 0:
	close(0);
	close(1);
	fd1=open("f.dat",O_RDONLY);
	fd2=open("f.res",O_TRUNC|O_CREAT|O_WRONLY,0666);
	execl("/bin/cat","cat","-b",(char *)0);
//-----------------------------	
	default:
	wait((int *)0);
	printf("pr 1 pico\n");
	
	in=dup(0);
	buf1=dup(0);
	buf2=dup(1);
	pipe(fd);

	switch(pid2=fork())
	{
	case 0:
	printf("open ls\n");
	out=fd[1];
	dup2(in,0);
	dup2(out,1);
	close(in);
	close(out);
	execl("/bin/ls","ls",(char *)0);
	
//	switch(pid2=fork())
//	{
//	case 0:

	default:		
	wait((int *)0);
	printf("open wc\n");
	in=fd[0];
	dup2(in,0);
	close(1);
	fd2=open("f.res",O_WRONLY|O_APPEND);
//	dup2(out,1);
//	close(in);
//	close(out);
	execl("/bin/wc","wc",(char *)0);
	}
}
}
Соседние файлы в папке pip
  • #
    26.05.201411.91 Кб6a.out
  • #
    26.05.201421 б5f.dat
  • #
    26.05.201424 б5f.res
  • #
    26.05.2014908 б5l2.c
  • #
    26.05.20141.07 Кб5lb2.c
  • #
    26.05.2014513 б6pip.c
  • #
    26.05.2014567 б5pip2.c