多进程 管道问题
Pipe3.c
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv)
{
int data_processed;
int file_pipes[2];
const char some_data[] = "123";
char buffer[BUFSIZ + 1];
pid_t fork_result;
memset(buffer, '\0', sizeof(buffer));
if(pipe(file_pipes) == 0)
{
fork_result = fork();
if(-1 == fork_result)
{
fprintf(stdout, "Fork failure\n");
exit(EXIT_FAILURE);
}
else if(0 == fork_result)
{
sprintf(buffer, "%d", file_pipes[0]);
printf("buffer address 0x%04X\n", buffer);
(void)execl("pipe4", "pipe4", buffer, (char*)0);
printf("execl failure\n");
exit(EXIT_FAILURE);
}
else
{
data_processed = write(file_pipes[1], some_data, strlen(some_data));
printf("Write %d bytes\n", data_processed);
wait(NULL);
printf("Child stopped\n");
}
}
exit(EXIT_SUCCESS);
}
pile4.c:
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv)
{
int data_processed;
char buffer[BUFSIZ + 1];
int file_descriptor;
memset(buffer, '\0', sizeof(buffer));
sscanf(argv[1], "%d", &file_descriptor);
printf("argv[1] address 0x%04X\n", argv[1]);
data_processed = read(file_descriptor, buffer, BUFSIZ);
printf("%d - read %d bytes: %s\n", getpid(), data_processed, buffer);
sleep(15);<