python获取mac窗口程序内容,如何从python应用程序获取Mac上正在运行的进程的完整列表...

博主尝试通过os.popen('ps-ea')获取Mac上类似'ps-ea'列出的所有进程,但发现只得到了部分属于当前shell的进程。尝试了其他shell命令如'sh-c/bin/ps-ea'等,效果不佳。最终,通过使用sudo并调用os模块的子进程功能,成功获取了完整进程列表。os.popen('ps aux')显示为有效的方法,适合用于wxpython应用来监控特定进程并检测其是否终止。
摘要由CSDN通过智能技术生成

I want to get the list of running processes on the Mac, similar to what you get from 'ps -ea'

I have tried os.popen('ps -ea') but this only lists a small subset of the processes, presumably those owned by the owning shell.

Other options I have tried are

'sh -c /bin/ps -ea'

'bash -c /bin/ps -ea'

'csh -c /bin/ps -ea'

Running as root via sudo

data = subprocess.Popen(['ps','ea'], stdout=subprocess.PIPE).stdout.readlines()

What other methods are there that might give me the full process information listing?

This is for a wx python app to monitor specific processes and spot when they die.

解决方案

os.popen('ps aux') looks like it's listing all processes for me.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值