当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Getpgid函数代码示例

本文整理汇总了Golang中syscall.Getpgid函数的典型用法代码示例。如果您正苦于以下问题:Golang Getpgid函数的具体用法?Golang Getpgid怎么用?Golang Getpgid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Getpgid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Kill

func (cmd *Cmd) Kill() error {
	switch cmd.State {
	case Running:
		cmd.State = Terminated
		lg.Debugf("Cmd:\tKilling %v\n", cmd.JobID)
		pgid, err := syscall.Getpgid(cmd.Cmd.Process.Pid)
		if err != nil {
			// Fall-back on error. Kill the main process only.
			cmd.Cmd.Process.Kill()
			break
		}
		// Kill the whole process group.
		syscall.Kill(-pgid, 15)

	case Finished:
		lg.Debug("Cmd:\tKilling pgroup %v\n", cmd.JobID)
		pgid, err := syscall.Getpgid(cmd.Cmd.Process.Pid)
		if err != nil {
			break
		}
		// Make sure to kill the whole process group,
		// so there are no subprocesses left.
		syscall.Kill(-pgid, 15)

	case Initialized:
		// This one is tricky, as the cmd's Start() might have
		// been called and is already in progress, but the cmd's
		// state is not Running yet.
		usCallingStartOnce := false
		cmd.StartOnce.Do(func() {
			cmd.WaitOnce.Do(func() {
				cmd.State = Invalidated
				cmd.StatusCode = -2
				cmd.Err = errors.New("invalidated")
				lg.Debugf("Cmd: Invalidating %v\n", cmd.JobID)
				close(cmd.Finished)
			})
			close(cmd.Started)
			usCallingStartOnce = true
		})
		if !usCallingStartOnce {
			// It was cmd.Start() that called StartOnce.Do(), not us,
			// thus we need to wait for Started and try to Kill again:
			<-cmd.Started
			cmd.Kill()
		}
	}

	return cmd.Err
}
开发者ID:pressly,项目名称:qmd,代码行数:50,代码来源:cmd.go

示例2: Start

func (p *execProcess) Start() error {
	if p.cmd.Stdout == nil {
		p.cmd.Stdout = p.stdoutWriter
	}

	if p.cmd.Stderr == nil {
		p.cmd.Stderr = p.stderrWriter
	}

	cmdString := strings.Join(p.cmd.Args, " ")
	p.logger.Debug(execProcessLogTag, "Running command '%s'", cmdString)

	if !p.keepAttached {
		p.cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
	}

	err := p.cmd.Start()
	if err != nil {
		return bosherr.WrapErrorf(err, "Starting command '%s'", cmdString)
	}

	if !p.keepAttached {
		p.pgid = p.cmd.Process.Pid
	} else {
		p.pgid, err = syscall.Getpgid(p.pid)
		if err != nil {
			p.logger.Error(execProcessLogTag, "Failed to retrieve pgid for command '%s'", cmdString)
			p.pgid = -1
		}
	}

	return nil
}
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:33,代码来源:exec_process_unix.go

示例3: Kill

func (r *Runner) Kill() error {
	pgid, err := syscall.Getpgid(r.cmd.Process.Pid)
	if err == nil {
		syscall.Kill(-pgid, syscall.SIGTERM)
	}
	return err
}
开发者ID:heyLu,项目名称:qst,代码行数:7,代码来源:qst.go

示例4: Getpgid

