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


Golang syscall.Signal函数代码示例

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


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

示例1: main

func main() {
	// Kinda hackish :/
	wd, _ := os.Getwd()
	os.Setenv("PATH",
		path.Join(wd, "framework/bin")+":"+
			path.Join(wd, "framework/sh")+":"+
			os.Getenv("PATH"))

	os.MkdirAll("cache", 0755)

	var inpipe, outpipe, context string

	flag.StringVar(&inpipe, "inpipe", "cache/wfdr-deamon-pipe-in", "Name of a file that should be used for a input IPC pipe. Should not exist.")
	flag.StringVar(&outpipe, "outpipe", "cache/wfdr-deamon-pipe-out", "Name of a file that should be used for an output IPC pipe. Should not exist.")
	flag.StringVar(&context, "context", "debug", "Context to run the daemon and child processes from. Valid choices are 'debug', 'test' and 'prod'.")

	flag.Parse()

	if context != "debug" && context != "test" && context != "prod" {
		log.Println("Invalid context argument provided!")
		log.Fatal(flag.Lookup("context").Usage)
	}

	os.Setenv("WFDR_CONTEXT", context)

	if osutil.FileExists(inpipe) || osutil.FileExists(outpipe) {
		log.Fatal("Pipe files already exist, the daemon is likely already running. However, it is also possible that the daemon was not cleanly shut down on its last run, and the files linger. If you suspect this to be the case, remove cache/wfdr-deamon-pipe-in and cache/wfdr-deamon-pipe-out, then try starting the daemon again.")
	}

	infile, err := moduled.OpenPipe(inpipe)
	if err != nil {
		log.Fatal(err)
	}
	outfile, err := moduled.OpenPipe(outpipe)
	if err != nil {
		log.Fatal(err)
	}

	rwc := &moduled.PipeReadWriteCloser{Input: infile, Output: outfile}

	go monitorPipe(rwc)

	sigc := make(chan os.Signal, 2)
	signal.Notify(sigc, syscall.Signal(0x02), syscall.Signal(0x09), syscall.Signal(0x0f))

	for {
		sig := <-sigc
		switch sig.(syscall.Signal) {
		// SIGINT, SIGKILL, SIGTERM
		case 0x02, 0x09, 0xf:
			Exit(0)
		// SIGCHLD
		case 0x11:
			// Do nothing
		default:
			log.Println(sig)
			break
		}
	}
}
开发者ID:WalterShe,项目名称:wfdr,代码行数:60,代码来源:daemon.go

示例2: InotifyLoop

func (v *Visitor) InotifyLoop() {
	sigc := make(chan os.Signal, 2)
	signal.Notify(sigc, syscall.Signal(0x02), syscall.Signal(0x09), syscall.Signal(0x0f))

	for {
		select {
		case ev := <-v.watcher.Event:
			//os.Exit(0)
			v.WatcherEvent(ev)
		case sig := <-sigc:
			switch sig.(syscall.Signal) {
			// SIGINT, SIGKILL, SIGTERM
			case 0x02, 0x09, 0xf:
				err := v.watcher.Close()
				if err != nil {
					log.Println("Warning: Error closing watcher:", err)
				}
				os.Exit(0)
			// SIGCHLD
			case 0x11:
				// Do nothing
			default:
				log.Println("Unhandled signal:", sig)
			}
		case err := <-v.watcher.Error:
			log.Println("Error in watcher:", err)
		}
	}
}
开发者ID:WalterShe,项目名称:wfdr,代码行数:29,代码来源:cache-monitor.go

示例3: Signal

func (c *ContainerInit) Signal(sig int, res *struct{}) error {
	c.mtx.Lock()
	defer c.mtx.Unlock()
	logger.Info("forwarding signal to job", "type", syscall.Signal(sig))
	if err := c.process.Signal(syscall.Signal(sig)); err != nil {
		return err
	}
	return nil
}
开发者ID:imjorge,项目名称:flynn,代码行数:9,代码来源:init.go

示例4: SignalHandler

