Write C programs to implement ipc between two unrelated processes using named pipe

#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<unistd.h>
int main()
{
int pfds[2];
char buf[30];
if(pipe(pfds)==-1)
{
perror("pipe");
exit(1);
}
printf("writing to file descriptor #%d\n", pfds[1]);
write(pfds[1],"test hello",10);
printf("reading from file descriptor #%d\n ", pfds[0]);
read(pfds[0],buf,10);
printf("read\"%s\"\n" ,buf);
}output:
jethusai@jethusai-Lenovo-G560:~$ gedit pipe.c
jethusai@jethusai-Lenovo-G560:~$ gcc pipe.c
jethusai@jethusai-Lenovo-G560:~$ ./a.out
writing to file descriptor #4
reading from file descriptor #3
 read"test hello"

Comments

Popular posts from this blog

Write C programs to simulate the Paging techniques of memory management

Write C programs to simulate the Two level directory File organization technique

Write C programs to simulate the Hierarchical directory File organization technique