-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.c
55 lines (49 loc) · 776 Bytes
/
command.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
#include<stdio.h>
#include <stdlib.h>
#include <unistd.h>
int pipe1[2];
int pipe2[2];
void exec1()
{
dup2(pipe1[1], 1);
close(pipe1[0]);
close(pipe1[1]);
execlp("cat", "cat","cmd.c", NULL);
// execlp("ls", "ls", NULL);
}
void exec2()
{
dup2(pipe1[0], 0);
dup2(pipe2[1], 1);
close(pipe1[0]);
close(pipe1[1]);
close(pipe2[0]);
close(pipe2[1]);
execlp("grep", "grep", "include", NULL);
//execlp("grep", "grep","e", NULL);
}
void exec3()
{
dup2(pipe2[0], 0);
close(pipe2[0]);
close(pipe2[1]);
execlp("grep", "grep", "std", NULL);
}
void main() {
pipe(pipe1);
if (fork() == 0)
{
exec1();
}
pipe(pipe2);
if (fork() == 0)
{
exec2();
}
close(pipe1[0]);
close(pipe1[1]);
if (fork() == 0)
{
exec3();
}
}