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


Golang Process.Signal方法代码示例

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


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

示例1: signalProcess

func signalProcess(process *os.Process, sig ssh.Signal) error {
	signal := msgs.Signals[sig]
	defer trace.End(trace.Begin(fmt.Sprintf("signal process %d: %s", process.Pid, sig)))

	s := syscall.Signal(signal)
	return process.Signal(s)
}
开发者ID:kjplatz,项目名称:vic,代码行数:7,代码来源:attach_linux.go

示例2: Trap

// Trap will listen for all stop signals and pass them along to the given
// process.
func Trap(process *os.Process) {
	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGINT, syscall.SIGKILL, syscall.SIGQUIT)
	go func() {
		process.Signal(<-c)
	}()
}
开发者ID:koenbollen,项目名称:ddp,代码行数:9,代码来源:main.go

示例3: babySit

func babySit(process *os.Process) int {
	// Forward all signals to the app
	sigchan := make(chan os.Signal, 1)
	sigutil.CatchAll(sigchan)
	go func() {
		for sig := range sigchan {
			if sig == syscall.SIGCHLD {
				continue
			}
			process.Signal(sig)
		}
	}()

	// Wait for the app to exit.  Also, as pid 1 it's our job to reap all
	// orphaned zombies.
	var wstatus syscall.WaitStatus
	for {
		pid, err := syscall.Wait4(-1, &wstatus, 0, nil)
		if err == nil && pid == process.Pid {
			break
		}
	}

	return wstatus.ExitStatus()
}
开发者ID:snormore,项目名称:flynn,代码行数:25,代码来源:init.go

示例4: GetExitCodeProcess

func GetExitCodeProcess(proc *os.Process) (uint32, error) {
	err := proc.Signal(syscall.Signal(0))
	if err != nil {
		return 0, err
	}
	return 259, nil
}
开发者ID:ChristophPech,项目名称:servertest,代码行数:7,代码来源:syscall_linux.go

示例5: 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

示例6: main

func main() {
	flag.Parse()

	// done is sent a value when the analyzer should exit
	done := make(chan struct{}, 1)
	defer func() { done <- struct{}{} }()

	analyzerBin, analyzerArgs, compilations := parseAnalyzerCommand()
	if len(compilations) == 0 {
		flagutil.UsageError("Missing kindex-file paths")
	}

	cmd := exec.Command(analyzerBin, analyzerArgs...)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	var proc *os.Process
	if err := process.StartAsync(cmd, &process.Callbacks{
		OnStart: func(p *os.Process) {
			log.Printf("Starting analyzer subprocess: %s", strings.Join(cmd.Args, " "))
			proc = p
		},
		OnExit: func(state *os.ProcessState, err error) {
			select {
			case <-done:
			default:
				log.Fatalf("Analyzer subprocess exited unexpectedly (state:%v; error:%v)", state, err)
			}
		},
	}); err != nil {
		log.Fatalf("Error starting analyzer: %v", err)
	}

	addr := fmt.Sprintf("localhost:%d", *analyzerPort)
	conn, err := grpc.Dial(addr, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("Error dialing analyzer %q: %v", addr, err)
	}
	defer conn.Close()

	queue := local.NewKIndexQueue(compilations)
	fdsAddr := launchFileDataService(queue)

	wr := delimited.NewWriter(os.Stdout)

	driver := &driver.Driver{
		Analyzer: &remote.Analyzer{aspb.NewCompilationAnalyzerClient(conn)},
		Output:   func(_ context.Context, out *apb.AnalysisOutput) error { return wr.Put(out.Value) },

		FileDataService: fdsAddr,
		Compilations:    queue,
	}

	if err := driver.Run(context.Background()); err != nil {
		log.Fatal(err)
	}

	if err := proc.Signal(os.Interrupt); err != nil {
		log.Fatalf("Failed to send interrupt to analyzer: %v", err)
	}
}
开发者ID:benjyw,项目名称:kythe,代码行数:60,代码来源:analyzer_driver.go

示例7: SignalProcess

