-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path7_3_4-childps.c
53 lines (41 loc) · 863 Bytes
/
7_3_4-childps.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* @Author: Nam
* @Date: 2018-04-28 18:39:17
* @Last Modified by: Nam
* @Last Modified time: 2018-05-15 04:56:57
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#define PROC_OK 0
#define PROC_NG -1
int main(int argc, char const *argv[]) {
printf("main :start\n");
char *args[] = {"ls", "-l", NULL};
int iRet = 0;
pid_t pid = 0;
int status = 0;
switch (pid = fork()) {
case -1: {
perror("processGenerate fork");
return 1;
}
case 0: {
iRet = execv("/bin/ls", args);
printf("execv ret = %d\n", iRet);
if (iRet == PROC_NG) {
return 1;
}
}
default: {
printf("Parent Process ChildProcPid = %d\n", pid);
pid = wait(&status);
printf("pid = %d, status = %d\n", pid, status);
break;
}
}
printf("main :end\n");
return 0;
}