Write a program that illustrates how to execute two commands concurrently with a command pipe
AIM:
Write a program that illustrates how to execute two commands concurrently with a command pipe.
Program:
#include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <stdlib.h> int main() { int pfds[2]; char buf[30]; if(pipe(pfds)==-1) { perror("pipe failed"); exit(1); } if(!fork()) { close(1); dup(pfds[1]; system (“ls –l”); } else { printf("parent reading from pipe \n"); while(read(pfds[0],buf,80)) printf("%s \n" ,buf); } }
Output:
[student@gcet ~]$ vi pipes2.c [student@gcet ~]$ cc pipes2.c [student@gcet ~]$ ./a.out Parent reading from pipe Total 24 -rwxrwxr-x l student student 5563Aug 3 10:39 a.out -rw-rw-r—l Student student 340 jul 27 10:45 pipe2.c -rw-rw-r—l student student Pipes2.c -rw-rw-r—l student student 401 34127 10:27 pipe2.c student
-
UpdatedOct 23, 2014
-
Views22,141
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.