-
Notifications
You must be signed in to change notification settings - Fork 891
/
ps.go
77 lines (63 loc) · 1.72 KB
/
ps.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
package robotgo
import ps "github.com/vcaesar/gops"
// Nps process struct
type Nps struct {
Pid int
Name string
}
// Pids get the all process id
func Pids() ([]int, error) {
return ps.Pids()
}
// PidExists determine whether the process exists
func PidExists(pid int) (bool, error) {
return ps.PidExists(pid)
}
// Process get the all process struct
func Process() ([]Nps, error) {
var npsArr []Nps
nps, err := ps.Process()
for i := 0; i < len(nps); i++ {
np := Nps{
nps[i].Pid,
nps[i].Name,
}
npsArr = append(npsArr, np)
}
return npsArr, err
}
// FindName find the process name by the process id
func FindName(pid int) (string, error) {
return ps.FindName(pid)
}
// FindNames find the all process name
func FindNames() ([]string, error) {
return ps.FindNames()
}
// FindIds finds the all processes named with a subset
// of "name" (case insensitive),
// return matched IDs.
func FindIds(name string) ([]int, error) {
return ps.FindIds(name)
}
// FindPath find the process path by the process pid
func FindPath(pid int) (string, error) {
return ps.FindPath(pid)
}
// Run run a cmd shell
func Run(path string) ([]byte, error) {
return ps.Run(path)
}
// Kill kill the process by PID
func Kill(pid int) error {
return ps.Kill(pid)
}