-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.cpp
More file actions
58 lines (56 loc) · 1.28 KB
/
Copy pathsource.cpp
File metadata and controls
58 lines (56 loc) · 1.28 KB
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 <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
void who_wc()
{
int pipe1[2];
int pipe2[2];
int pipe3[2];
pipe(pipe1);
pipe(pipe2);
if (!fork())
{
if (!fork())
{
close(STDOUT_FILENO);
dup2(pipe1[1], STDOUT_FILENO);
close(pipe1[0]);
close(pipe1[1]);
close(pipe2[0]);
close(pipe2[1]);
execlp("ls", "ls", NULL);
}
else
{
close(STDOUT_FILENO);
close(STDIN_FILENO);
dup2(pipe1[0], STDIN_FILENO);
dup2(pipe2[1], STDOUT_FILENO);
close(pipe1[0]);
close(pipe1[1]);
close(pipe2[0]);
close(pipe2[1]);
execlp("grep", "grep", "sour*", NULL);
}
} else
{
char path[] = "//home//box//result.out";
FILE* file = fopen(path, "w");
close(STDIN_FILENO);
close(STDOUT_FILENO);
dup2(pipe2[0], STDIN_FILENO);
dup2(fileno(file), STDOUT_FILENO);
close(pipe1[0]);
close(pipe1[1]);
close(pipe2[0]);
close(pipe2[1]);
fclose(file);
execlp("wc", "wc", "-l", NULL);
}
}
int main (int argc, char ** argv)
{
who_wc();
return 0;
}