func SignalHandler() {
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.Signal(0xa))
	for {
		if <-sigs == syscall.Signal(0xa) {
			log.Print("Recieved 0xa, reloading config")
			LoadConfig()
		}
	}
}
开发者ID:joseph-hurtado,项目名称:hostsplitter,代码行数:10,代码来源:signal_handler.go

示例5: init

func init() {
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.Signal(0xa))
	go func() {
		for syscall.Signal(0xa) == <-sigs {
			log.Print("Recieved 0xa, reloading config")
			LoadConfig()
		}
	}()

}
开发者ID:ammario,项目名称:hostsplitter,代码行数:11,代码来源:signal_handler.go

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

示例7: validateBackend

func validateBackend(dirname string, interval int) error {
	_, err := os.Stat(path.Join(dirname, DataFilename))
	// TODO Handle perm problems...
	if err != nil {
		//log.Println("XXX Failed stat")
		return start(dirname, interval)
	}

	// Data file exists, now check for the pid
	data, err := ioutil.ReadFile(path.Join(dirname, PidFilename))
	if err != nil {
		//log.Println("XXX Failed pid read")
		return start(dirname, interval)
	}
	pidString := strings.TrimSpace(string(data))
	pid, err := strconv.Atoi(pidString)
	if err != nil {
		//log.Println("XXX Failed conversion on pid")
		return start(dirname, interval)
	}
	process, err := os.FindProcess(pid)
	if err != nil {
		//log.Println("XXX Failed process find")
		return start(dirname, interval)
	}
	if err := process.Signal(syscall.Signal(0)); err != nil {
		return start(dirname, interval)
	}

	// Validate the interval is the right
	data, err = ioutil.ReadFile(path.Join(dirname, IntervalFilename))
	if err != nil {
		//log.Println("XXX Failed interval read")
		process.Signal(syscall.Signal(9))
		return start(dirname, interval)
	}

	oldIntervalString := strings.TrimSpace(string(data))
	oldInterval, err := strconv.Atoi(oldIntervalString)
	if err != nil {
		//log.Println("XXX Failed process interval")
		process.Signal(syscall.Signal(9))
		return start(dirname, interval)
	}
	if oldInterval != interval {
		//log.Println("XXX wrong interval")
		process.Signal(syscall.Signal(9))
		return start(dirname, interval)
	}

	// Everything looks good, continue using it
	return nil
}
开发者ID:dhiltgen,项目名称:ioutil,代码行数:53,代码来源:ioutil.go

示例8: isProcessAlive

func isProcessAlive(pid int) bool {
	p, _ := os.FindProcess(pid)
	if e := p.Signal(syscall.Signal(0)); e == nil {
		return true
	}
	return false
}
开发者ID:jmptrader,项目名称:spirit,代码行数:7,代码来源:utils.go

示例9: TestSyscall

func TestSyscall(t *testing.T) {
	proc, err := os.StartProcess("/usr/bin/ls", []string{"ls", "/"}, &os.ProcAttr{
		Sys: &syscall.SysProcAttr{
			Ptrace: true,
		},
	})
	catch(err)

	time.Sleep(1 * time.Nanosecond)

	tracer, err := Attach(proc)
	catch(err)

	for {
		no, err := tracer.Syscall(syscall.Signal(0))
		if err == syscall.ESRCH {
			t.Logf("Syscall() threw %v", err)
			break
		}
		if err != nil {
			t.Errorf("Syscall() threw %v", err)
			break
		}

		t.Logf("Syscall() = %v", no)
	}
}
开发者ID:hjr265,项目名称:ptrace.go,代码行数:27,代码来源:ptrace_test.go

示例10: checkAndSetPid

func checkAndSetPid(pidFile string) error { // {{{
	contents, err := ioutil.ReadFile(pidFile)
	if err == nil {
		pid, err := strconv.Atoi(strings.TrimSpace(string(contents)))
		if err != nil {
			return errors.New(fmt.Sprintf("Error reading proccess id from pidfile '%s': %s", pidFile, err))
		}

		process, err := os.FindProcess(pid)

		// on Windows, err != nil if the process cannot be found
		if runtime.GOOS == "windows" {
			if err == nil {
				return errors.New(fmt.Sprintf("Process %d is already running.", pid))
			}
		} else if process != nil {
			// err is always nil on POSIX, so we have to send the process a signal to check whether it exists
			if err = process.Signal(syscall.Signal(0)); err == nil {
				return errors.New(fmt.Sprintf("Process %d is already running.", pid))
			}
		}
	}
	if err := ioutil.WriteFile(pidFile, []byte(strconv.Itoa(os.Getpid())), 0644); err != nil {
		return errors.New(fmt.Sprintf("Unable to write pidfile '%s': %s", pidFile, err))
	}
	log.Printf("Wrote pid to pidfile '%s'", pidFile)

	return nil
} // }}}
开发者ID:rprp,项目名称:hivego,代码行数:29,代码来源:hive.go

