Source file src/pkg/os/exec.go
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.
4
5 package os
6
7 import (
8 "runtime"
9 "syscall"
10 )
11
12 // Process stores the information about a process created by StartProcess.
13 type Process struct {
14 Pid int
15 handle uintptr
16 done bool // process has been successfully waited on
17 }
18
19 func newProcess(pid int, handle uintptr) *Process {
20 p := &Process{Pid: pid, handle: handle}
21 runtime.SetFinalizer(p, (*Process).Release)
22 return p
23 }
24
25 // ProcAttr holds the attributes that will be applied to a new process
26 // started by StartProcess.
27 type ProcAttr struct {
28 // If Dir is non-empty, the child changes into the directory before
29 // creating the process.
30 Dir string
31 // If Env is non-nil, it gives the environment variables for the
32 // new process in the form returned by Environ.
33 // If it is nil, the result of Environ will be used.
34 Env []string
35 // Files specifies the open files inherited by the new process. The
36 // first three entries correspond to standard input, standard output, and
37 // standard error. An implementation may support additional entries,
38 // depending on the underlying operating system. A nil entry corresponds
39 // to that file being closed when the process starts.
40 Files []*File
41
42 // Operating system-specific process creation attributes.
43 // Note that setting this field means that your program
44 // may not execute properly or even compile on some
45 // operating systems.
46 Sys *syscall.SysProcAttr
47 }
48
49 // A Signal represents an operating system signal.
50 // The usual underlying implementation is operating system-dependent:
51 // on Unix it is syscall.Signal.
52 type Signal interface {
53 String() string
54 Signal() // to distinguish from other Stringers
55 }
56
57 // The only signal values guaranteed to be present on all systems
58 // are Interrupt (send the process an interrupt) and
59 // Kill (force the process to exit).
60 var (
61 Interrupt Signal = syscall.SIGINT
62 Kill Signal = syscall.SIGKILL
63 )
64
65 // Getpid returns the process id of the caller.
66 func Getpid() int { return syscall.Getpid() }
67
68 // Getppid returns the process id of the caller's parent.
69 func Getppid() int { return syscall.Getppid() }