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


Golang syscall.WaitStatus函数代码示例

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


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

示例1: mkdirNormalMasterRun

func mkdirNormalMasterRun(master *Master, arg string, rep *WorkResponse) {
	rootless := strings.TrimLeft(arg, "/")
	dir, _ := SplitPath(rootless)
	dirAttr := master.fileServer.attributes.Get(dir)
	if dirAttr.Deletion() {
		rep.Stderr = fmt.Sprintf("File not found: /%s", dir)
		rep.Exit = syscall.WaitStatus(1 << 8)
		return
	}

	if !dirAttr.IsDir() {
		rep.Stderr = fmt.Sprintf("Is not a directory: /%s", dir)
		rep.Exit = syscall.WaitStatus(1 << 8)
		return
	}

	chAttr := master.fileServer.attributes.Get(rootless)
	if !chAttr.Deletion() {
		rep.Stderr = fmt.Sprintf("File exists: /%s", rootless)
		rep.Exit = syscall.WaitStatus(1 << 8)
		return
	}
	chAttr = mkdirEntry(rootless)

	fs := attr.FileSet{}

	ct := chAttr.ChangeTime()
	mt := chAttr.ModTime()
	dirAttr.SetTimes(nil, &mt, &ct)
	fs.Files = append(fs.Files, dirAttr, chAttr)
	master.replay(fs)
}
开发者ID:janneke,项目名称:termite,代码行数:32,代码来源:masterrun.go

示例2: TestExitStatus

func TestExitStatus(t *testing.T) {
	status := syscall.WaitStatus(0)
	ex := ExitStatus(status)
	if ex != 0 {
		t.Errorf("expected exit status to equal 0 and received %d", ex)
	}
}
开发者ID:Altiscale,项目名称:runc,代码行数:7,代码来源:utils_test.go

示例3: TestExitStatusSignaled

func TestExitStatusSignaled(t *testing.T) {
	status := syscall.WaitStatus(2)
	ex := ExitStatus(status)
	if ex != 130 {
		t.Errorf("expected exit status to equal 130 and received %d", ex)
	}
}
开发者ID:Altiscale,项目名称:runc,代码行数:7,代码来源:utils_test.go

示例4: Error

func (e ExitError) Error() string {
	w := syscall.WaitStatus(e)
	s := ""

	switch {
	case w.Exited():
		s = "exit status " + strconv.Itoa(w.ExitStatus())

	case w.Signaled():
		s = "signal: " + w.Signal().String()

	case w.Stopped():
		s = "stop signal: " + w.StopSignal().String()
		if w.StopSignal() == syscall.SIGTRAP && w.TrapCause() != 0 {
			s += " (trap " + strconv.Itoa(w.TrapCause()) + ")"
		}

	case w.Continued():
		s = "continued"
	}

	if w.CoreDump() {
		s += " (core dumped)"
	}

	return s
}
开发者ID:hjr265,项目名称:jail.go,代码行数:27,代码来源:jail.go

示例5: exitCode

func exitCode(s int) string {
	ws := syscall.WaitStatus(s)
	if ws.Exited() {
		return fmt.Sprintf("status %d", ws.ExitStatus())
	} else if ws.Signaled() && ws.CoreDump() {
		return fmt.Sprintf("signal %v, with core dump", ws.Signal())
	} else if ws.Signaled() {
		return fmt.Sprintf("signal %v", ws.Signal())
	} else if ws.Stopped() {
		return fmt.Sprintf("stopped by %v", ws.StopSignal())
	} else if ws.Continued() {
		return fmt.Sprintf("continued")
	} else {
		return fmt.Sprintf("exit status unknown")
	}
}
开发者ID:William-J-Earl,项目名称:cloudproxy,代码行数:16,代码来源:tao_launch.go

示例6: Syscall

