Witam, mam problem z programem, w którym proces macierzysty będzie czytał z pliku tekst umieszczał go w potoku nienazwanym a proces potomny odbierał tekst i pisał go do pliku. Poniżej mój kod. Program się kompiluje, ale plik wyjściowy nie daje się otworzyć. Nie bardzo wiem, gdzie robię błąd. Z góry dzięki za pomoc.

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/param.h>

int main(int argc, char *argv[])
{
int fd[2], nbytes, in_des, out_des;
char *in="in", *out="out", buf[PIPE_BUF];
if(argc>1) { in = argv[1]; }/*nazwa pliku zrodlowego*/
if(argc>2) { out = argv[2]; }/*nazwa pliku docelowego*/

if(pipe(fd) == -1)
{
perror("pipe error");
exit(EXIT_FAILURE);
}
else
{
pid_t pid = fork();
switch(pid)
{
	case -1:/*obsluga bledu fork*/
		perror("fork error");
		exit(EXIT_FAILURE);
		break;

	case 0:/*proces potomny*/
		if(close(fd[1])==-1)
		{
		perror("close error -p potomny -deskryptor potoku do zapisu");
		exit(EXIT_FAILURE);
		}
		if(read(fd[0], buf, PIPE_BUF) == -1)
		{perror("read error -p potomny -czytanie z potoku");
		exit(EXIT_FAILURE);}
		if(close(fd[0]) == -1)
		{perror("close error -p potomny -deskryptor potoku do odczytu");}
		out_des = open(out, O_WRONLY | O_CREAT, 0600);
		if(out_des == -1)
		{perror("open error - child process");
		exit(EXIT_FAILURE);}
		if(write(out_des, buf, PIPE_BUF) == -1)
		{perror("write error -p potomny -pisanie do pliku");
		exit(EXIT_FAILURE);}
		if(close(out_des) == -1)
		{perror("close error - deskryptor pliku docelowego");}
		break;

	default:/*proces macierzysty*/
		if( close(fd[0]) == -1)
		{perror("close error -p macierzysty -deskryptor potoku do odczytu");
		exit(EXIT_FAILURE);}
		in_des = open(in, O_RDONLY, 0600);
		if( in_des == -1)
		{perror("open error - mother process");
		exit(EXIT_FAILURE);}
		nbytes = read(in_des, buf, PIPE_BUF);
		if(nbytes == -1)
		{perror("read error");
		exit(EXIT_FAILURE);}
		if(close(in_des) == -1)
		{perror("close error - deskryptor pliku zrodlowego");
		exit(EXIT_FAILURE);}
		if(write(fd[1], buf, PIPE_BUF) == -1)
		{perror("write error -p macierzysty -pisanie do potoku");
		exit(EXIT_FAILURE);}
		if(close(fd[1]) == -1)
		{perror("close error -p macierzysty -deskryptor potoku do zapisu");
		exit(EXIT_FAILURE);}
		break;
}
}
return 0;
}