In Linux, in a multi-core processor, ps, top and similar tools can show the CPU logical core id running a specific process. If the process runs for a certain amount of time, it's easy to identify it in the process list.
I have instead a stand-alone program which prints "hello world" and the number of logical core detected from CPU assembly (RDPID instruction):
$ ./hello_world
hello world
1
$
It immediately ends. I would like to compare this number with the one provided by ps, top or similar. So, how to obtain the same information (the CPU logical core id) in this case? How to get the process information while this process is still executing?
topshows the CPU "running" a process or thread. If a process is using 10% of a CPU, then 90% of the time no CPU is running it.topcan show you the "Last used CPU", but with a warning that even asking is likely to alter the outcome across the whole system. Forps, the thread cumulative CPU time is found from the time between entry and exit of user mode (not continuously updated). CFS deals with variable time-slices, and longest appears to be capped at 0.006 secs, which means any separate process attempting to monitor is hopelessly lagging behind.