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

//----//
// xz //
//----//
void pr1(int data_pipe[]) {
close(data_pipe[1]);
printf("out123");
}

void pr2(int data_pipe[]) {
close(data_pipe[1]);
printf("out2321");
}

void pr3(int data_pipe[], char* file) {
int c;
int chr;
FILE *f;
close(1);
f = fopen(file,"w");
close(data_pipe[1]);
while ((chr = read(data_pipe[0], &c, 1)) > 0) {
    fprintf(stdout,"%c",c);
}
exit(0);
}

int main(int argc, char* argv[]) {
int data_pipe[2]; 
int pid;
int rc;
rc = pipe(data_pipe);
if (rc == -1) {
	perror("Pipe Err");
	exit(1);
}
pid = fork();
switch (pid) {
    case -1:
		perror("Fork Err");
		exit(1);
    case 0:
		pr1(data_pipe);
		pr2(data_pipe);
	
    default:
		pr3(data_pipe,argv[1]);
    }
return 0;
}
Соседние файлы в папке 2
  • #
    26.05.201411.88 Кб4a.out
  • #
    26.05.201431 б4f.dat
  • #
    26.05.201413 б4f.res
  • #
    26.05.2014823 б4q.c
  • #
    26.05.201431 б5res.txt