-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (66 loc) · 1.16 KB
/
main.cpp
File metadata and controls
71 lines (66 loc) · 1.16 KB
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
62
63
64
65
66
67
68
69
70
71
#include "GameChannel.h"
#include "GameMsg.h"
#include "msg.pb.h"
#include "AOIWorld.h"
using namespace std;
extern RandomName random_name;
//守护进程函数
void safeguard()
{
int ipid = fork();
if (ipid < 0)
{
exit(-1);
}
//父进程退出
if (ipid > 0)
{
exit(0);
}
//子进程设置会话 脱离当前会话组
setsid();
//重定向守护进程的标准输入 输出 错误 到黑洞设备 使守护进程无法与终端进行IO交互
int nullfd = open("/dev/null", O_RDWR);
if (nullfd > 0)
{
dup2(nullfd, 0);
dup2(nullfd, 1);
dup2(nullfd, 2);
close(nullfd);
}
//进程监控
while (1)
{
int pid = fork();
if (pid < 0)
{
exit(-1);
}
else if (pid > 0)
{
int status = 0;
wait(&status);
if (status == 0)//说明是正常退出
{
exit(0);
}
}
else
{
//子进程跳出循环执行游戏业务
break;
}
}
}
int main()
{
safeguard();
random_name.LoadFile();
ZinxKernel::ZinxKernelInit();
/*添加监听通道*/
ZinxKernel::Zinx_Add_Channel(*(new ZinxTCPListen(9999, new GameConnFact())));
ZinxKernel::Zinx_Add_Channel(*(new ZinxTimerChannel()));
ZinxKernel::Zinx_Run();
ZinxKernel::ZinxKernelFini();
return 0;
}