示例11: Close

func (z *Zork) Close() error {
	// Signal 0 checks if the process is alive.
	if z.cmd.Process.Signal(syscall.Signal(0)) == nil {
		return z.cmd.Process.Kill()
	}
	return nil
}
开发者ID:A-t48,项目名称:frotz-slack-bot,代码行数:7,代码来源:zork.go

示例12: Signal

// Signal handles `docker stop` on Windows. While Linux has support for
// the full range of signals, signals aren't really implemented on Windows.
// We fake supporting regular stop and -9 to force kill.
func (clnt *client) Signal(containerID string, sig int) error {
	var (
		cont *container
		err  error
	)

	// Get the container as we need it to find the pid of the process.
	clnt.lock(containerID)
	defer clnt.unlock(containerID)
	if cont, err = clnt.getContainer(containerID); err != nil {
		return err
	}

	cont.manualStopRequested = true

	logrus.Debugf("lcd: Signal() containerID=%s sig=%d pid=%d", containerID, sig, cont.systemPid)
	context := fmt.Sprintf("Signal: sig=%d pid=%d", sig, cont.systemPid)

	if syscall.Signal(sig) == syscall.SIGKILL {
		// Terminate the compute system
		if err := hcsshim.TerminateComputeSystem(containerID, hcsshim.TimeoutInfinite, context); err != nil {
			logrus.Errorf("Failed to terminate %s - %q", containerID, err)
		}
	} else {
		// Terminate Process
		if err = hcsshim.TerminateProcessInComputeSystem(containerID, cont.systemPid); err != nil {
			logrus.Warnf("Failed to terminate pid %d in %s: %q", cont.systemPid, containerID, err)
			// Ignore errors
			err = nil
		}
	}

	return nil
}
开发者ID:RAMESHBABUK,项目名称:docker,代码行数:37,代码来源:client_windows.go

示例13: Kill

func (d *driver) Kill(c *execdriver.Command, sig int) error {
	if sig == 9 || c.ProcessConfig.Process == nil {
		return KillLxc(c.ID, sig)
	}

	return c.ProcessConfig.Process.Signal(syscall.Signal(sig))
}
开发者ID:colebrumley,项目名称:docker,代码行数:7,代码来源:driver.go

示例14: Stop

func (r *Runner) Stop() error {
	r.Logger.Info("agent-runner.stop.get-process")

	process, err := r.getProcess()
	if err != nil {
		r.Logger.Error("agent-runner.stop.get-process.failed", errors.New(err.Error()))
		return err
	}

	r.Logger.Info("agent-runner.stop.get-process.result", lager.Data{
		"pid": process.Pid,
	})

	r.Logger.Info("agent-runner.stop.signal", lager.Data{
		"pid": process.Pid,
	})

	err = process.Signal(syscall.Signal(syscall.SIGKILL))
	if err != nil {
		r.Logger.Error("agent-runner.stop.signal.failed", err)
		return err
	}

	r.Logger.Info("agent-runner.stop.success")
	return nil
}
开发者ID:tkysk,项目名称:consul-release,代码行数:26,代码来源:runner.go

示例15: IsAlive

// IsAlive will check if the process is alive or not.
// Returns true if the process is alive or false otherwise.
func (proc *Proc) IsAlive() bool {
	p, err := os.FindProcess(proc.Pid)
	if err != nil {
		return false
	}
	return p.Signal(syscall.Signal(0)) == nil
}
开发者ID:topfreegames,项目名称:apm,代码行数:9,代码来源:proc_container.go


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