Получается нечто подобное:
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
int fd1, fd2;
int pid2, pid3, st, i, n;
char* buffer;
char ch = 'a';
void main(int argc, char *argv[])
{
if (argc < 4)
{
puts("File no found.");
}
else
{
n = atoi(argv[2]);
fd1 = open(argv[1], O_CREAT | O_WRONLY);
pid2 = fork();
if (pid2 == 0)/* process 2 */
{
for (i = 0; i < n; i++)
{
write(fd1, &ch, sizeof(char));
ch++;
}
}
else /* process 1 */
{
pid3 = fork();
if (pid3 == 0) /* process 3 */
{
for (i = 0; i < n; i++)
{
write(fd1, &ch, sizeof(char));
ch++;
}
}
waitpid(pid2, &st, 0);
waitpid(pid3, &st, 0);
close(fd1);
fd2 = open(argv[1], O_RDONLY);
read(fd2, buffer, 2*n);
printf("Process buffer %s:", buffer);
close(fd2);
}
}
exit(0);
}