前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在AMD PetaLinux的systemd里启动后台命令的注意事项

在AMD PetaLinux的systemd里启动后台命令的注意事项

作者头像
hankfu
发布2023-10-16 18:38:41
1500
发布2023-10-16 18:38:41
举报
文章被收录于专栏:hank

由于客户需要,需要在Linux里启动服务,使一个脚本在后台一直运行。

于是创建一个systemd服务,使其运行顶层脚本,再在其中以后台运行方式启动另外一个长期运行脚本。

结果发现,后台运行的长期运行脚本,过一段时间也退出了。

经过调试和分析,发现systemd创建的后台进程,以“Type=forking”方式运行,就不会退出。

按文档 systemd.service , “Type=forking” 表示子进程作为服务的主进程。这说明以“Type=forking”方式运行的后台进程,是正确的模式。

代码语言:javascript
复制
 •   If set to forking, it is expected that the process
               configured with ExecStart= will call fork() as part of
               its start-up. The parent process is expected to exit when
               start-up is complete and all communication channels are
               set up. The child continues to run as the main service
               process, and the service manager will consider the unit
               started when the parent process exits. This is the
               behavior of traditional UNIX services. If this setting is
               used, it is recommended to also use the PIDFile= option,
               so that systemd can reliably identify the main process of
               the service. systemd will proceed with starting follow-up
               units as soon as the parent process exits.
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-08-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档