"I guess the last one get a value of 2
for p.cpu_num()
indicates that this job is on parallel computing"
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 )
>>> 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
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.