// SignalProcess sends signal sig to process p
func SignalProcess(p *os.Process, sig os.Signal) error {
	if p == nil {
		return syscall.ESRCH
	}
	err := p.Signal(sig)
	return err
}
开发者ID:Jimdo,项目名称:periodicnoise,代码行数:8,代码来源:process.go

示例8: babySit

func babySit(process *os.Process) int {
	log := logger.New("fn", "babySit")

	// Forward all signals to the app
	sigchan := make(chan os.Signal, 1)
	sigutil.CatchAll(sigchan)
	go func() {
		for sig := range sigchan {
			log.Info("received signal", "type", sig)
			if sig == syscall.SIGCHLD {
				continue
			}
			log.Info("forwarding signal to command", "type", sig)
			process.Signal(sig)
		}
	}()

	// Wait for the app to exit.  Also, as pid 1 it's our job to reap all
	// orphaned zombies.
	var wstatus syscall.WaitStatus
	for {
		pid, err := syscall.Wait4(-1, &wstatus, 0, nil)
		if err == nil && pid == process.Pid {
			break
		}
	}

	if wstatus.Signaled() {
		log.Info("command exited due to signal")
		return 0
	}
	return wstatus.ExitStatus()
}
开发者ID:ably-forks,项目名称:flynn,代码行数:33,代码来源:init.go

示例9: 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

示例10: 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

示例11: Lock

// Lock creates a lockfile which prevents to open more than one instance
// of the same node (on the same machine).
func (ctx *Context) Lock() (err error) {
	var f *os.File
	var p *os.Process
	var pid int

	lockFile := path.Join(ctx.storageDir, ctx.nodeName+".lock")
	if f, err = os.Open(lockFile); err != nil {
		goto lock
	}
	if _, err = fmt.Fscanf(f, "%d", &pid); err != nil && pid == 0 {
		goto lock
	}
	if p, err = os.FindProcess(pid); err == nil && p != nil {
		if err = p.Signal(syscall.Signal(0)); err == nil {
			msg := fmt.Sprintf("node '%s' is already running", ctx.NodeName())
			return errors.New(msg)
		}
	}
lock:
	// Write a lock file.
	pidstr := []byte(fmt.Sprintf("%d", os.Getppid()))
	if err = ioutil.WriteFile(lockFile, pidstr, 0644); err != nil {
		return
	}
	return nil
}
开发者ID:elliotcm,项目名称:webrocket,代码行数:28,代码来源:context.go

示例12: Lock

// Lock creates a lockfile which prevents to open more than one instance
// of the same node (on the same machine).
func (ctx *Context) Lock() (err error) {
	var f *os.File
	var p *os.Process
	var pid int

	lockFile := path.Join(ctx.storageDir, ctx.nodeName+".lock")
	if f, err = os.Open(lockFile); err != nil {
		goto lock
	}
	if _, err = fmt.Fscanf(f, "%d", &pid); err != nil && pid == 0 {
		goto lock
	}
	if p, err = os.FindProcess(pid); err == nil && p != nil {
		if err = p.Signal(os.UnixSignal(0)); err == nil {
			return errors.New(
				fmt.Sprintf("node '%s' is already running",
					ctx.NodeName()))
		}
	}
lock:
	// Write a lock file.
	if f, err = os.Create(lockFile); err == nil {
		pid := os.Getppid()
		f.Write([]byte(fmt.Sprintf("%d", pid)))
		f.Close()
	}
	return nil
}
开发者ID:pote,项目名称:webrocket,代码行数:30,代码来源:context.go

示例13: handleSignal

func handleSignal(channel chan os.Signal, synapse *os.Process) {
	select {
	case sig := <-channel:
		log.Print("Got signal: ", sig)
		synapse.Signal(os.Interrupt)
		os.Exit(1)
	}
}
开发者ID:matrix-org,项目名称:dendron,代码行数:8,代码来源:main.go

示例14: Interrupter

// Interrupter will send the `InfoSignal` to the given process every interval.
func Interrupter(process *os.Process, interval time.Duration) {
	go func() {
		for {
			time.Sleep(interval)
			process.Signal(InfoSignal)
		}
	}()
}
开发者ID:koenbollen,项目名称:ddp,代码行数:9,代码来源:main.go

示例15: logSignal

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


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