Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersonQ committed Sep 12, 2023
1 parent 75d373d commit d5f052f
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions metric/system/process/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ import (
"github.com/elastic/gosigar/sys/windows"
)

var (
processQueryLimitedInfoAccess = windows.PROCESS_QUERY_LIMITED_INFORMATION

// processEntries
//processEntries = map[int]syscall.ProcessEntry32{}
)

// FetchPids returns a map and array of pids
func (procStats *Stats) FetchPids() (ProcsMap, []ProcState, error) {
pids, err := windows.EnumProcesses()
Expand Down Expand Up @@ -156,8 +149,11 @@ func FillPidMetrics(_ resolve.Resolver, pid int, state ProcState, _ func(string)
}

func getProcArgs(pid int) ([]string, error) {

handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess|windows.PROCESS_VM_READ, false, uint32(pid))
handle, err := syscall.OpenProcess(
windows.PROCESS_QUERY_LIMITED_INFORMATION|
windows.PROCESS_VM_READ,
false,
uint32(pid))
if err != nil {
return nil, fmt.Errorf("OpenProcess failed: %w", err)
}
Expand Down Expand Up @@ -186,7 +182,7 @@ func getProcArgs(pid int) ([]string, error) {
}

func getProcTimes(pid int) (uint64, uint64, uint64, error) {
handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess, false, uint32(pid))
handle, err := syscall.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
if err != nil {
return 0, 0, 0, fmt.Errorf("OpenProcess failed for pid=%v: %w", pid, err)
}
Expand All @@ -204,7 +200,11 @@ func getProcTimes(pid int) (uint64, uint64, uint64, error) {
}

func procMem(pid int) (uint64, uint64, error) {
handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess|windows.PROCESS_VM_READ, false, uint32(pid))
handle, err := syscall.OpenProcess(
windows.PROCESS_QUERY_LIMITED_INFORMATION|
windows.PROCESS_VM_READ,
false,
uint32(pid))
if err != nil {
return 0, 0, fmt.Errorf("OpenProcess failed for pid=%v: %w", pid, err)
}
Expand All @@ -221,7 +221,7 @@ func procMem(pid int) (uint64, uint64, error) {

// getProcName returns the process name associated with the PID.
func getProcName(pid int) (string, error) {
handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess, false, uint32(pid))
handle, err := syscall.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
if err != nil {
return "", fmt.Errorf("OpenProcess failed for pid=%v: %w", pid, err)
}
Expand All @@ -239,7 +239,7 @@ func getProcName(pid int) (string, error) {

// getProcStatus returns the status of a process.
func getPidStatus(pid int) (PidState, error) {
handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess, false, uint32(pid))
handle, err := syscall.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
if err != nil {
return Unknown, fmt.Errorf("OpenProcess failed for pid=%v: %w", pid, err)
}
Expand All @@ -261,7 +261,7 @@ func getPidStatus(pid int) (PidState, error) {

// getParentPid returns the parent process ID of a process.
func getParentPid(pid int) (int, error) {
handle, err := syscall.OpenProcess(processQueryLimitedInfoAccess, false, uint32(pid))
handle, err := syscall.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
if err != nil {
return 0, fmt.Errorf("OpenProcess failed for pid=%v: %w", pid, err)
}
Expand Down

0 comments on commit d5f052f

Please sign in to comment.