func (t *Tracer) Syscall(sig syscall.Signal) (uint64, error) {
	err := syscall.PtraceSyscall(t.Process.Pid, int(sig))
	if err != nil {
		return 0, err
	}

	status := syscall.WaitStatus(0)
	_, err = syscall.Wait4(t.Process.Pid, &status, 0, nil)
	if err != nil {
		return 0, err
	}

	regs, err := t.GetRegs()
	if err != nil {
		return 0, err
	}

	return regs.Orig_rax, nil
}
开发者ID:hjr265,项目名称:ptrace.go,代码行数:19,代码来源:ptrace.go

示例7: doPtraceExit

// doPtraceExit handles SIGTRAP debug events with a PTRACE_EVENT_EXIT
// cause.  It sets up the thread's state, but does not remove it from
// the process.  A later WIFEXITED debug event will remove it from the
// process.
func (ev *debugEvent) doPtraceExit() (threadState, os.Error) {
	t := ev.t

	// Get exit status
	exitStatus, err := t.ptraceGetEventMsg()
	if err != nil {
		return stopped, err
	}
	ws := syscall.WaitStatus(exitStatus)
	t.logTrace("exited with %v", ws)
	switch {
	case ws.Exited():
		t.exitStatus = ws.ExitStatus()
	case ws.Signaled():
		t.signal = ws.Signal()
	}

	// We still need to continue this thread and wait on this
	// thread's WIFEXITED event.  We'll delete it then.
	return stoppedExiting, nil
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:25,代码来源:proc_linux.go

示例8: Run

func (c *Cmd) Run() error {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	err := c.Cmd.Start()
	if err != nil {
		return err
	}

	ready := map[int]bool{}

	status := syscall.WaitStatus(0)
	usage := syscall.Rusage{}
	for {
		pid, err := syscall.Wait4(c.Cmd.Process.Pid, &status, 0, &usage)
		if err != nil {
			return err
		}

		if !ready[pid] {
			ready[pid] = true
		}

		c.Usages.Cpu = time.Duration(usage.Utime.Nano())
		c.Usages.Memory = uint64(usage.Maxrss)

		switch {
		case status.Exited():
			if status.ExitStatus() != 0 {
				return ExitError(status)
			}
			return nil

		case status.Signaled():
			return ExitError(status)
		}
	}

	panic("unreachable")
}
开发者ID:hjr265,项目名称:jail.go,代码行数:40,代码来源:jail_darwin.go

示例9: CleanUpZombieChildren

func CleanUpZombieChildren() {
	cmd := exec.Command("pgrep", "-P", fmt.Sprintf("%d", os.Getpid()))
	var outBuf bytes.Buffer
	cmd.Stdout = &outBuf
	err := cmd.Start()
	if err != nil {
		log.Println("Error starting pgrep in CleanUpZombieChildren", err)
	}
	err = cmd.Wait()
	if err != nil {
		_, ok := err.(*exec.ExitError)
		if !ok {
			log.Println("Failed to execute pgrep in CleanUpZombieChildren", err)
		}
	}
	go func() {
		scanner := bufio.NewScanner(&outBuf)
		for scanner.Scan() {
			line := scanner.Text()
			pid64, err := strconv.ParseInt(line, 10, 32)
			if err != nil {
				log.Println("Could not parse PID from line", line, "in CleanUpZombieChildren", err)
				continue
			}
			pid := int(pid64)
			if pid != cmd.Process.Pid {
				log.Printf("@(dim:Cleaning up zombie child) %[email protected](dim:.)\n", pid)
				go func() {
					syscall.Kill(pid, syscall.SIGHUP)
					time.Sleep(60 * time.Second)
					syscall.Kill(pid, syscall.SIGINT)
					time.Sleep(20 * time.Second)
					syscall.Kill(pid, syscall.SIGTERM)
				}()
				ws := syscall.WaitStatus(0)
				syscall.Wait4(pid, &ws, 0, nil)
			}
		}
	}()
}
开发者ID:tillberg,项目名称:go-autorebuild,代码行数:40,代码来源:clean_up_zombie_children.go

示例10: executeHandler

func executeHandler(command *os.File, args []string, sigs chan os.Signal) (syscall.WaitStatus, error) {
	cmd := exec.Command(command.Name(), args...)
	cmd.Env = os.Environ()
	// cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stderr
	cmd.Stderr = os.Stderr

	go func() {
		sig := <-sigs
		if cmd.Process != nil {
			cmd.Process.Signal(sig)
		}
	}()

	if err := cmd.Run(); err != nil {
		if exitError, ok := err.(*exec.ExitError); ok {
			return exitError.Sys().(syscall.WaitStatus), nil
		}
	}

	return syscall.WaitStatus(0), nil
}
开发者ID:justinhennessy,项目名称:lifecycled,代码行数:22,代码来源:daemon.go

示例11: Sys

func (f fakeExitError) Sys() interface{} { return syscall.WaitStatus(f << 8) }
开发者ID:qinguoan,项目名称:vulcan,代码行数:1,代码来源:task_test.go

示例12: FakeExternalCmdExit

func FakeExternalCmdExit(name string, exit int, sig syscall.Signal) ExternalCmdExit {
	return ExternalCmdExit{syscall.WaitStatus(exit<<8 + int(sig)), name, 0}
}
开发者ID:zhsj,项目名称:elvish,代码行数:3,代码来源:error.go

示例13: init

func init() {
	failureStatus = syscall.WaitStatus(255)
	successStatus = syscall.WaitStatus(0)
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:4,代码来源:starter_any.go

示例14: cleanUpChildZombiesInt

func cleanUpChildZombiesInt(quiet bool) {
	var logWriter io.Writer
	if quiet {
		logWriter = ioutil.Discard
	} else {
		logWriter = os.Stderr
	}
	logger := log.New(logWriter, "[autorestart.CleanUpZombies] ", log.LstdFlags)
	cmd := exec.Command("pgrep", "-P", fmt.Sprintf("%d", os.Getpid()))
	var outBuf bytes.Buffer
	cmd.Stdout = &outBuf
	err := cmd.Start()
	if err != nil {
		logger.Println("Error starting pgrep in CleanUpZombieChildren", err)
	}
	err = cmd.Wait()
	if err != nil {
		_, ok := err.(*exec.ExitError)
		if !ok {
			logger.Println("Failed to execute pgrep in CleanUpZombieChildren", err)
		}
	}
	go func() {
		scanner := bufio.NewScanner(&outBuf)
		for scanner.Scan() {
			line := scanner.Text()
			pid64, err := strconv.ParseInt(line, 10, 32)
			if err != nil {
				logger.Println("Could not parse PID from line", line, "in CleanUpZombieChildren", err)
				continue
			}
			pid := int(pid64)
			if pid != cmd.Process.Pid {
				logger.Printf("Cleaning up zombie child with PID %d.\n", pid)
				exited := false
				go func() {
					// Send SIGHUP, SIGINT, and finally SIGTERM, on long delays, to encourage still-living
					// child processes to draw closer to the netherworld.
					time.Sleep(5 * time.Second)
					if exited {
						return
					}
					logger.Printf("Sending SIGHUP to %d.\n", pid)
					err := syscall.Kill(pid, syscall.SIGHUP)
					if err != nil {
						return
					}
					time.Sleep(120 * time.Second)
					if exited {
						return
					}
					logger.Printf("Sending SIGINT to %d.\n", pid)
					err = syscall.Kill(pid, syscall.SIGINT)
					if err != nil {
						return
					}
					time.Sleep(60 * time.Second)
					if exited {
						return
					}
					logger.Printf("Sending SIGTERM to %d.\n", pid)
					syscall.Kill(pid, syscall.SIGTERM)
				}()
				ws := syscall.WaitStatus(0)
				_, err := syscall.Wait4(pid, &ws, 0, nil)
				if err != nil {
					logger.Printf("Error while waiting for PID %d to exit: %s\n", pid, err)
				} else {
					logger.Printf("Zombie %d has gone to rest.\n", pid)
				}
				exited = true
			}
		}
	}()
}
开发者ID:tillberg,项目名称:autorestart,代码行数:75,代码来源:zombie_cleanup.go

示例15: Run

func (c *Cmd) Run() error {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	err := c.Cmd.Start()
	if err != nil {
		return err
	}

	ready := map[int]bool{}

	status := syscall.WaitStatus(0)
	usage := syscall.Rusage{}
	for {
		pid, err := syscall.Wait4(c.Cmd.Process.Pid, &status, 0, &usage)
		if err != nil {
			return err
		}

		if !ready[pid] {
			_, _, errno := syscall.RawSyscall6(syscall.SYS_PRLIMIT64, uintptr(pid), syscall.RLIMIT_CPU, uintptr(unsafe.Pointer(&syscall.Rlimit{
				Cur: uint64(c.Limits.Cpu)/1e9 + 1,
				Max: uint64(c.Limits.Cpu)/1e9 + 1,
			})), 0, 0, 0)
			if errno != 0 {
				err = errno
				return err
			}

			_, _, errno = syscall.RawSyscall6(syscall.SYS_PRLIMIT64, uintptr(pid), syscall.RLIMIT_DATA, uintptr(unsafe.Pointer(&syscall.Rlimit{
				Cur: c.Limits.Memory,
				Max: c.Limits.Memory,
			})), 0, 0, 0)
			if errno != 0 {
				err = errno
				return err
			}

			ready[pid] = true
		}

		c.Usages.Cpu = time.Duration(usage.Utime.Nano())
		c.Usages.Memory = uint64(usage.Maxrss * (1 << 10))

		switch {
		case status.Exited():
			if status.ExitStatus() != 0 {
				return ExitError(status)
			}
			return nil

		case status.Signaled():
			return ExitError(status)

		case status.Stopped():
			switch {
			case status.StopSignal()&syscall.SIGTRAP > 0:
				regs := syscall.PtraceRegs{}
				err = syscall.PtraceGetRegs(pid, &regs)
				if err != nil {
					return err
				}

				switch regs.Orig_rax {
				case syscall.SYS_READ:
				case syscall.SYS_WRITE:
				case syscall.SYS_OPEN:
				case syscall.SYS_CLOSE:
				case syscall.SYS_STAT:
				case syscall.SYS_FSTAT:
				case syscall.SYS_LSTAT:
				case syscall.SYS_POLL:
				case syscall.SYS_LSEEK:
				case syscall.SYS_MMAP:
				case syscall.SYS_MPROTECT:
				case syscall.SYS_MUNMAP:
				case syscall.SYS_BRK:
				case syscall.SYS_RT_SIGACTION:
				case syscall.SYS_RT_SIGPROCMASK:
				case syscall.SYS_RT_SIGRETURN:
				case syscall.SYS_IOCTL:
				case syscall.SYS_PREAD64:
				case syscall.SYS_PWRITE64:
				case syscall.SYS_READV:
				case syscall.SYS_WRITEV:
				case syscall.SYS_ACCESS:
				case syscall.SYS_PIPE:
				case syscall.SYS_SELECT:
				case syscall.SYS_SCHED_YIELD:
				case syscall.SYS_MREMAP:
				case syscall.SYS_MSYNC:
				case syscall.SYS_MINCORE:
				case syscall.SYS_MADVISE:
				case syscall.SYS_SHMGET:
				case syscall.SYS_SHMAT:
				case syscall.SYS_SHMCTL:
				case syscall.SYS_DUP:
				case syscall.SYS_DUP2:
				case syscall.SYS_PAUSE:
				case syscall.SYS_NANOSLEEP:
//.........这里部分代码省略.........
开发者ID:hjr265,项目名称:jail.go,代码行数:101,代码来源:jail_linux.go


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