process.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package hcsshim
  2. import (
  3. "io"
  4. "time"
  5. "github.com/Microsoft/hcsshim/internal/hcs"
  6. )
  7. // ContainerError is an error encountered in HCS
  8. type process struct {
  9. p *hcs.Process
  10. }
  11. // Pid returns the process ID of the process within the container.
  12. func (process *process) Pid() int {
  13. return process.p.Pid()
  14. }
  15. // Kill signals the process to terminate but does not wait for it to finish terminating.
  16. func (process *process) Kill() error {
  17. return convertProcessError(process.p.Kill(), process)
  18. }
  19. // Wait waits for the process to exit.
  20. func (process *process) Wait() error {
  21. return convertProcessError(process.p.Wait(), process)
  22. }
  23. // WaitTimeout waits for the process to exit or the duration to elapse. It returns
  24. // false if timeout occurs.
  25. func (process *process) WaitTimeout(timeout time.Duration) error {
  26. return convertProcessError(process.p.WaitTimeout(timeout), process)
  27. }
  28. // ExitCode returns the exit code of the process. The process must have
  29. // already terminated.
  30. func (process *process) ExitCode() (int, error) {
  31. code, err := process.p.ExitCode()
  32. if err != nil {
  33. err = convertProcessError(err, process)
  34. }
  35. return code, err
  36. }
  37. // ResizeConsole resizes the console of the process.
  38. func (process *process) ResizeConsole(width, height uint16) error {
  39. return convertProcessError(process.p.ResizeConsole(width, height), process)
  40. }
  41. // Stdio returns the stdin, stdout, and stderr pipes, respectively. Closing
  42. // these pipes does not close the underlying pipes; it should be possible to
  43. // call this multiple times to get multiple interfaces.
  44. func (process *process) Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, error) {
  45. stdin, stdout, stderr, err := process.p.Stdio()
  46. if err != nil {
  47. err = convertProcessError(err, process)
  48. }
  49. return stdin, stdout, stderr, err
  50. }
  51. // CloseStdin closes the write side of the stdin pipe so that the process is
  52. // notified on the read side that there is no more data in stdin.
  53. func (process *process) CloseStdin() error {
  54. return convertProcessError(process.p.CloseStdin(), process)
  55. }
  56. // Close cleans up any state associated with the process but does not kill
  57. // or wait on it.
  58. func (process *process) Close() error {
  59. return convertProcessError(process.p.Close(), process)
  60. }