-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait.c
61 lines (59 loc) · 1.51 KB
/
wait.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
54
55
56
57
58
59
60
61
/*======================================================
> File Name: wait.c
> Author: lyh
> E-mail:
> Other :
> Created Time: 2016年03月08日 星期二 20时19分21秒
=======================================================*/
#include<stdio.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
int main(int argc,char *argv[],char **environ)
{
int status = 0;
pid_t pid,ret;
pid = fork();
if(pid < 0)
{
printf("fork erro\n");
}
else if(pid==0)
{
printf("my process\n");
execve("./server/server",argv,environ);
}
else
{
printf("This is parent process with pid of %d\n",getpid());
while(pid>0)
{
ret = wait(&status);
if(ret == -1)
{
printf("no have child process\n");
}
else
{
// if(WIFEXITED(status))
// {
printf("this child process %d exit normally.\n",ret);
pid = fork();
if(pid < 0)
{
printf("fork erro\n");
}
else if(pid==0)
{
execve("./server/server",argv,environ);
}
// }
// else
// {
// printf("this child process %d exit abnormally.\n",ret);
// }
}
}
}
return 0;
}