It has been a long time since I used pipes, I/O duplication, and process forking in a C program. However, I need to remember how it is done. The UNIX command ls | wc is implemented this way in C.
pipe(p);
if ((pid1 = fork()) == 0) {
close(p[1]);
dup2(p[0],0);
close(p[0]);
execl("wc","wc",(char *)0);
exit(1);
}
if ((pid1 = fork()) == 0) {
close(p[0]);
dup2(p[1],1);
close(p[1]);
execl("ls","ls",(char *)0);
exit(1);
}
close(p[0]);
close(p[1]);
while(wait(&status) != pid1);
Subscribe to:
Post Comments (Atom)
Published Scholars in the Philippines
Using Google Scholar data, webometrics ranks 453 scientists in the Philippines (June 2016 report). Each of these scientists has at least an...
-
So much for the bubble -- the hokies are about to burst theirs. The yellow jackets are currently pulling away from the hokies. The tigers ho...
-
Written a program to generate a couple of reports, prepared a description of statistical analysis of ozone stress data, studied possible sta...
-
I thought the wolfpack would get a touchdown its last drive during the dying minutes of the 4th quarter. However, they came short and the ho...
1 comment:
i totally get this...not hehehe.
Post a Comment