func (k *PosixKernel) Getpgid(pid int) uint64 {
	n, err := syscall.Getpgid(pid)
	if err != nil {
		return Errno(err)
	}
	return uint64(n)
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:7,代码来源:process.go

示例5: killGroupProcess

//KillGroupProcess ...
func killGroupProcess(cmd *exec.Cmd) {
	pgid, err := syscall.Getpgid(cmd.Process.Pid)
	if err == nil {
		err = syscall.Kill(-pgid, 15)
		printError("syscall Kill :", err)
		sendMessage("info", "Run aborted\n")
	}
}
开发者ID:bitrise-io,项目名称:bitrise-cli-webui,代码行数:9,代码来源:runCommand.go

示例6: Exec

// Satisfies the Listener interface and calls the relevant binary file
func (this *Cli) Exec(evt event.Event) {

	this.Log.Handler(this, &evt)

	bin := magicString(this.Config.GetBin(), evt)
	stdin := magicString(this.Config.GetStdin(), evt)
	args := append([]string(nil), this.Config.GetArgs()...)
	for i, arg := range this.Config.GetArgs() {
		args[i] = magicString(arg, evt)
	}

	cmd := exec.Command(bin, args...)
	cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
	cmd.Stdin = strings.NewReader(stdin)
	var out bytes.Buffer
	var sErr bytes.Buffer
	cmd.Stdout = &out
	cmd.Stderr = &sErr

	this.Log.Info("CLI CMD %s %s \"%s %s\"", evt.GetId(), this.GetName(), bin, strings.Join(args, " "))
	err := cmd.Start()
	if err != nil {
		this.Log.Error("CLI ERR %s %s \"%s\"", evt.GetId(), this.GetName(), sErr.String())
		this.Log.HandlerError(this, err.Error(), &evt)
		return
	}

	timeOut := this.Config.GetTimeout()
	if timeOut == 0 {
		if err := cmd.Wait(); err != nil {
			this.Log.Error("CLI ERROR %s", err.Error())
		}
	} else {
		// this allows us to set a timeout on the cli (phantomjs def needs this)
		done := make(chan error, 1)
		go func() {
			done <- cmd.Wait()
		}()
		select {
		case <-time.After(time.Duration(timeOut) * time.Second):
			pgid, err := syscall.Getpgid(cmd.Process.Pid)
			if err == nil {
				syscall.Kill(-pgid, 15) // note the minus sign
				this.Log.Warning("CLITIMEOUT %s %s", evt.GetId(), this.GetName())
			}
			<-done // allow goroutine to exit
		case err := <-done:
			if err != nil {
				this.Log.Error("CLI ERROR %s", err.Error())
			}
		}

	}

	this.Log.Debug("CLI OUT %s %s \"%s\"", evt.GetId(), this.GetName(), out.String())
}
开发者ID:jmptrader,项目名称:eevy,代码行数:57,代码来源:cli.go

示例7: Info

func (c *command) Info() (pid, pgrp int) {
	pid = c.proc.Process.Pid

	pgrp, err := syscall.Getpgid(pid)
	if err != nil {
		c.test.Fatal(err)
	}

	return
}
开发者ID:2thetop,项目名称:go,代码行数:10,代码来源:exec_unix_test.go

示例8: killall

func killall(multierr io.Writer, cmd *exec.Cmd) {
	cmd.Start()

	pgid, err := syscall.Getpgid(cmd.Process.Pid)
	if err == nil {
		syscall.Kill(-pgid, 15) // note the minus sign
		cmd.Wait()
	} else {
		fmt.Fprintf(multierr, "\n%v\n", err)
	}
}
开发者ID:gidden,项目名称:cloudlus,代码行数:11,代码来源:job.go

示例9: sendSignalToProcess

func sendSignalToProcess(process *os.Process, what values.Signal, tryGroup bool) error {
	if tryGroup {
		pgid, err := syscall.Getpgid(process.Pid)
		if err == nil {
			if syscall.Kill(-pgid, syscall.Signal(what)) == nil {
				return nil
			}
		}
	}
	process.Signal(syscall.Signal(what))
	return nil
}
开发者ID:echocat,项目名称:caretakerd,代码行数:12,代码来源:execution_unix.go

示例10: kill

// Kill a script run and all child processes
func (self *ScriptRun) kill() error {
	if self.Cmd == nil {
		return errors.New("Cmd is nil")
	} else if self.Cmd.Process == nil {
		return errors.New("Cmd.Process is nil")
	}
	pgid, err := syscall.Getpgid(self.Cmd.Process.Pid)
	if err != nil {
		return err
	}
	return syscall.Kill(-pgid, syscall.SIGKILL)
}
开发者ID:adsr,项目名称:gobashd,代码行数:13,代码来源:run.go

示例11: killProcessOnTimeout

// kills a cmd process based on config timeout settings
func killProcessOnTimeout(cmd *exec.Cmd, timeout time.Duration) (exitCode int, err error) {
	// 1 deep channel for done
	done := make(chan error, 1)

	go func() {
		done <- cmd.Wait()
	}()

	processGroupID, err := syscall.Getpgid(cmd.Process.Pid)
	if err != nil {
		return 0, err
	}

	grimProcessGroupID, err := syscall.Getpgid(os.Getpid())
	if err != nil {
		return 0, err
	}

	select {
	case <-time.After(timeout):
		exitCode = -23
		err = errTimeout
	case err := <-done:
		if err != nil {
			exitCode, err = getExitCode(err)
			if err != nil {
				return 0, fmt.Errorf("Build Error: %v", err)
			}
		}
	}

	if grimProcessGroupID != processGroupID {
		syscall.Kill(-processGroupID, syscall.SIGKILL)
	}

	return
}
开发者ID:jhannah,项目名称:grim,代码行数:38,代码来源:execute.go

示例12: TestIPERF

func TestIPERF(t *testing.T) {

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)
	go func() {
		if <-c != syscall.SIGTERM {
			panic(nil)
		}
	}()

	if len(os.Getenv("IPERF")) != 0 {
		cmd0 := exec.Command("iperf3", "-s", "", "-p", "5203")
		cmd0.Start()
		pid := cmd0.Process.Pid
		go cmd0.Wait()

		t0 := Accelerate("tcp://:41501-41504,udp://:42401-42404", "tcp://127.0.0.1:5203", BACKEND)
		t0.WaitforAlive()
		t1 := Accelerate("tcp://:50500", "tcp://127.0.0.1:41501-41504,udp://127.0.0.1:42401-42404", FRONTEND)
		t1.WaitforAlive()

		//iperfExec(exec.Command("iperf3", "-c", "127.0.0.1", "-p", "50500", "-R", "-P", "3"))
		//iperfExec(exec.Command("iperf3", "-c", "127.0.0.1", "-p", "50500", "-b", "10M"))
		cmd1 := exec.Command("iperf3", "-c", "127.0.0.1", "-p", "50500", "--get-server-output")
		iperfExec(cmd1)
		if len(os.Getenv("CPU")) != 0 {
			f, err := os.Create("cpu.profile")
			if err != nil {
				log.Fatal(err)
			}
			pprof.StartCPUProfile(f)
			defer pprof.StopCPUProfile()
		}
		cmd1.Wait()

		cmd2 := exec.Command("iperf3", "-c", "127.0.0.1", "-p", "50500", "-R", "--get-server-output")
		iperfExec(cmd2)
		cmd2.Wait()

		t0.Status()
		t1.Status()

		pgid, err := syscall.Getpgid(pid)
		if err == nil {
			syscall.Kill(-pgid, 15) // note the minus sign
		}
	}
}
开发者ID:tomasen,项目名称:trafcacc,代码行数:49,代码来源:trafcacc_test.go

