zh-five / xdaemon Goto Github PK
View Code? Open in Web Editor NEWA library for writing system daemons in golang.
License: MIT License
A library for writing system daemons in golang.
License: MIT License
这里的打开文件代码,可能会重复调用,会不会有问题呢?
我是先 build,然后运行的可执行文件。环境 macOS。
楼主守护进程整的不错,能添加开机自启功能就更完美了!
代码如下非常简单
`func main() {
xdaemon.Background(".log", true)
r := gin.New()
r.Handle("GET", "/test", test)
r.Run(":3333")
}
func test(ginCtx *gin.Context) {
ginCtx.AbortWithStatus(400)
}`
步骤
1 、在CMD中执行 test.exe后,显示
启动子进程成功: -> 1600
2、在CMD中键盘ctrl+c
3、pid为1600的子进程已退出
使用这个库之后,编译好,直接双击启动程序,cmd窗口仍然还在。没有进入后台进程。
请问如何避免重复启动守护进程,比如2次执行 ./aaa 后,有4个aaa进程。
我想要关闭这些程序的时候 总是会去查看这个程序的进程pid 然后 kill 掉主程序 和主程序,感觉有点不方便,
怎么实现关闭?
mac m1电脑
运行example
日志
2022/10/08 16:29:01 83675 : 启动子进程成功: -> 83676
2022/10/08 16:29:01 守护进程(pid:83675; count:1/2; errNum:0/3): 监视到子进程(83676)退出, 共运行了0秒: signal: killed
2022/10/08 16:29:01 83675 : 启动子进程成功: -> 83677
2022/10/08 16:29:01 守护进程(pid:83675; count:2/2; errNum:1/3): 监视到子进程(83677)退出, 共运行了0秒: signal: killed
2022/10/08 16:29:01 守护进程(pid:83675; count:3/2; errNum:2/3): 重启次数太多退出
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.