I need to start a new process in Go with the following requirements:
- The starting process should run even after the Go process is terminated
- I need to be able to set the Unix user/group that's running it
- I need to be able to set the environment variables inherited
- I need control over std in/out/err
Here is an attempt:
var attr = os.ProcAttr {
Dir: "/bin",
Env: os.Environ(),
Files: []*os.File{
os.Stdin,
"stdout.log",
"stderr.log",
},
}
process, err := os.StartProcess("sleep", []string{"1"}, &attr)
This works fine but has the following shortcomings from the requirements:
- No way to set Unix user/group
- The started process ends when the Go process (parent) stops
This needs to run on Linux only if that simplifies things.