本文整理汇总了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
}
}
}
示例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)
}
}
}
示例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
}
示例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()
}
}
}
示例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()
}
}()
}
示例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
}
示例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
}
示例8: isProcessAlive
func isProcessAlive(pid int) bool {
p, _ := os.FindProcess(pid)
if e := p.Signal(syscall.Signal(0)); e == nil {
return true
}
return false
}
示例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)
}
}
示例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
} // }}}
示例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
}
示例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
}
示例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))
}
示例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
}
示例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
}