- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
#include <unistd.h>
#include <stdlib.h>
int main(int argc,char* argv[])
{
int fdp1[2],fdp2[2],fdp3[2],fdp4[2],fdp5[2];
pipe(fdp1);
pipe(fdp2);
pipe(fdp3);
pipe(fdp4);
pipe(fdp5);
if(fork()==0){
close(1);dup(fdp1[1]);close(fdp1[1]);close(fdp1[0]);
execl("/bin/cat","cat",argv[1],(char*)0);
exit(1);
}
if(fork()==0){
close(0);dup(fdp1[0]);close(fdp1[0]);close(fdp1[1]);
close(1);dup(fdp2[1]);close(fdp2[1]);
execl("/usr/bin/tr","tr","-cs","A-Za-z","\n",(char*)0);
exit(2);
}
if(fork()==0){
close(0);dup(fdp2[0]);close(fdp2[0]);close(fdp2[1]);
close(fdp1[0]);close(fdp1[1]);
close(1);dup(fdp3[1]);close(fdp3[1]);close(fdp3[0]);
execl("/usr/bin/sort","sort",(char*)0);
exit(3);
}
if(fork()==0){
close(0);dup(fdp3[0]);close(fdp3[0]);close(fdp3[1]);
close(fdp1[0]);close(fdp1[1]);
close(fdp2[0]);close(fdp2[1]);
close(1);dup(fdp4[1]);close(fdp4[1]);
execl("/usr/bin/uniq","uniq","-c",(char*)0);
exit(4);
}
if(fork()==0){
close(0);dup(fdp4[0]);close(fdp4[0]);close(fdp4[1]);
close(fdp1[0]);close(fdp1[1]);
close(fdp2[0]);close(fdp2[1]);
close(fdp3[0]);close(fdp3[1]);
close(1);dup(fdp5[1]);close(fdp5[1]);
execl("/usr/bin/sort","sort","-n",(char*)0);
exit(5);
}
if(fork()==0){
close(0);dup(fdp5[0]);close(fdp5[0]);close(fdp5[1]);
close(fdp1[0]);close(fdp1[1]);
close(fdp2[0]);close(fdp2[1]);
close(fdp3[0]);close(fdp3[1]);
close(fdp4[0]);close(fdp4[1]);
execl("/usr/bin/tail","tail","-n",argv[2],(char*)0);
exit(6);
}
close(fdp1[0]);close(fdp1[1]);
close(fdp2[0]);close(fdp2[1]);
close(fdp3[0]);close(fdp3[1]);
close(fdp4[0]);close(fdp4[1]);
close(fdp5[0]);close(fdp5[1]);
while(wait(0)!=(-1));
exit(0);
}
задача: подсчет повторяемости слов, и вывод слов указанной длины.