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

How to get the CPU usage of the background process on the windows platform. #466

Closed
ArnoldFu opened this issue Dec 8, 2017 · 8 comments
Closed

Comments

@ArnoldFu
Copy link

ArnoldFu commented Dec 8, 2017

The 'process.CPUPercent()' method works for front process, but it does not works for background process. The program prompts 'could not get CreationDate: Access is denied'.
How to get the CPU usage of the background process on the windows platform.

@Lomanic
Copy link
Collaborator

Lomanic commented Dec 8, 2017

I can reproduce, it occurs for processes run by NT AUTHORITY\SYSTEM, NT AUTHORITY\NETWROK, NT AUTHORITY\LOCAL and it looks like it has to do with SeDebugPrivilege. With admin rights it seems doable to port this C# program to enable SeDebugPrivilege for the current process with windows syscalls. Python's psutil indeed has a function psutil_set_se_debug called here.

I can work on this during the weekend if nobody takes this task.

@shirou
Copy link
Owner

shirou commented Dec 9, 2017

@Lomanic Thank you! Since I can not work this weekend, I would very appreciate if you can work on this issue.

@ArnoldFu
Copy link
Author

@Lomanic
Yes, the processes run by NT AUTHORITY\SYSTEM.
I have already run the program as an administrator, but it doesn't works.
I would very grateful if you could help me solve this problem.

Lomanic added a commit to Oxibox/gopsutil that referenced this issue Dec 19, 2017
Problem is an "Access denied" on adjustTokenPrivileges() in
enableSeDebugPrivilege()
@Lomanic
Copy link
Collaborator

Lomanic commented Dec 19, 2017

So far I have the above commit, but it is currently not functional (Access Denied even as admin), I don't know what the problem is, maybe I will look at it in the future. Anybody can take this task in the mean time.

@fanlw0816
Copy link

I have also encountered this problem, Is this problem solved?

@onkarbanerjee
Copy link

Is this solved. I dont think it is yet.

@Lomanic
Copy link
Collaborator

Lomanic commented Oct 30, 2019

This was fixed by the commit that closed this issue, as usual on Github.

@cwegener
Copy link

This seems silly.

SeDebugPrivilege was originally introduced by Jay Loden in version 0.1.1 of psutil for the purposes of killing a process. giampaolo/psutil@4a9678b

Whilst that original implementation is still very questionable (why does psutil have a need to bypass the Win32 security system by using the SeDebugPrivilege instead of returning an actual 'access denied' error if the user who runs psutil does not have permissions to kill the process? Does psutil do the same bypassing of the OS security on non-Windows platforms?), at least the original implementation was strictly limited to psutil's kill() API.

Unfortunately, nobody seems to have asked that question when this feature was originally implemented, and now everyone seems to be blindly following this bad example.

E.g. in psutil, this bad example escalated many years later to running THE WHOLE psutil process with the SeDebugPrivilege ALL THE TIME and not only for the limited task for which it was originally implemented (the kill() API. And also because the original implementation was probably faulty ...)

giampaolo/psutil#1429

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

No branches or pull requests

6 participants