I have tried to use os.StartProcess and failed always. My lately created
process exits instantly.
Can anyone give me some examples?
import(
"os"
)
func main() {
if len(os.Args) < 2 {
println("usage: supervisor program arg1 arg2 ...")
return
}
procAttr := new(os.ProcAttr)
var args []string
if len(os.Args) == 2 {
args = nil
} else {
args = os.Args[2:]
}
process, err := os.StartProcess(os.Args[1], args, procAttr)
if err != nil {
println("start process failed:" + err.String())
return
}
waitMsg, err := process.Wait(os.WSTOPPED)
if err != nil {
println("Wait Error:" + err.String())
}
println("waitMsg:" + waitMsg.String())
}
锟斤拷 2011/6/3 18:27, Hoping White 写锟斤拷:
>> I have tried to use os.StartProcess and failed always. My lately created
>> process exits instantly.
>> Can anyone give me some examples?
Tell us what the error messages were, and what arguments
you passed, and what OS you're using.
Chris
--
Chris "allusive" Dollin
> procAttr := new(os.ProcAttr)
> var args []string
> if len(os.Args) == 2 {
> args = nil
> } else {
> args = os.Args[2:]
> }
Try
args = os.Args[1:]
instead of the complete "if" block. The program name needs to be the
first argument in the argument list.
Norbert
Thanks, it works now.
I have another question, how to make a program deamonize?
I have searched the nuts mailist, and found that the suggested thread
can't be opened.
锟斤拷 2011/6/3 20:55, Norbert Roos 写锟斤拷:
> I have another question, how to make a program deamonize?
You mean the started process should keep running, even when the program
which started the process terminates? Sorry, i don't know this... i
could imagine that this is something os specific.
Norbert