當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。