Example #1
0
func stopServer(proc *os.Process) {
	err := proc.Kill()
	if err != nil {
		panic(err.Error())
	}
	proc.Release()
}
Example #2
0
func startDaemon() error {
	var proc *os.Process

	dir, err := os.Getwd()
	if err != nil {
		return err
	}
	procattr := os.ProcAttr{Dir: dir, Env: os.Environ(), Files: []*os.File{nil, nil, nil}}
	proc, err = os.StartProcess("helloworld.exe", nil, &procattr)
	if err != nil {
		return err
	}
	return proc.Release()
}
Example #3
0
// KillWithChildren kills the process
// and tries to kill its all children (process group)
func KillWithChildren(p *os.Process, interrupt bool) (err error) {
	Log.Debug("killWithChildren", "process", p)
	if p == nil {
		return
	}
	Log.Info("killWithChildren", "pid", p.Pid, "interrupt", interrupt)
	defer func() {
		if r := recover(); r != nil {
			Log.Warn("PANIC in kill", "process", p, "error", r)
		}
	}()
	defer p.Release()
	if p.Pid == 0 {
		return nil
	}
	if interrupt {
		defer p.Signal(os.Interrupt)
		return Pkill(p.Pid, os.Interrupt)
	}
	defer p.Kill()
	return Pkill(p.Pid, os.Kill)
}