>Зря ты кусок обрезал. Так и не поймешь что, как и куда
>ты выносишь. Весь код в студию. Вот, пожалуйста. При пересылке почему-то теряются отступы, смотреть страшно:)
/********************Начало**************************/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
char *output_file[] = {"out1", "out2"};
struct {
int pid;
int status;
int fd[2];
} task[2];
#define BIG_SIZE 5000
char big_string[BIG_SIZE];
int run_child(char *output, int *fd)
{
int out;
int c;
dup2(fd[0], 0);
close(fd[0]);
close(fd[1]);
if(-1 != (out = open(output, O_CREAT | O_TRUNC | O_WRONLY, S_IREAD | S_IWRITE))){
dup2(out, 1);
close(out);
execlp("cat", "cat", NULL);
}
exit(0);
return 0;
}
main()
{
int i;
for(i = 0; i < BIG_SIZE; i++)
big_string[i] = 'a';
for(i = 0; i < 2; i++)
if(pipe(task[i].fd) < 0){
printf("Pipe error\n");
exit(1);
}
for(i = 0; i < 2; i++){
if(0 > (task[i].pid = fork())){
printf("Fork error !\n");
exit(2);
}
if(task[i].pid == 0)
run_child(output_file[i], task[i].fd);
/**********Когда пишу здесь, то работает************************
close(task[i].fd[0]);
write(task[i].fd[1], big_string, BIG_SIZE);
close(task[i].fd[1]);
*******************************************/
}
/**************Если пишу здесь, то не работает********/
for(i = 0; i < 2; i++){
close(task[i].fd[0]);
write(task[i].fd[1], big_string, BIG_SIZE);
close(task[i].fd[1]);
}
/******************************************/
for(i = 0; i < 2; i++)
waitpid(task[i].pid, &task[i].status, 0);
return 0;
}
/****************Конец***********************/
$uname -a
Linux localhost.localdomain 2.4.3-20mdk #1 Sun Apr 15 23:03:10 CEST 2001 i686 unknown