Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
62543202
Commit
62543202
authored
Mar 27, 2022
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
精简进程管理相关代码
parent
ae99662a
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
18 行增加
和
26 行删除
+18
-26
server/Process.cpp
+18
-26
没有找到文件。
server/Process.cpp
查看文件 @
62543202
...
...
@@ -48,15 +48,14 @@ static void setupChildProcess() {
}
/* Start function for cloned child */
static
int
runChildProcess
(
const
string
&
cmd
,
string
&
log_file_tmp
)
{
static
int
runChildProcess
(
string
cmd
,
string
log_file
)
{
setupChildProcess
();
string
log_file
;
if
(
log_file_tmp
.
empty
())
{
if
(
log_file
.
empty
())
{
//未指定子进程日志文件时,重定向至/dev/null
log_file
=
"/dev/null"
;
}
else
{
log_file
=
StrPrinter
<<
log_file
_tmp
<<
"."
<<
getpid
();
log_file
=
StrPrinter
<<
log_file
<<
"."
<<
getpid
();
}
//重定向shell日志至文件
...
...
@@ -103,19 +102,17 @@ static int cloneFunc(void *ptr) {
#endif
void
Process
::
run
(
const
string
&
cmd
,
string
&
log_file
_tmp
)
{
void
Process
::
run
(
const
string
&
cmd
,
string
&
log_file
)
{
kill
(
2000
);
#ifdef _WIN32
STARTUPINFO
si
=
{
0
};
PROCESS_INFORMATION
pi
=
{
0
};
string
log_file
;
if
(
log_file_tmp
.
empty
())
{
if
(
log_file
.
empty
())
{
//未指定子进程日志文件时,重定向至/dev/null
log_file
=
"NUL"
;
}
else
{
log_file
=
StrPrinter
<<
log_file
_tmp
<<
"."
<<
getCurrentMillisecond
();
log_file
=
StrPrinter
<<
log_file
<<
"."
<<
getCurrentMillisecond
();
}
log_file_tmp
=
log_file
;
//重定向shell日志至文件
auto
fp
=
File
::
create_file
(
log_file
.
data
(),
"ab"
);
...
...
@@ -144,39 +141,34 @@ void Process::run(const string &cmd, string &log_file_tmp) {
WarnL
<<
"start child process fail: "
<<
get_uv_errmsg
();
}
fclose
(
fp
);
#elif ((defined(__linux) || defined(__linux__)))
#else
#if (defined(__linux) || defined(__linux__))
_process_stack
=
malloc
(
STACK_SIZE
);
auto
args
=
std
::
make_pair
(
cmd
,
log_file
_tmp
);
int
pid
=
clone
(
reinterpret_cast
<
int
(
*
)(
void
*
)
>
(
&
cloneFunc
),
(
char
*
)
_process_stack
+
STACK_SIZE
,
CLONE_FS
|
SIGCHLD
,
(
void
*
)(
&
args
));
if
(
pid
==
-
1
)
{
auto
args
=
std
::
make_pair
(
cmd
,
log_file
);
_
pid
=
clone
(
reinterpret_cast
<
int
(
*
)(
void
*
)
>
(
&
cloneFunc
),
(
char
*
)
_process_stack
+
STACK_SIZE
,
CLONE_FS
|
SIGCHLD
,
(
void
*
)(
&
args
));
if
(
_
pid
==
-
1
)
{
WarnL
<<
"clone process failed:"
<<
get_uv_errmsg
();
free
(
_process_stack
);
_process_stack
=
nullptr
;
throw
std
::
runtime_error
(
StrPrinter
<<
"fork child process failed,err:"
<<
get_uv_errmsg
());
}
_pid
=
pid
;
if
(
log_file_tmp
.
empty
())
{
InfoL
<<
"start child process "
<<
_pid
<<
", log file:"
<<
"/dev/null"
;
}
else
{
InfoL
<<
"start child process "
<<
_pid
<<
", log file:"
<<
log_file_tmp
.
c_str
()
<<
"."
<<
_pid
;
}
#else
_pid
=
fork
();
if
(
_pid
<
0
)
{
if
(
_pid
==
-
1
)
{
throw
std
::
runtime_error
(
StrPrinter
<<
"fork child process failed,err:"
<<
get_uv_errmsg
());
}
if
(
_pid
==
0
)
{
//子进程
exit
(
runChildProcess
(
cmd
,
log_file
_tmp
));
exit
(
runChildProcess
(
cmd
,
log_file
));
}
string
log_file
;
if
(
log_file_tmp
.
empty
())
{
#endif
if
(
log_file
.
empty
())
{
//未指定子进程日志文件时,重定向至/dev/null
log_file
=
"/dev/null"
;
}
else
{
log_file
=
StrPrinter
<<
log_file
_tmp
<<
"."
<<
_pid
;
log_file
=
StrPrinter
<<
log_file
<<
"."
<<
_pid
;
}
log_file_tmp
=
log_file
;
InfoL
<<
"start child process "
<<
_pid
<<
", log file:"
<<
log_file
;
#endif // _WIN32
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论