1 package os
2 3 import (
4 "errors"
5 "syscall"
6 )
7 8 var (
9 ErrNotImplementedDir = errors.New("directory setting not implemented")
10 ErrNotImplementedSys = errors.New("sys setting not implemented")
11 ErrNotImplementedFiles = errors.New("files setting not implemented")
12 )
13 14 type Signal interface {
15 String() string
16 Signal() // to distinguish from other Stringers
17 }
18 19 // Getpid returns the process id of the caller, or -1 if unavailable.
20 func Getpid() int {
21 return syscall.Getpid()
22 }
23 24 // Getppid returns the process id of the caller's parent, or -1 if unavailable.
25 func Getppid() int {
26 return syscall.Getppid()
27 }
28 29 type ProcAttr struct {
30 Dir string
31 Env []string
32 Files []*File
33 Sys *syscall.SysProcAttr
34 }
35 36 // ErrProcessDone indicates a Process has finished.
37 var ErrProcessDone = errors.New("os: process already finished")
38 39 type ProcessState struct {
40 }
41 42 func (p *ProcessState) String() string {
43 return "" // TODO
44 }
45 func (p *ProcessState) Success() bool {
46 return false // TODO
47 }
48 49 // Sys returns system-dependent exit information about
50 // the process. Convert it to the appropriate underlying
51 // type, such as syscall.WaitStatus on Unix, to access its contents.
52 func (p *ProcessState) Sys() interface{} {
53 return nil // TODO
54 }
55 56 func (p *ProcessState) Exited() bool {
57 return false // TODO
58 }
59 60 // ExitCode returns the exit code of the exited process, or -1
61 // if the process hasn't exited or was terminated by a signal.
62 func (p *ProcessState) ExitCode() int {
63 return -1 // TODO
64 }
65 66 type Process struct {
67 Pid int
68 }
69 70 // StartProcess starts a new process with the program, arguments and attributes specified by name, argv and attr.
71 // Arguments to the process (os.Args) are passed via argv.
72 func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error) {
73 return startProcess(name, argv, attr)
74 }
75 76 func (p *Process) Wait() (*ProcessState, error) {
77 if p.Pid == -1 {
78 return nil, syscall.EINVAL
79 }
80 return nil, ErrNotImplemented
81 }
82 83 func (p *Process) Kill() error {
84 return ErrNotImplemented
85 }
86 87 func (p *Process) Signal(sig Signal) error {
88 return ErrNotImplemented
89 }
90 91 func Ignore(sig ...Signal) {
92 // leave all the signals unaltered
93 return
94 }
95 96 // Release releases any resources associated with the Process p,
97 // rendering it unusable in the future.
98 // Release only needs to be called if Wait is not.
99 func (p *Process) Release() error {
100 return p.release()
101 }
102 103 // FindProcess looks for a running process by its pid.
104 // Keep compatibility with golang and always succeed and return new proc with pid on Linux.
105 func FindProcess(pid int) (*Process, error) {
106 return findProcess(pid)
107 }
108