forked from waffle-iron/core0
/
process.go
50 lines (40 loc) · 1.01 KB
/
process.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package process
import (
"github.com/g8os/core0/base/pm/core"
"github.com/g8os/core0/base/pm/stream"
"github.com/op/go-logging"
"syscall"
)
const (
CommandSystem = "core.system"
)
var (
log = logging.MustGetLogger("process")
)
type GetPID func() (int, error)
type PIDTable interface {
//Register atomic registration of PID. MUST grantee that that no wait4 will happen
//on any of the child process until the register operation is done.
Register(g GetPID) error
WaitPID(pid int) syscall.WaitStatus
}
//ProcessStats holds process cpu and memory usage
type ProcessStats struct {
CPU float64 `json:"cpu"`
RSS uint64 `json:"rss"`
VMS uint64 `json:"vms"`
Swap uint64 `json:"swap"`
Debug string `json:"debug,ommitempty"`
}
//Process interface
type Process interface {
Command() *core.Command
Run() (<-chan *stream.Message, error)
}
type Signaler interface {
Signal(sig syscall.Signal) error
}
type Stater interface {
Stats() *ProcessStats
}
type ProcessFactory func(PIDTable, *core.Command) Process