1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
13 // The only signal values guaranteed to be present in the os package
14 // on all systems are Interrupt (send the process an interrupt) and
15 // Kill (force the process to exit). Interrupt is not implemented on
16 // Windows; using it with os.Process.Signal will return an error.
18 Interrupt Signal
= syscall
.SIGINT
19 Kill Signal
= syscall
.SIGKILL
22 func startProcess(name
string, argv
[]string, attr
*ProcAttr
) (p
*Process
, err error
) {
23 // If there is no SysProcAttr (ie. no Chroot or changed
24 // UID/GID), double-check existence of the directory we want
25 // to chdir into. We can make the error clearer this way.
26 if attr
!= nil && attr
.Sys
== nil && attr
.Dir
!= "" {
27 if _
, err
:= Stat(attr
.Dir
); err
!= nil {
28 pe
:= err
.(*PathError
)
34 sysattr
:= &syscall
.ProcAttr
{
39 if sysattr
.Env
== nil {
40 sysattr
.Env
= Environ()
42 for _
, f
:= range attr
.Files
{
43 sysattr
.Files
= append(sysattr
.Files
, f
.Fd())
46 pid
, h
, e
:= syscall
.StartProcess(name
, argv
, sysattr
)
48 return nil, &PathError
{"fork/exec", name
, e
}
50 return newProcess(pid
, h
), nil
53 func (p
*Process
) kill() error
{
57 // ProcessState stores information about a process, as reported by Wait.
58 type ProcessState
struct {
59 pid
int // The process's id.
60 status syscall
.WaitStatus
// System-dependent status info.
61 rusage
*syscall
.Rusage
64 // Pid returns the process id of the exited process.
65 func (p
*ProcessState
) Pid() int {
69 func (p
*ProcessState
) exited() bool {
70 return p
.status
.Exited()
73 func (p
*ProcessState
) success() bool {
74 return p
.status
.ExitStatus() == 0
77 func (p
*ProcessState
) sys() interface{} {
81 func (p
*ProcessState
) sysUsage() interface{} {
85 func (p
*ProcessState
) String() string {
89 status
:= p
.Sys().(syscall
.WaitStatus
)
93 res
= "exit status " + itoa(status
.ExitStatus())
94 case status
.Signaled():
95 res
= "signal: " + status
.Signal().String()
96 case status
.Stopped():
97 res
= "stop signal: " + status
.StopSignal().String()
98 if status
.StopSignal() == syscall
.SIGTRAP
&& status
.TrapCause() != 0 {
99 res
+= " (trap " + itoa(status
.TrapCause()) + ")"
101 case status
.Continued():
104 if status
.CoreDump() {
105 res
+= " (core dumped)"