-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortFile.c
More file actions
39 lines (39 loc) · 773 Bytes
/
sortFile.c
File metadata and controls
39 lines (39 loc) · 773 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
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<sys/wait.h>
#include<sys/types.h>
int main(int argc, char *argv[]){
int fd = open(argv[1],O_RDONLY);
if(fd<0){
printf("Illegal command or arguements\n");
exit(0);
}
dup2(fd,0);
//char input[10000];
//int c=read(0,input,10000);
int status;
pid_t child;
fflush(stdout);
child = fork();
fflush(stdout);
if (child!=0){
waitpid(child, &status, 0);
char input[10000];
int c=read(0,input,10000);
int i=0;
for(i=0;i<c;i++){
printf("%c",input[i]);
}
}
else{
char *eargs[]={"sort","-f",NULL};
fflush(stdout);
execvp("sort",eargs);
fflush(stdout);
}
}