-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1-5.c
More file actions
32 lines (26 loc) · 658 Bytes
/
1-5.c
File metadata and controls
32 lines (26 loc) · 658 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
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#define MAXLINE 100
int main()
{
char buf[MAXLINE];
pid_t pid;
int status;
printf("%% ");
while (fgets(buf, MAXLINE, stdin) != NULL) {
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = 0;
if ((pid = fork()) < 0) {
err_sys("fork error!");
} else if (0 == pid) {
execlp(buf, buf, (char *)0);
err_ret("couldn't execute: %s", buf);
exit(127);
}
if (pid = waitpid(pid, &status, 0) < 0)
err_sys("waitpid error!");
printf("%% ");
}
exit(0);
}