Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
79f4358f
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,发现更多精彩内容 >>
提交
79f4358f
编写于
3月 20, 2015
作者:
W
WAKAYAMA Shirou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
process: Exe, Cmdline and Name implemented in windows by using wmic
上级
5f8b99aa
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
92 addition
and
27 deletion
+92
-27
README.rst
README.rst
+4
-4
process/process_test.go
process/process_test.go
+26
-5
process/process_windows.go
process/process_windows.go
+62
-18
未找到文件。
README.rst
浏览文件 @
79f4358f
...
...
@@ -152,8 +152,8 @@ Process class
name Linux FreeBSD MacOSX Windows
pid x x x x
ppid x x x x
name x x x
cmdline x x
name x x x
x
cmdline x x
x
create_time x
status x x x
cwd x
...
...
@@ -162,10 +162,10 @@ uids x x x
gids x x x
terminal x x x
io_counters x
nice x x
nice x x
x
num_fds x
num_ctx_switches x
num_threads x x x
num_threads x x x
x
cpu_times x
memory_info x x x
memory_info_ex x
...
...
process/process_test.go
浏览文件 @
79f4358f
...
...
@@ -89,8 +89,7 @@ func Test_Process_CmdLine(t *testing.T) {
if
err
!=
nil
{
t
.
Errorf
(
"geting ppid error %v"
,
err
)
}
if
!
strings
.
HasSuffix
(
v
,
"/_test/process.test"
)
{
if
!
strings
.
Contains
(
v
,
"process.test"
)
{
t
.
Errorf
(
"invalid cmd line %v"
,
v
)
}
}
...
...
@@ -165,10 +164,21 @@ func Test_Process_Nice(t *testing.T) {
if
err
!=
nil
{
t
.
Errorf
(
"geting nice error %v"
,
err
)
}
if
n
!=
0
&&
n
!=
20
{
if
n
!=
0
&&
n
!=
20
&&
n
!=
8
{
t
.
Errorf
(
"invalid nice: %d"
,
n
)
}
}
func
Test_Process_NumThread
(
t
*
testing
.
T
)
{
p
:=
testGetProcess
()
n
,
err
:=
p
.
NumThreads
()
if
err
!=
nil
{
t
.
Errorf
(
"geting NumThread error %v"
,
err
)
}
if
n
<
0
{
t
.
Errorf
(
"invalid NumThread: %d"
,
n
)
}
}
func
Test_Process_Name
(
t
*
testing
.
T
)
{
p
:=
testGetProcess
()
...
...
@@ -177,8 +187,19 @@ func Test_Process_Name(t *testing.T) {
if
err
!=
nil
{
t
.
Errorf
(
"geting name error %v"
,
err
)
}
if
n
!=
"process.test"
{
t
.
Errorf
(
"invalid name %s"
,
n
)
if
!
strings
.
Contains
(
n
,
"process.test"
)
{
t
.
Errorf
(
"invalid Exe %s"
,
n
)
}
}
func
Test_Process_Exe
(
t
*
testing
.
T
)
{
p
:=
testGetProcess
()
n
,
err
:=
p
.
Exe
()
if
err
!=
nil
{
t
.
Errorf
(
"geting Exe error %v"
,
err
)
}
if
!
strings
.
Contains
(
n
,
"process.test"
)
{
t
.
Errorf
(
"invalid Exe %s"
,
n
)
}
}
...
...
process/process_windows.go
浏览文件 @
79f4358f
...
...
@@ -4,6 +4,8 @@ package process
import
(
"errors"
"fmt"
"strconv"
"syscall"
"unsafe"
...
...
@@ -42,13 +44,13 @@ type MemoryMapsStat struct {
}
func
Pids
()
([]
int32
,
error
)
{
var
ret
[]
int32
procs
,
err
:=
processes
()
if
err
!=
nil
{
return
ret
,
nil
}
for
_
,
proc
:=
range
procs
{
ret
=
append
(
ret
,
proc
.
Pid
)
}
...
...
@@ -64,18 +66,38 @@ func (p *Process) Ppid() (int32, error) {
return
ret
,
nil
}
func
(
p
*
Process
)
Name
()
(
string
,
error
)
{
name
:=
""
return
name
,
common
.
NotImplementedError
query
:=
fmt
.
Sprintf
(
"ProcessId = %d"
,
p
.
Pid
)
lines
,
err
:=
common
.
GetWmic
(
"process"
,
"where"
,
query
,
"get"
,
"Name"
)
if
err
!=
nil
{
return
""
,
err
}
if
len
(
lines
)
==
0
{
return
""
,
fmt
.
Errorf
(
"could not get Name"
)
}
return
lines
[
0
][
1
],
nil
}
func
(
p
*
Process
)
Exe
()
(
string
,
error
)
{
_
,
_
,
ret
,
err
:=
p
.
getFromSnapProcess
(
p
.
Pid
)
query
:=
fmt
.
Sprintf
(
"ProcessId = %d"
,
p
.
Pid
)
lines
,
err
:=
common
.
GetWmic
(
"process"
,
"where"
,
query
,
"get"
,
"ExecutablePath"
)
if
err
!=
nil
{
return
""
,
err
}
return
ret
,
nil
if
len
(
lines
)
==
0
{
return
""
,
fmt
.
Errorf
(
"could not get ExecutablePath"
)
}
return
lines
[
0
][
1
],
nil
}
func
(
p
*
Process
)
Cmdline
()
(
string
,
error
)
{
return
""
,
common
.
NotImplementedError
query
:=
fmt
.
Sprintf
(
"ProcessId = %d"
,
p
.
Pid
)
lines
,
err
:=
common
.
GetWmic
(
"process"
,
"where"
,
query
,
"get"
,
"CommandLine"
)
if
err
!=
nil
{
return
""
,
err
}
if
len
(
lines
)
==
0
{
return
""
,
fmt
.
Errorf
(
"could not get command line"
)
}
return
lines
[
0
][
1
],
nil
}
func
(
p
*
Process
)
Cwd
()
(
string
,
error
)
{
return
""
,
common
.
NotImplementedError
...
...
@@ -101,8 +123,23 @@ func (p *Process) Gids() ([]int32, error) {
func
(
p
*
Process
)
Terminal
()
(
string
,
error
)
{
return
""
,
common
.
NotImplementedError
}
// Nice returnes priority in Windows
func
(
p
*
Process
)
Nice
()
(
int32
,
error
)
{
return
0
,
common
.
NotImplementedError
query
:=
fmt
.
Sprintf
(
"ProcessId = %d"
,
p
.
Pid
)
lines
,
err
:=
common
.
GetWmic
(
"process"
,
"where"
,
query
,
"get"
,
"Priority"
)
if
err
!=
nil
{
return
0
,
err
}
if
len
(
lines
)
==
0
{
return
0
,
fmt
.
Errorf
(
"could not get command line"
)
}
priority
,
err
:=
strconv
.
Atoi
(
lines
[
0
][
1
])
if
err
!=
nil
{
return
0
,
err
}
return
int32
(
priority
),
nil
}
func
(
p
*
Process
)
IOnice
()
(
int32
,
error
)
{
return
0
,
common
.
NotImplementedError
...
...
@@ -122,11 +159,20 @@ func (p *Process) NumFDs() (int32, error) {
return
0
,
common
.
NotImplementedError
}
func
(
p
*
Process
)
NumThreads
()
(
int32
,
error
)
{
_
,
ret
,
_
,
err
:=
p
.
getFromSnapProcess
(
p
.
Pid
)
query
:=
fmt
.
Sprintf
(
"ProcessId = %d"
,
p
.
Pid
)
lines
,
err
:=
common
.
GetWmic
(
"process"
,
"where"
,
query
,
"get"
,
"ThreadCount"
)
if
err
!=
nil
{
return
0
,
err
}
return
ret
,
nil
if
len
(
lines
)
==
0
{
return
0
,
fmt
.
Errorf
(
"could not get command line"
)
}
count
,
err
:=
strconv
.
Atoi
(
lines
[
0
][
1
])
if
err
!=
nil
{
return
0
,
err
}
return
int32
(
count
),
nil
}
func
(
p
*
Process
)
Threads
()
(
map
[
string
]
string
,
error
)
{
ret
:=
make
(
map
[
string
]
string
,
0
)
...
...
@@ -220,21 +266,19 @@ func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) {
// Get processes
func
processes
()
([]
*
Process
,
error
)
{
ps
:=
make
([]
uint32
,
255
)
var
read
uint32
if
w32
.
EnumProcesses
(
ps
,
uint32
(
len
(
ps
)),
&
read
)
==
false
{
return
nil
,
syscall
.
GetLastError
()
lines
,
err
:=
common
.
GetWmic
(
"process"
,
"get"
,
"processid"
)
if
err
!=
nil
{
return
nil
,
err
}
var
results
[]
*
Process
dwardSize
:=
uint32
(
4
)
for
_
,
pid
:=
range
ps
[
:
read
/
dwardSize
]
{
if
pid
==
0
{
for
_
,
l
:=
range
lines
{
pid
,
err
:=
strconv
.
Atoi
(
l
[
1
])
if
err
!=
nil
{
continue
}
p
,
err
:=
NewProcess
(
int32
(
pid
))
if
err
!=
nil
{
break
continue
}
results
=
append
(
results
,
p
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录