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


Golang Process.Kill方法代码示例

本文整理汇总了Golang中os.Process.Kill方法的典型用法代码示例。如果您正苦于以下问题:Golang Process.Kill方法的具体用法?Golang Process.Kill怎么用?Golang Process.Kill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os.Process的用法示例。


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

示例1: rerunner

func (ss *SubService) rerunner(rerunChan chan bool) {
	var proc *os.Process
	for rerun := range rerunChan {
		if !rerun {
			break
		}

		cmd := exec.Command(ss.binPath, ss.argv...)
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr

		startupTimer := time.NewTimer(RerunWait)

		cmd.Start()
		proc = cmd.Process

		// In another goroutine, wait for the process to complete and send a relaunch signal.
		// If this signal is sent after the stop signal, it is ignored.
		go func(proc *os.Process) {
			proc.Wait()
			select {
			case <-startupTimer.C:
				// we let it run long enough that it might not be a recurring error, try again
				rerunChan <- true
			default:
				// error happened too quickly - must be startup issue
				startupTimer.Stop()
			}
		}(proc)
	}
	proc.Kill()
}
开发者ID:sdmajor,项目名称:skynet,代码行数:32,代码来源:subservice.go

示例2: stopServer

func stopServer(proc *os.Process) {
	err := proc.Kill()
	if err != nil {
		panic(err.Error())
	}
	proc.Release()
}
开发者ID:joshuaconner,项目名称:etcd,代码行数:7,代码来源:etcd_tls_test.go

示例3: run

func run(binName, binPath string, args []string) (runch chan bool) {
	runch = make(chan bool)
	go func() {
		cmdline := append([]string{binName}, args...)
		var proc *os.Process
		for relaunch := range runch {
			if proc != nil {
				err := proc.Signal(os.Interrupt)
				if err != nil {
					log.Printf("error on sending signal to process: '%s', will now hard-kill the process\n", err)
					proc.Kill()
				}
				proc.Wait()
			}
			if !relaunch {
				continue
			}
			cmd := exec.Command(binPath, args...)
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
			log.Print(cmdline)
			err := cmd.Start()
			if err != nil {
				log.Printf("error on starting process: '%s'\n", err)
			}
			proc = cmd.Process
		}
	}()
	return
}
开发者ID:sinni800,项目名称:rerun,代码行数:30,代码来源:rerun.go

示例4: run

func run(ch chan bool, bin string, args []string) {
	go func() {
		var proc *os.Process

		for relaunch := range ch {
			if proc != nil {
				if err := proc.Signal(os.Interrupt); err != nil {
					proc.Kill()
				}
				proc.Wait()
			}

			if !relaunch {
				continue
			}

			cmd := exec.Command(bin, args...)
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr

			if err := cmd.Start(); err != nil {
				log("error: %s", err)
			}

			proc = cmd.Process
		}
	}()
	return
}
开发者ID:csquared,项目名称:rerun,代码行数:29,代码来源:rerun.go

示例5: runBin

// runBin runs the generated bin file with the arguments expected
func runBin(bindir, bin string, args []string) chan bool {
	var relunch = make(chan bool)
	go func() {
		binfile := fmt.Sprintf("%s/%s", bindir, bin)
		// cmdline := append([]string{bin}, args...)
		var proc *os.Process

		for dosig := range relunch {
			if proc != nil {
				if err := proc.Signal(os.Interrupt); err != nil {
					log.Printf("Error in sending signal %s", err)
					proc.Kill()
				}
				proc.Wait()
			}

			if !dosig {
				continue
			}

			cmd := exec.Command(binfile, args...)
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr

			if err := cmd.Start(); err != nil {
				log.Printf("Error starting process: %s", err)
			}

			proc = cmd.Process
		}
	}()
	return relunch
}
开发者ID:influx6,项目名称:watch,代码行数:34,代码来源:watch.go

示例6: stop

