我想检查程序是否正在运行,所以我搜索并尝试了this,方法如下:
import psutil
if "notepad.exe" in (p.name() for p in psutil.process_iter()):
print('program is running')
else:
print('not running')但是我得到了这个错误:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "~/temp.py", line 2, in <module>
if "notepad.exe" in (p.name() for p in psutil.process_iter()):
File "~/temp.py", line 2, in <genexpr>
if "notepad.exe" in (p.name() for p in psutil.process_iter()):
File "~\Python\Python38-32\lib\site-packages\psutil\__init__.py", line 630, in name
name = self._proc.name()
File "~\Python\Python38-32\lib\site-packages\psutil\_pswindows.py", line 750, in name
return os.path.basename(self.exe())
File "~\Python\Python38-32\lib\site-packages\psutil\_pswindows.py", line 681, in wrapper
raise convert_oserror(err, pid=self.pid, name=self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=6836)
Process finished with exit code 1在这段简单的代码中,我做错了什么吗?或者,还有其他方法吗?
编辑:对不起,我忘了提到即时通讯在windows上,而不是linux上,你能给我windows平台的解决方案吗?
发布于 2020-06-01 00:14:35
您可能需要系统上的管理员/ root权限。
如果您可以获得命令提示符,请在运行python之前尝试使用sudo将您的权限提升到根用户。或为您的用户提供管理员级别访问权限。
https://stackoverflow.com/questions/62118693
复制相似问题