本文整理汇总了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()
}
示例2: stopServer
func stopServer(proc *os.Process) {
err := proc.Kill()
if err != nil {
panic(err.Error())
}
proc.Release()
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
}
示例8: simpleKill
func simpleKill(p *os.Process) error {
if p == nil {
return nil
}
Log.Info("killing", "pid", p.Pid)
defer recover()
return p.Kill()
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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."))
}
}
示例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("")
}
示例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()
}
}()
}