Reputation: 31
So basically I have Created this application in python that uses Psutil. Iam using it to suspend and resume a process at very high speeds. Although it does work for the majority of the process it doesn't work for some. Ill provide the error code down below but if you do decide to help please be very noob friendly Iam just getting started in python
import psutil
import time
import subprocess
print("Auto Suspender")
condition = 10
subprocess.call("taskkill /Program example")
print("Program Example has been killed :)")
time.sleep(1)
somepid = int(input("What is Process ID ?"))
p = psutil.Process(somepid)
print("Working...")
time.sleep(0.5)
while condition == 10:
choice = input("1__Suspend")
if (choice == "1"):
while condition == 10:
p.suspend()
print("Suspended !")
time.sleep(0.1)
p.resume
print("Resumed !")
else:
print("Invalid response")`enter code here`
ERROR Iam getting
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\psutil\_pswindows.py", line 207, in wrapper
return fun(self, *args, **kwargs)
File "C:\Python34\lib\site-packages\psutil\_pswindows.py", line 366, in suspend
return cext.proc_suspend(self.pid)
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Jacob/PycharmProjects/Suspender.111/Main.py", line 26, in <module>
p.suspend()
File "C:\Python34\lib\site-packages\psutil\__init__.py", line 273, in wrapper
return fun(self, *args, **kwargs)
File "C:\Python34\lib\site-packages\psutil\__init__.py", line 1025, in suspend
self._proc.suspend()
File "C:\Python34\lib\site-packages\psutil\_pswindows.py", line 213, in wrapper
raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: (pid=3076)
Process finished with exit code 1
Upvotes: 3
Views: 2229
Reputation: 1039
I think about that you do not have sufficient privileges for process suspending. Some processes in Windows OS (and in other OSes too) runs under another user account, in Windows typically under System account, and normal user can not suspend or kill this processes. Try running your script as Administrator user and there maybe chance that script will be working.
Upvotes: 2