Design and Develop a program to demonstrate pipe function using dup system call.
AIM:
Design and Develop a program to demonstrate pipe function using dup system call.
Program:
#include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<unistd.h> int main() { int ptd[2]; char buff[30]; if(pie(ptd)==-1) { perror(“pipe failed”); exit(1); } if(!fork()) { printf(“CHILD:writing to the pipe\n”); write(ptd[1],”test”,5); printf(“CHILD: exiting\n”); exit(0); } else { printf(“PARENT:reading from pipe\n”); read(ptd[0],buf,5); printf(“PARENT: read \”%S “\n”,buff); wait(NULL); } }
Output:
Student@ubuntu:~$ gcc –o dup.out dup.c Student@ubuntu:~$./dup.out PARENT:reading from pipe CHILD:writing to the pipe CHILD: exiting PARENT: read testInitial Value.
-
UpdatedOct 23, 2014
-
Views2,187
You May Like
Write a Shell script to find factorial of a given integer.
Write in C the following Unix commands using system calls A). cat B). ls C). mv
Write a Shell script that displays list of all the files in the current directory to which the user has read, Write and execute permissions.
Write a Shell script that accepts a filename, starting and ending line numbers as arguments and displays all the lines between the given line numbers.
Write a C program to emulate the Unix ls-l command.
Write a Shell script to list all of the directory files in a directory.