forked from wenjun1055/c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
8.8.c
38 lines (32 loc) · 832 Bytes
/
8.8.c
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
char *env_init[] = {"USER=unknown", "PATH=/tmp", NULL};
int main(void)
{
pid_t pid;
if ((pid = fork()) < 0) {
printf("fork error\n");
exit(-1);
} else if (0 == pid) {
if (execle("/home/sar/bin/echoall", "echoall", "myarg1", "MY ARG2", (char *)0, env_init) < 0) {
printf("execle error\n");
exit(-1);
}
}
if (waitpid(pid, NULL, 0) < 0) {
printf("wait error\n");
exit(-1);
}
if ((pid = fork()) < 0) {
printf("fork error\n");
exit(-1);
} else if (0 == pid) {
if (execlp("echoall", "echoall", "only 1 arg", (char *)0) < 0) {
printf("ececlp error\n");
exit(-1);
}
}
return 0;
}