diff --git a/README.md b/README.md index f2458c3..969f3a7 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ MinGW or other GCC zlib & libpng (bitmap need it.) ``` -##### [Zlib & libpng Windows32 GCC's Course](https://github.com/go-vgo/Mingw32) +##### [Windows gcc installation Zlib & libpng tutorial](https://github.com/go-vgo/Mingw32) ##### [Download include zlib & libpng Windows64 GCC](https://github.com/go-vgo/Mingw) diff --git a/README_zh.md b/README_zh.md index 6268cc6..78739c2 100644 --- a/README_zh.md +++ b/README_zh.md @@ -57,7 +57,7 @@ MinGW or other GCC zlib & libpng (bitmap 依赖) ``` -##### [Zlib & libpng Windows32 GCC 教程](https://github.com/go-vgo/Mingw32) +##### [Windows GCC 安装 Zlib & libpng 教程](https://github.com/go-vgo/Mingw32) ##### [下载包含 zlib 和 libpng 的 64位 MinGW](https://github.com/go-vgo/Mingw) #### For everything else (Linux 等其他系统): diff --git a/vendor/github.com/shirou/gopsutil/process/process_windows.go b/vendor/github.com/shirou/gopsutil/process/process_windows.go index a1c3373..be91f97 100644 --- a/vendor/github.com/shirou/gopsutil/process/process_windows.go +++ b/vendor/github.com/shirou/gopsutil/process/process_windows.go @@ -3,6 +3,7 @@ package process import ( + "context" "fmt" "strings" "syscall" @@ -94,7 +95,7 @@ func init() { func Pids() ([]int32, error) { // inspired by https://gist.github.com/henkman/3083408 - // and https://github.com/giampaolo/psutil/blob/1c3a15f637521ba5c0031283da39c733fda53e4c/psutil/arch/windows/process_info.c#L315-L329 + // and https://github.com/giampaolo/psutil/blob/1c3a15f637521ba5c0031283da39c733fda53e4c/psutil/arch/windows/process_info.c#L315-L329 var ret []int32 var read uint32 = 0 var psSize uint32 = 1024 @@ -119,20 +120,21 @@ func Pids() ([]int32, error) { } func (p *Process) Ppid() (int32, error) { - dst, err := GetWin32Proc(p.Pid) + ppid, _, _, err := getFromSnapProcess(p.Pid) if err != nil { return 0, err } - - return int32(dst[0].ParentProcessID), nil + return ppid, nil } func GetWin32Proc(pid int32) ([]Win32_Process, error) { var dst []Win32_Process query := fmt.Sprintf("WHERE ProcessId = %d", pid) q := wmi.CreateQuery(&dst, query) - - if err := wmi.Query(q, &dst); err != nil { + ctx, cancel := context.WithTimeout(context.Background(), common.Timeout) + defer cancel() + err := common.WMIQueryWithContext(ctx, q, &dst) + if err != nil { return []Win32_Process{}, fmt.Errorf("could not get win32Proc: %s", err) } @@ -144,11 +146,11 @@ func GetWin32Proc(pid int32) ([]Win32_Process, error) { } func (p *Process) Name() (string, error) { - dst, err := GetWin32Proc(p.Pid) + _, _, name, err := getFromSnapProcess(p.Pid) if err != nil { return "", fmt.Errorf("could not get Name: %s", err) } - return dst[0].Name, nil + return name, nil } func (p *Process) Exe() (string, error) { @@ -334,7 +336,9 @@ func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) { func (p *Process) Children() ([]*Process, error) { var dst []Win32_Process query := wmi.CreateQuery(&dst, fmt.Sprintf("Where ParentProcessId = %d", p.Pid)) - err := wmi.Query(query, &dst) + ctx, cancel := context.WithTimeout(context.Background(), common.Timeout) + defer cancel() + err := common.WMIQueryWithContext(ctx, query, &dst) if err != nil { return nil, err } @@ -406,7 +410,7 @@ func (p *Process) Kill() error { return common.ErrNotImplementedError } -func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) { +func getFromSnapProcess(pid int32) (int32, int32, string, error) { snap := w32.CreateToolhelp32Snapshot(w32.TH32CS_SNAPPROCESS, uint32(pid)) if snap == 0 { return 0, 0, "", windows.GetLastError() @@ -434,19 +438,14 @@ func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) { // Get processes func Processes() ([]*Process, error) { - var dst []Win32_Process - q := wmi.CreateQuery(&dst, "") - err := wmi.Query(q, &dst) + pids, err := Pids() if err != nil { - return []*Process{}, err - } - if len(dst) == 0 { - return []*Process{}, fmt.Errorf("could not get Process") + return []*Process{}, fmt.Errorf("could not get Processes %s", err) } results := []*Process{} - for _, proc := range dst { - p, err := NewProcess(int32(proc.ProcessID)) + for _, pid := range pids { + p, err := NewProcess(int32(pid)) if err != nil { continue } diff --git a/vendor/vendor.json b/vendor/vendor.json index f929583..952c76d 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -75,10 +75,10 @@ "revisionTime": "2017-11-12T16:40:41Z" }, { - "checksumSHA1": "ahQMAy3zGepU4ero/dAi3Bputkk=", + "checksumSHA1": "v3USS/LSyBuVc/DMBV+GX4ikZ5M=", "path": "github.com/shirou/gopsutil/process", - "revision": "a8bc26299477e53c4ca89f7ec60160a74d4c0890", - "revisionTime": "2017-11-12T16:40:41Z" + "revision": "bfe3c2e8f406bf352bc8df81f98c752224867349", + "revisionTime": "2017-11-21T12:01:14Z" }, { "checksumSHA1": "Nve7SpDmjsv6+rhkXAkfg/UQx94=",