小编Wor*_*ink的帖子

如何让RUST在后台优雅运行并守护进程?

这就是我想要实现的目标

\n\n
root> ./webserver start   // Does not block the terminal after startup, runs in the background and the process is guarded\nroot> \n
Run Code Online (Sandbox Code Playgroud)\n\n

我当前的实现逻辑\xef\xbc\x9a

\n\n逻辑在后台运行\n\n
root> ./webserver start   // Does not block the terminal after startup, runs in the background and the process is guarded\nroot> \n
Run Code Online (Sandbox Code Playgroud)\n\n

这样rust就会在后台运行,不会阻塞终端,但是rust在后台打印的信息仍然会显示在终端上,退出终端时当前的rust程序也会退出

\n\n进程守护程序逻辑\n\n

我的想法是监听系统的退出信号,不处理退出请求

\n\n
SIGHUP       1          /* Hangup (POSIX).  */                  \nSIGINT       2          /* Interrupt (ANSI).  */                       \nSIGQUIT      3          /* Quit (POSIX).  */                        \nSIGTERM      15         /* Termination (ANSI).  */               \n
Run Code Online (Sandbox Code Playgroud)\n\n

代码:

\n\n …

service daemon rust

8
推荐指数
1
解决办法
8647
查看次数

标签 统计

daemon ×1

rust ×1

service ×1