func (h *Hoverfly) stop(hoverflyDirectory HoverflyDirectory) error {
	if !h.isLocal() {
		return errors.New("hoverctl can not stop an instance of Hoverfly on a remote host")
	}

	pid, err := hoverflyDirectory.GetPid(h.AdminPort, h.ProxyPort)

	if err != nil {
		log.Debug(err.Error())
		return errors.New("Could not read Hoverfly pid file")
	}

	if pid == 0 {
		return errors.New("Hoverfly is not running")
	}

	hoverflyProcess := os.Process{Pid: pid}
	err = hoverflyProcess.Kill()
	if err != nil {
		log.Info(err.Error())
		return errors.New("Could not kill Hoverfly")
	}

	err = hoverflyDirectory.DeletePid(h.AdminPort, h.ProxyPort)
	if err != nil {
		log.Debug(err.Error())
		return errors.New("Could not delete Hoverfly pid")
	}

	return nil
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:31,代码来源:hoverfly.go

示例7: runner

// Run the command in the given string and restart it after
// a message was received on the buildDone channel.
func runner(command string, buildDone <-chan struct{}) {
	var currentProcess *os.Process
	pipeChan := make(chan io.ReadCloser)

	go logger(pipeChan)

	for {
		<-buildDone

		if currentProcess != nil {
			if err := currentProcess.Kill(); err != nil {
				log.Fatal("Could not kill child process. Aborting due to danger of infinite forks.")
			}

			_, werr := currentProcess.Wait()

			if werr != nil {
				log.Fatal("Could not wait for child process. Aborting due to danger of infinite forks.")
			}
		}

		log.Println("Restarting the given command.")
		cmd, stdoutPipe, stderrPipe, err := startCommand(command)

		if err != nil {
			log.Fatal("Could not start command:", err)
		}

		pipeChan <- stdoutPipe
		pipeChan <- stderrPipe

		currentProcess = cmd.Process
	}
}
开发者ID:jimstudt,项目名称:CompileDaemon,代码行数:36,代码来源:daemon.go

示例8: simpleKill

func simpleKill(p *os.Process) error {
	if p == nil {
		return nil
	}
	Log.Info("killing", "pid", p.Pid)
	defer recover()
	return p.Kill()
}
开发者ID:xingskycn,项目名称:go,代码行数:8,代码来源:procutils.go

示例9: stop

// Go doesn't support signals in windows (pre Go 1.3) because windows doesn't have signals.
// Windows implementation will use kill
func stop(process *os.Process) error {
	err := process.Kill()
	if err != nil {
		log.Println("Error while sending SIG_DEATH to running server:", err)
		return err
	}
	return nil
}
开发者ID:yeerkkiller1,项目名称:buildblast,代码行数:10,代码来源:stop_windows.go

示例10: logKill

// Log a call to os.Process.Kill.
func logKill(p *os.Process) error {
	log.Printf("killing PID %d", p.Pid)
	err := p.Kill()
	if err != nil {
		log.Print(err)
	}
	return err
}
开发者ID:scucoco,项目名称:meek,代码行数:9,代码来源:meek-client-torbrowser.go

示例11: RunGo

// RunGo runs the generated binary file with the arguments expected
func RunGo(gofile string, args []string, done, stopped func()) chan bool {
	var relunch = make(chan bool)

	// if runtime.GOOS == "windows" {
	gofile = filepath.Clean(gofile)
	// }

	go func() {

		// var cmdline = fmt.Sprintf("go run %s", gofile)
		cmdargs := append([]string{"run", gofile}, args...)
		// cmdline = strings.Joinappend([]string{}, "go run", gofile)

		var proc *os.Process

		for dosig := range relunch {
			if proc != nil {
				var err error

				if runtime.GOOS == "windows" {
					err = proc.Kill()
				} else {
					err = proc.Signal(os.Interrupt)
				}

				if err != nil {
					fmt.Printf("---> Error in Sending Kill Signal %s\n", err)
					proc.Kill()
				}
				proc.Wait()
				proc = nil
			}

			if !dosig {
				continue
			}

			fmt.Printf("--> Starting cmd: %s\n", cmdargs)
			cmd := exec.Command("go", cmdargs...)
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr

			if err := cmd.Start(); err != nil {
				fmt.Printf("---> Error starting process: %s\n", err)
			}

			proc = cmd.Process
			if done != nil {
				done()
			}
		}

		if stopped != nil {
			stopped()
		}
	}()
	return relunch
}
开发者ID:influx6,项目名称:reactors,代码行数:59,代码来源:pkg.go

示例12: kill

func kill(p *os.Process) {
	verboseLog("Killing child process")
	if err := p.Kill(); err != nil {
		traceLog("Could not kill", ApplicationName, "child is still running with PID:", p.Pid)
	}

	verboseLog("Removing test artifacts")
	os.Remove(ApplicationPIDFile)
	os.Remove(ApplicationName)
}
开发者ID:ryanfaerman,项目名称:talks,代码行数:10,代码来源:acceptance_test.go

示例13: killProcessHard

func killProcessHard(process *os.Process) {
	log.Println(okColor("Hard stopping the current process.."))

	if err := process.Kill(); err != nil {
		log.Fatal(failColor("Could not kill child process. Aborting due to danger of infinite forks."))
	}

	if _, err := process.Wait(); err != nil {
		log.Fatal(failColor("Could not wait for child process. Aborting due to danger of infinite forks."))
	}
}
开发者ID:currantlabs,项目名称:CompileDaemon,代码行数:11,代码来源:daemon.go

示例14: killCamli

func killCamli(proc *os.Process) {
	if *fast {
		return
	}
	dbg.Println("killing dev server")
	err := proc.Kill()
	if err != nil {
		log.Fatalf("Could not kill dev-server: %v", err)
	}
	dbg.Println("")
}
开发者ID:stunti,项目名称:camlistore,代码行数:11,代码来源:bot.go

示例15: listenSignal

// listen for signal and forward to process
func listenSignal(proc *os.Process) {

	sig := make(chan os.Signal)
	signal.Notify(sig, syscall.SIGTERM, syscall.SIGQUIT)

	go func() {
		for {
			<-sig
			proc.Kill()
		}
	}()
}
开发者ID:hoffoo,项目名称:envR,代码行数:13,代码来源:rproc.go


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