本文整理匯總了Golang中syscall.SysProcAttr.Setpgid方法的典型用法代碼示例。如果您正苦於以下問題:Golang SysProcAttr.Setpgid方法的具體用法?Golang SysProcAttr.Setpgid怎麽用?Golang SysProcAttr.Setpgid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類syscall.SysProcAttr
的用法示例。
在下文中一共展示了SysProcAttr.Setpgid方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: solverWorker
func (ctx *context) solverWorker() {
conn := ctx.pool.Get()
defer conn.Close()
for r := range ctx.solverch {
var arg string
if r.IsIR {
arg = "-action=ir"
} else {
arg = "-action=inst"
}
cmd := exec.Command(os.Args[0]+"-backend", arg, os.Args[1])
cmd.Stdin = strings.NewReader(r.Req)
var outb, errb bytes.Buffer
cmd.Stdout = &outb
cmd.Stderr = &errb
var sys syscall.SysProcAttr
sys.Setpgid = true
cmd.SysProcAttr = &sys
err := cmd.Start()
if err != nil {
os.Stdout.Write([]byte("Error invoking solver: " + err.Error() + "\n"))
r.result <- solverResp{"", friendlyError{"Error invoking solver", err}}
continue
}
timeout := false
timer := time.AfterFunc(10*time.Second, func() {
syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
timeout = true
})
err = cmd.Wait()
timer.Stop()
if timeout {
os.Stdout.Write([]byte("Solver timeout\n"))
r.result <- solverResp{"", friendlyError{"Solver timeout", nil}}
} else if err != nil {
r.result <- solverResp{"", friendlyError{"Error invoking solver", err}}
} else if errb.Len() != 0 {
r.result <- solverResp{"", friendlyError{errb.String(), nil}}
} else {
r.result <- solverResp{outb.String(), nil}
}
}
}