-
Notifications
You must be signed in to change notification settings - Fork 0
/
zad42g.c
59 lines (52 loc) · 1.24 KB
/
zad42g.c
1
2
3
4
5
6
7
8
9
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
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char* argv[])
{
mkfifo("fifo1", 0600);
mkfifo("fifo2", 0600);
mkfifo("fifo3", 0600);
int pid = fork();
if(pid == 0)
{
pid = fork();
if(pid == 0){
pid = fork();
if(pid == 0)
{
close(1);
open("fifo3", O_WRONLY);
execlp("who", "who",(char *)NULL);
perror("who");
exit(1);
}
else{
close(1);
open("fifo2", O_WRONLY);
close(0);
open("fifo3", O_RDONLY);
execlp("cut", "cut", "-f1", "-d", " ", (char *)NULL);
perror("cut");
exit(1);
}
}
else{
close(1);
open("fifo1", O_WRONLY);
close(0);
open("fifo2", O_RDONLY);
execlp("sort", "sort", (char *)NULL);
perror("sort");
exit(1);
}
}
else{
close(0);
open("fifo1", O_RDONLY);
execlp("uniq", "uniq", "-c", (char *)NULL);
perror("uniq");
exit(1);
}
exit(0);
}