英文:
Can I daemonize a golang process without external tools?
问题
我看到了很多关于如何在Go中将应用程序变为守护进程的建议,包括使用upstart或init.d。但是,为什么不自己来做呢?这些步骤似乎很简单:
- 分叉并退出父进程
- 更改文件模式掩码
- 创建唯一的会话ID
- 更改当前工作目录
- 关闭文件描述符
(来源:1)
那么,为什么不在你的程序中自己完成这些步骤,而要依赖第三方软件来完成这个简单的任务呢?
英文:
I've seen many different suggestions for how to daemonize an application written in Go, including using upstart or init.d. Why not just do it yourself though? It seems like the steps are simple enough:
- Fork and exit parent
- Change file mode mask
- Create a unique session id
- Change current working directory
- Close file descriptors
(source)
So why not just do this in your program, rather than depending on third party software to do a simple task for you?
答案1
得分: 1
直接在Go程序中使用fork()是危险的。基于等效的C程序的典型守护进程实现是不安全的。
您可能对以下软件包使用的方法感兴趣:
https://github.com/VividCortex/godaemon
英文:
Messing directly with fork() from a Go program is perilous. A typical deamonize implementation based on an equivalent C program is not safe.
You may be interested by the approach used by the following package:
https://github.com/VividCortex/godaemon
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论