zoukankan      html  css  js  c++  java
  • 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[1:] cmd := exec.Command(os.Args[0], 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 0, err } return cmd.Process.Pid, nil }
  • 相关阅读:
    2.2.16锁对象的改变
    2.2.15内置类与同步:测试2
    2.2.14内置类与同步:测试1
    2.2.13内置类与静态内置类
    libev客户端
    Linux下sqlite3编程
    ds18b20驱动及应用程序
    ds18b20采集温度并上报服务器
    linux下GPRS模块ppp拨号上网
    linux下GPRS模块的应用程序
  • 原文地址:https://www.cnblogs.com/welhzh/p/9178034.html
Copyright © 2011-2022 走看看