golang 中创建daemon的方法
https://github.com/takama/daemon
https://github.com/immortal/immortal/blob/master/fork.go 这个是比较原始的最接近c语言的实现,它里面还有很多原始c语言的东西的golang实现:
// fork.go
package immortal import (
"os"
"os/exec"
"syscall"
) // Fork crete a new process
func Fork() (int, error) {
args := os.Args[:]
cmd := exec.Command(os.Args[], args...)
cmd.Env = os.Environ()
cmd.Stdin = nil
cmd.Stdout = nil
cmd.Stderr = nil
cmd.ExtraFiles = nil
cmd.SysProcAttr = &syscall.SysProcAttr{
// Setsid is used to detach the process from the parent (normally a shell)
//
// The disowning of a child process is accomplished by executing the system call
// setpgrp() or setsid(), (both of which have the same functionality) as soon as
// the child is forked. These calls create a new process session group, make the
// child process the session leader, and set the process group ID to the process
// ID of the child. https://bsdmag.org/unix-kernel-system-calls/
Setsid: true,
}
if err := cmd.Start(); err != nil {
return , err
}
return cmd.Process.Pid, nil
}
golang 中创建daemon的方法的更多相关文章
- Linux中创建Daemon进程的三种方法
什么是daemon进程? Unix/Linux中的daemon进程类似于Windows中的后台服务进程,一直在后台运行运行,例如http服务进程nginx,ssh服务进程sshd等.注意,其英文拼写为 ...
- 说说Python多线程中的daemon属性方法
大家看多线程部分的时候肯定看到过daemon这个属性,当我在百度了一圈后也没发现有比较好的解释(或者大家对这个解释都非常清楚),于是自己通过代码和官方介绍了解它,进行了一些总结 给大家一些参考. 首先 ...
- 你能用Java覆盖静态方法吗?如果我在子类中创建相同的方法是编译时错误?
不,你不能在Java中覆盖静态方法,但在子类中声明一个完全相同的方法不是编译时错误,这称为隐藏在Java中的方法.你不能覆盖Java中的静态方法,因为方法覆盖基于运行时的动态绑定,静态方法在编译时使用 ...
- cocos2d-x js 中创建node的方法
1.精灵Sprite 一共4种创建方式 (1) 根据图片资源路径创建 1 2 3 4 //参数1:图片资源路径 var sprite1 = cc.Sprite.create("res/zif ...
- js中创建数组的方法
1.声明或创建一个不指定长度的数组(Array)的方式为: 如:var arrayObj = new Array(); 2.声明或创建一个数组并指定长度的数组(Array)的方式为: 如:var ar ...
- eclipse中创建类和方法自动注释
<?xml version="1.0" encoding="UTF-8"?><templates><template autoin ...
- centos6中创建软raid方法
raid概述: 组建raid阵列命令: mdadm:模式化的工具 /etc/mdadm.conf -A Assemble 装配模式 -C Create 创建模式 -C:专用 ...
- golang中字符串的查找方法小结
1)func Contains(s, substr string) bool这个函数是查找某个字符是否在这个字符串中存在,存在返回true 示例如下: import ( "fmt" ...
- [转]MySql中创建序列的方法
CREATE TABLE `my_seq` ( `seq` int(10) NOT NULL default 10000) ENGINE=MyISAM DEFAULT CHARSET=utf8 ...
随机推荐
- Tiobe最新编程语言排行
https://www.tiobe.com/tiobe-index/
- [原]openstack-kilo--issue(八)NovaException: Unexpected vif_type=binding_failed
2016-12-06 11:11:22.593 1505 INFO nova.scheduler.client.report [req-43897fe4-800f-436a-a13b-1a0098c8 ...
- win2008在组件服务中未找到office组件服务
在win2003系统,cmd中输入 dcomcnfg ,组件服务里面找到office的组件服务,但win2008 R2 64位操作系统需要输入comexp.msc -32 tks:http://www ...
- db2 删除过期的日志和备份文件(转)
DB2 删除过期备份和日志 $ db2 list history archive log all forpayment2 ------列出归档日志 $ db2 list history back ...
- F#周报2018年第52期
新闻 Sudokube--使用Fable开发的数独立方体 Rust 2019年及以后的发展 视频及幻灯片 我爱F#代码 马蒂亚斯·布兰在Developer On Fire上的演讲--有条理的和有趣的 ...
- Chap6:风险与监督[《区块链中文词典》维京&甲子]
- tp5, laravel, yii2我该选择哪个
为什么写这篇文章 我个人有一个技术群,里面学什么框架的都有,经常会有人问 某某功能 在 哪个框架怎么实现,用什么框架实现更好,说道这里我大家讲一个同类型问题的笑话 某女:你能让这个论坛的人都吵起来,我 ...
- 20165317 学习基础和C语言基础调查
学习基础和C语言基础调查 关于优势技能 说来惭愧,读书多年,爱好不少,但是真的能拿的出手的.能被叫做特长的不多.至今,能在同龄人中处于较领先位置的也只有从四年级开始练起的乒乓球.记得开始练习乒乓球是从 ...
- LeetCode 104 Maximum Depth of Binary Tree 解题报告
题目要求 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...
- LeetCode 700 Search in a Binary Search Tree 解题报告
题目要求 Given the root node of a binary search tree (BST) and a value. You need to find the node in the ...