[英]Is it possible to get the PID of the sibling process by using `psutil` or any other Python packages?
I am running a set of parallel computing. 我正在运行一组并行计算。
I am trying to use psutil
to track the computation (If someone has a better solution, plz tell me) 我正在尝试使用
psutil
跟踪计算(如果有人有更好的解决方案,请告诉我)
>>> p = psutil.Process(4370)
>>> p.cpu_percent()
0.0
>>> p.cpu_times()
pcputimes(user=6440.78, system=5.4, children_user=0.0, children_system=0.0)
>>> p.cpu_affinity()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
>>> p.cpu_num()
2
I guess the last one get a value of 2 for p.cpu_num()
indicates that this job is on parallel computing, there is another sibling process doing the computing simultaneously. 我猜最后一个
p.cpu_num()
的值为2表示此工作是在并行计算上,还有另一个同级进程在同时进行计算。
Is it possible to get the PID of the sibling process by using psutil
or any other Python packages? 是否可以通过使用
psutil
或任何其他Python包来获取同级进程的PID?
" I guess the last one get a value of
2
forp.cpu_num()
indicates that this job is on parallel computing "“ 我想最后一个
p.cpu_num()
的值为2
表示此作业正在并行计算上 ”
No, this does not mean anything other but that a process p
is currently mapped onto the second CPU from all CPU-s available ( O/S task scheduler decides on which CPU/core a job is going to get executed + the process-affinity settings may restrict such a choice ) 不,这并不意味着什么,而是当前将进程
p
从所有可用CPU映射到第二个CPU(O / S任务调度程序确定要在哪个CPU /核心上执行作业+进程亲和力设置可能会限制这种选择)
>>> print( p.cpu_num.__doc__ )
Return what CPU this process is currently running on.
The returned number should be <= psutil.cpu_count()
and <= len(psutil.cpu_percent(percpu=True)).
It may be used in conjunction with
psutil.cpu_percent(percpu=True) to observe the system
workload distributed across CPUs.
Q : Is it possible to get the PID of the sibling process by using
psutil
问 : 是否可以通过使用
psutil
获得同级进程的PID
Yes, it is. 是的。 How?
怎么样? It is quite enough to follow the documentation to assemble any traversing tree strategy that meets your needs and expectations upto a system-level universal process-monitor.
只需按照文档来组装满足您的需求和期望的任何遍历树策略,直到系统级通用过程监视器即可。
>>> aParentOfThisPROCESS = psutil.Process( thisProcess.parent().pid )
>>> aParentOfThisPROCESS.threads()
6
>>> aParentOfThisPROCESS.open_files()
[popenfile(path='/XXXXXXXXXXXXXXXX', fd=8, position=0, mode='r', flags=32768)]
>>> print( aParentOfThisPROCESS.children.__doc__ )
Return the children of this process as a list of Process
instances, pre-emptively checking whether PID has been reused.
If *recursive* is True return all the parent descendants.
Example (A == this process):
A ─┐
│
├─ B (child) ─┐
│ └─ X (grandchild) ─┐
│ └─ Y (great grandchild)
├─ C (child)
└─ D (child)
>>> import psutil
>>> p = psutil.Process()
>>> p.children()
B, C, D
>>> p.children(recursive=True)
B, X, Y, C, D
Note that in the example above if process X disappears
process Y won't be listed as the reference to process A
is lost.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.