Shows basic usage of anonymous pipes
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
int main(void)
{
int pipe_fds[2];
const int read_end = 0;
const int write_end = 1;
if(pipe(pipe_fds) < 0)
{
perror("Error creating pipe");
return 1;
}
const char* input = "This is a test input string";
write(pipe_fds[write_end], input, strlen(input)+1);
char buffer[256];
read(pipe_fds[read_end], buffer, sizeof(buffer)/sizeof(buffer[0]));
printf("Read '%s' from the pipe\n", buffer);
assert(strcmp(input, buffer) == 0);
return 0;
}