Linux -
Richard Stevens Advanced Programming in the UNIX Environment
UNIX
Linux
IPCInterProcess Communication Unix
Unix
Linux
Unix
2.3.1
pipe
#include <unistd.h>
int pipe(int filedis[2])
filedis filedes[0] filedes[1]
filedes[1] filedes[0]
#define INPUT 0
#define OUTPUT 1
void main() {
int file_descriptors[2];
/* */
pid_t pid;
char buf[256];
int returned_count;
/* */
pipe(file_descriptors);
/* */
if((pid = fork()) == -1) {
printf("Error in fork");
exit(1);
}
/* */
if(pid == 0) {
printf("in the spawned (child) process...");
/* */
close(file_descriptors[INPUT]);
write(file_descriptors[OUTPUT], "test data", strlen("test data"));
exit(0);