PIPE
presented by,
K.ABINAYA II-MCA
AAMEC
P1
P2
PIPE
TWO TYPES
 Ordinary pipes
int pipe(int filedes[2]);
 Named pipes
NAMED PIPE
 It is also known as FIFO.
 mkfifo
int mkfifo(char * path, mode_t mode)
path - points to the pathname of a file
mode - access rights
WRITER
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
int fd;
char * myfifo = "/tmp/myfifo";
mkfifo(myfifo, 0666);
fd = open(myfifo, O_WRONLY);
write(fd, "Hi", sizeof("Hi"));
close(fd);
unlink(myfifo);
return 0;
}
READER
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#define MAX_BUF 1024
int main()
{
int fd;
char * myfifo = "/tmp/myfifo";
char buf[MAX_BUF];
fd = open(myfifo, O_RDONLY);
read(fd, buf, MAX_BUF);
printf("Received: %sn", buf);
close(fd);
return 0;
}
THANKYOU

Pipe