示例13: killall

func killall(multierr io.Writer, cmd *exec.Cmd) {
	pgid, err := syscall.Getpgid(cmd.Process.Pid)

	// don't kill myself if cmd is running in same process group
	if pgid == os.Getpid() || pgid == os.Getgid() {
		cmd.Process.Kill()
		return
	}

	if err == nil {
		syscall.Kill(-pgid, 15) // note the minus sign
		cmd.Wait()
	} else {
		fmt.Fprintf(multierr, "\n%v\n", err)
	}
}
开发者ID:rwcarlsen,项目名称:cloudlus,代码行数:16,代码来源:job.go

示例14: KillProcesses

func (x *ProcessManager) KillProcesses() error {
	x.processes.Lock()
	defer x.processes.Unlock()
	for _, pi := range x.processes.values {
		// we could potentially fail before the processes are correctly started
		// in that case, do nothing
		if pi.cmd.Process != nil {
			pgid, err := syscall.Getpgid(pi.cmd.Process.Pid)
			if err != nil {
				return err
			}
			syscall.Kill(-pgid, 15)
		}
	}
	return nil
}
开发者ID:Senior-Design-May1601,项目名称:projectmain,代码行数:16,代码来源:process.go

示例15: cmdKill

func (i *instance) cmdKill(req *Request) (*Response, error) {
	glog.Infoln("Server going down with SIGKILL")
	glog.Flush()

	pgid, err := syscall.Getpgid(0)
	if err != nil {
		glog.Errorln("Failed to get pgid", err)
		os.Exit(1)
	}

	err = syscall.Kill(-pgid, syscall.SIGKILL)
	if err != nil {
		glog.Errorln("Failed to kill our process group", err)
		os.Exit(1)
	}

	// We'll never get here...
	return nil, nil
}
开发者ID:akramer,项目名称:lateral,代码行数:19,代码来源:server.go


注:本文中的syscall.Getpgid函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。