-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathA01569420
44 lines (33 loc) · 789 Bytes
/
A01569420
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
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
void execute_argument(char* argument) {
pid_t pid;
pid = fork();
if (pid < 0) {
fprintf(stderr, "Fork failed\n");
return;
} else if (pid == 0) {
execlp("ls", "-l", NULL);
fprintf(stderr, "Exec failed\n");
return;
} else {
int status;
waitpid(pid, &status, 0);
}
}
int main() {
char argument[100];
while (1) {
printf("osh> ls");
fgets(argument, sizeof(argument), stdin);
argument[strlen(argument) - 1] = '\0';
if (strcmp(argument, "exit") == 0) {
break;
}
execute_argument(argument);
}
return 0;
}