Which process is running on which cpu core?

23 Views Asked by At

There are 4 cpu cores in my pc.

import os
os.cpu_count()
4

I create 4 processes with Process module:

vim mp.py
import os,time
from multiprocessing import Process

def run_proc(name):
    print('child process %s (%s) running ...' %(name,os.getpid()))
    print('process will start'+name)
    time.sleep(5)
    print('end  '+name)

if __name__ == '__main__':
    print('parent process %s.' %os.getppid())
    for i in range(5):
        p = Process(target=run_proc,args=(str(i),))
        p.start()
    print("parent process end")

Run with python3 mp.py:

there are 4 cpus in the pc 
parent process 6011.
child process 0 (8755) running ...
process will start0
parent process end
child process 1 (8756) running ...
process will start1
child process 2 (8757) running ...
process will start2
child process 3 (8758) running ...
process will start3
end  0
end  1
end  2
end  3

How can know which process is running on which cup core?For example,the 8755 process is running on which cpu core?Does operating system call the 4 cpus by their names or addresses?

0

There are 0 best solutions below