-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopyq2.c
More file actions
45 lines (39 loc) · 721 Bytes
/
copyq2.c
File metadata and controls
45 lines (39 loc) · 721 Bytes
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/wait.h>
int main(int argc, char *argv[]){
pid_t pid;
int p[2];
if(argc < 3){
// printf("Invalid amount of arguments\n");
// exit(1);
}
for(int i = 0; i <= argc; i++){
argv[i -1] = argv[i];
}
pipe(p);
pid = fork();
if(pid == 0){
puts("Starting Child");
puts("Please Enter city then population. Hit ctrl D to finish");
close(p[0]);
dup2(p[1], 1);
close(p[1]);
execvp(argv[0], argv);
}
else if(pid > 0){
wait(NULL);
printf("Starting Parent");
close(p[1]);
dup2(p[0], 0);
close(p[0]);
execvp(argv[1], argv);
}
else{
printf("\nError bad PID\n");
exit(1);
}
}