鉴于此代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#define BUF_SIZE 256
int main()
{
int fd1[2];
int fd2[2];
ssize_t numRead = -1;
// remark : working under the assumption that the messages are of equal length
const char* messageOne = "Hello world , I'm child number 1\n";
const char* messageTwo = "Hello world , I'm child number 2\n";
const unsigned int commLen = strlen(messageOne) + 1;
char buf[BUF_SIZE];
if (pipe(fd1) == -1)
{
printf("Error opening pipe 1!\n"); …Run Code Online (Sandbox Code Playgroud)