Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[process] Fix #607 properly check PID existence #713

Merged
merged 3 commits into from
Jul 27, 2019

Conversation

Lomanic
Copy link
Collaborator

@Lomanic Lomanic commented Jul 7, 2019

Fix #607

Use signal(0) on posix-compliant platforms (linux freebsd openbsd darwin)

Use OpenProcess+GetExitCodeProcess on windows

Tested on linux, windows (10, broken on XP), darwin, openbsd, freebsd

Regarding WinXP, this is failing because of PROCESS_QUERY_LIMITED_INFORMATION being introduced in in Vista. Calling windows.OpenProcess with windows.PROCESS_QUERY_INFORMATION works properly on WinXP (hinting that every calls to OpenProcess with PROCESS_QUERY_LIMITED_INFORMATION in gopsutil fail on WinXP). Handling this (opening process with right parameter according to Windows version) would complicate a little bit the code in process_window.go (while being prudent not too slow down gopsutil functions), I'm not sure if we should bother so much about WinXP now that it's deprecated for quite a few years.

@Lomanic Lomanic changed the title Fix #607 use signals Fix #607 use signals or OpenProcess+GetExitCodeProcess to check PID existence Jul 7, 2019
@Lomanic Lomanic changed the title Fix #607 use signals or OpenProcess+GetExitCodeProcess to check PID existence [process] Fix #607 properly check PID existence Jul 7, 2019
@Lomanic Lomanic requested a review from shirou July 23, 2019 15:46
@shirou
Copy link
Owner

shirou commented Jul 27, 2019

This is really great PR! thank you so much!

@shirou shirou merged commit 1edab19 into shirou:master Jul 27, 2019
if err != nil {
return false, err
}
err = proc.Signal(syscall.Signal(0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line actually breaks the whole story if you are running inside container, and you are tracking host processes.
More details can be found here:
influxdata/telegraf#6813

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

process.PidExists() is inefficient, should only check given PID
3 participants