exec.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. package os
  5. import (
  6. "runtime"
  7. "sync/atomic"
  8. "syscall"
  9. )
  10. // Process stores the information about a process created by StartProcess.
  11. type Process struct {
  12. Pid int
  13. handle uintptr
  14. isdone uint32 // process has been successfully waited on, non zero if true
  15. }
  16. func newProcess(pid int, handle uintptr) *Process {
  17. p := &Process{Pid: pid, handle: handle}
  18. runtime.SetFinalizer(p, (*Process).Release)
  19. return p
  20. }
  21. func (p *Process) setDone() {
  22. atomic.StoreUint32(&p.isdone, 1)
  23. }
  24. func (p *Process) done() bool {
  25. return atomic.LoadUint32(&p.isdone) > 0
  26. }
  27. // ProcAttr holds the attributes that will be applied to a new process
  28. // started by StartProcess.
  29. type ProcAttr struct {
  30. // If Dir is non-empty, the child changes into the directory before
  31. // creating the process.
  32. Dir string
  33. // If Env is non-nil, it gives the environment variables for the
  34. // new process in the form returned by Environ.
  35. // If it is nil, the result of Environ will be used.
  36. Env []string
  37. // Files specifies the open files inherited by the new process. The
  38. // first three entries correspond to standard input, standard output, and
  39. // standard error. An implementation may support additional entries,
  40. // depending on the underlying operating system. A nil entry corresponds
  41. // to that file being closed when the process starts.
  42. Files []*File
  43. // Operating system-specific process creation attributes.
  44. // Note that setting this field means that your program
  45. // may not execute properly or even compile on some
  46. // operating systems.
  47. Sys *syscall.SysProcAttr
  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. // Getpid returns the process id of the caller.
  57. func Getpid() int { return syscall.Getpid() }
  58. // Getppid returns the process id of the caller's parent.
  59. func Getppid() int { return syscall.Getppid() }