Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
2d297dfb
G
Gopsutil
项目概览
Canread
/
Gopsutil
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gopsutil
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2d297dfb
编写于
11月 24, 2015
作者:
S
shirou
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #113 from shirou/add_process_children
process[linux,freebsd,darwin]: implements Children using pgrep.
上级
54a6c186
dd133008
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
84 addition
and
6 deletion
+84
-6
README.rst
README.rst
+1
-1
internal/common/common_unix.go
internal/common/common_unix.go
+26
-0
process/process_darwin.go
process/process_darwin.go
+14
-2
process/process_freebsd.go
process/process_freebsd.go
+14
-2
process/process_linux.go
process/process_linux.go
+13
-1
process/process_test.go
process/process_test.go
+16
-0
未找到文件。
README.rst
浏览文件 @
2d297dfb
...
...
@@ -195,7 +195,7 @@ cpu_percent x x
cpu_affinity
memory_percent
parent x x
children
children
x x x
connections x x
is_running
================ ===== ======= ====== =======
...
...
internal/common/common_unix.go
浏览文件 @
2d297dfb
...
...
@@ -38,3 +38,29 @@ func CallLsof(invoke Invoker, pid int32, args ...string) ([]string, error) {
}
return
ret
,
nil
}
func
CallPgrep
(
invoke
Invoker
,
pid
int32
)
([]
int32
,
error
)
{
var
cmd
[]
string
cmd
=
[]
string
{
"-P"
,
strconv
.
Itoa
(
int
(
pid
))}
pgrep
,
err
:=
exec
.
LookPath
(
"pgrep"
)
if
err
!=
nil
{
return
[]
int32
{},
err
}
out
,
err
:=
invoke
.
Command
(
pgrep
,
cmd
...
)
if
err
!=
nil
{
return
[]
int32
{},
err
}
lines
:=
strings
.
Split
(
string
(
out
),
"
\n
"
)
ret
:=
make
([]
int32
,
0
,
len
(
lines
))
for
_
,
l
:=
range
lines
{
if
len
(
l
)
==
0
{
continue
}
i
,
err
:=
strconv
.
Atoi
(
l
)
if
err
!=
nil
{
continue
}
ret
=
append
(
ret
,
int32
(
i
))
}
return
ret
,
nil
}
process/process_darwin.go
浏览文件 @
2d297dfb
...
...
@@ -10,8 +10,8 @@ import (
"syscall"
"unsafe"
"github.com/shirou/gopsutil/internal/common"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/internal/common"
"github.com/shirou/gopsutil/net"
)
...
...
@@ -278,7 +278,19 @@ func (p *Process) MemoryPercent() (float32, error) {
}
func
(
p
*
Process
)
Children
()
([]
*
Process
,
error
)
{
return
nil
,
common
.
NotImplementedError
pids
,
err
:=
common
.
CallPgrep
(
invoke
,
p
.
Pid
)
if
err
!=
nil
{
return
nil
,
err
}
ret
:=
make
([]
*
Process
,
0
,
len
(
pids
))
for
_
,
pid
:=
range
pids
{
np
,
err
:=
NewProcess
(
pid
)
if
err
!=
nil
{
return
nil
,
err
}
ret
=
append
(
ret
,
np
)
}
return
ret
,
nil
}
func
(
p
*
Process
)
OpenFiles
()
([]
OpenFilesStat
,
error
)
{
...
...
process/process_freebsd.go
浏览文件 @
2d297dfb
...
...
@@ -7,8 +7,8 @@ import (
"encoding/binary"
"unsafe"
"github.com/shirou/gopsutil/internal/common"
cpu
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/internal/common"
net
"github.com/shirou/gopsutil/net"
)
...
...
@@ -168,7 +168,19 @@ func (p *Process) MemoryPercent() (float32, error) {
}
func
(
p
*
Process
)
Children
()
([]
*
Process
,
error
)
{
return
nil
,
common
.
NotImplementedError
pids
,
err
:=
common
.
CallPgrep
(
invoke
,
p
.
Pid
)
if
err
!=
nil
{
return
nil
,
err
}
ret
:=
make
([]
*
Process
,
0
,
len
(
pids
))
for
_
,
pid
:=
range
pids
{
np
,
err
:=
NewProcess
(
pid
)
if
err
!=
nil
{
return
nil
,
err
}
ret
=
append
(
ret
,
np
)
}
return
ret
,
nil
}
func
(
p
*
Process
)
OpenFiles
()
([]
OpenFilesStat
,
error
)
{
...
...
process/process_linux.go
浏览文件 @
2d297dfb
...
...
@@ -203,7 +203,19 @@ func (p *Process) MemoryPercent() (float32, error) {
}
func
(
p
*
Process
)
Children
()
([]
*
Process
,
error
)
{
return
nil
,
common
.
NotImplementedError
pids
,
err
:=
common
.
CallPgrep
(
invoke
,
p
.
Pid
)
if
err
!=
nil
{
return
nil
,
err
}
ret
:=
make
([]
*
Process
,
0
,
len
(
pids
))
for
_
,
pid
:=
range
pids
{
np
,
err
:=
NewProcess
(
pid
)
if
err
!=
nil
{
return
nil
,
err
}
ret
=
append
(
ret
,
np
)
}
return
ret
,
nil
}
func
(
p
*
Process
)
OpenFiles
()
([]
OpenFilesStat
,
error
)
{
...
...
process/process_test.go
浏览文件 @
2d297dfb
...
...
@@ -312,3 +312,19 @@ func Test_Connections(t *testing.T) {
t
.
Fatalf
(
"wrong connections"
)
}
}
func
Test_Children
(
t
*
testing
.
T
)
{
p
,
err
:=
NewProcess
(
1
)
if
err
!=
nil
{
t
.
Fatalf
(
"new process error %v"
,
err
)
}
c
,
err
:=
p
.
Children
()
if
err
!=
nil
{
t
.
Fatalf
(
"error %v"
,
err
)
}
if
len
(
c
)
==
0
{
t
.
Fatalf
(
"children is empty"
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录