如何派生流程 [英] How to fork a process

查看:83
本文介绍了如何派生流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来了解如何在Go中妖魔化一个过程.

I need help understanding how to demonize a process in Go.

package main

import (
   "fmt"
   "os"
)

func start() {
   var procAttr os.ProcAttr 
   procAttr.Files = []*os.File{nil, nil, nil}
   _, err := os.StartProcess("/Path/prog", nil, &procAttr)
   if err != nil {
       fmt.Printf("%v", err)
   }
}


func main () {
   start()
} 

如果在命令行上启动此代码,则程序将返回控制权,但仍与cmd连接.关闭cmd将关闭程序.

If you start this code on the command line the program returns control, but is still connected with cmd. Closing the cmd closes the program.

如何将其与cmd分离?添加:

How can I decouple it from the cmd? Adding:

procAttr.Sys.HideWindow = true

导致此错误:对错误的内存指针恐慌"

Results in this error: "panic" to wrong memory pointer

推荐答案

我在'golang-nuts'中询问,发现golang具有链接选项:

I asked in 'golang-nuts', and found out that golang has a link option:

go tool 8l -o output.exe -Hwindowsgui input.8

这篇关于如何派生流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