-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy path8.10.c
More file actions
29 lines (24 loc) · 691 Bytes
/
8.10.c
File metadata and controls
29 lines (24 loc) · 691 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
#include "apue.h"
#include <sys/wait.h>
char *env_init[] = {"USER=unknown", "PATH=/tmp", NULL};
int main() {
pid_t pid;
if ((pid = fork()) < 0) {
err_sys("fork error");
} else if (pid == 0) {
if (execle("/home/meik/apue/Chapter-08/echoall", "echoall", "myarg1", "MY ARG2", (char *)0, env_init) < 0) {
err_sys("execle error");
}
}
if (waitpid(pid, NULL, 0) < 0) {
err_sys("wait error");
}
if ((pid = fork()) < 0) {
err_sys("fork error");
} else if (pid == 0) {
if (execlp("./echoall", "echoall", "only 1 arg", (char *)0) < 0) {
err_sys("execlp error");
}
}
exit(0);
}