• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • How to find out on which core a process is running on in Linux

    There are many processes in Linux which run on single core while many will switch between different core depending upon the availability.

    With below two methods you can find if a process is continuously running on single core or if it is switching between all the available cores based on the availability.

    Method 1

    Below command can be used
    # ps -o pid,psr,time,comm -p $(pgrep -x fio)
      PID PSR     TIME COMMAND
     8453   4 00:00:00 fio
     8455   8 00:00:01 fio

    Here 'psr' column shows the last used core by the process. I have used pgrep to grep the pid of the process running by the name of 'fio'. Everytime I hit the same command I observe the processor to be changing
    # ps -o pid,psr,time,comm -p $(pgrep -x fio)
      PID PSR     TIME COMMAND
     8453   4 00:00:00 fio
     8455   8 00:00:03 fio

    # ps -o pid,psr,time,comm -p $(pgrep -x fio)
      PID PSR     TIME COMMAND
     8453   9 00:00:00 fio
     8455   8 00:00:03 fio
    So to monitor this for a while I can run it in a while loop, here I have used a sleep of 5 seconds which you can increase based on the requirement

    # while true; do echo -ne "`ps -o pid,psr,time,comm -p $(pgrep -x fio) `\t"; date;sleep 5;done
      PID PSR     TIME COMMAND
     8453   4 00:00:00 fio
     8455   9 00:00:07 fio  Fri Jul  7 18:47:13 IST 2017
      PID PSR     TIME COMMAND
     8453   4 00:00:00 fio
     8455   9 00:00:07 fio  Fri Jul  7 18:47:18 IST 2017
      PID PSR     TIME COMMAND
     8453   4 00:00:00 fio
     8455   9 00:00:07 fio  Fri Jul  7 18:47:23 IST 2017
      PID PSR     TIME COMMAND
     8453   4 00:00:00 fio
     8455   9 00:00:07 fio  Fri Jul  7 18:47:28 IST 2017
      PID PSR     TIME COMMAND
     8453   4 00:00:00 fio
     8455   9 00:00:07 fio  Fri Jul  7 18:47:33 IST 2017
      PID PSR     TIME COMMAND
     8453   5 00:00:00 fio
     8455   9 00:00:07 fio  Fri Jul  7 18:47:38 IST 2017


    Method 2

    'top' is a nice tool which can also give you this information.

    Execute 'top' from your terminal

    Press "f" to enter the field menu as below

    Press "J" as the menu shows which will display the last used CPU
    Hit "Enter"

    Now you should see a new column in your top command output


    I hope the article was useful.

    Related Articles:
    Understanding Load Average in Linux and when to be worried about it?
    How to run a process in background or bring to foreground in Linux
    10 examples to help you understand top command usage in Unix/Linux



    Deepak Prasad

    is a techie and an author who is still trying to survive in this IT generation with very little knowledge he has on Linux/Unix, VMware, SAN Storage, Automation, networking etc

    You can follow him on Facebook or Google+

    Do you also have something to share here?

    Become an author and be a part of our GoLinuxHub Team, Click here for more information
    How to find out on which core a process is running on in Linux How to find out on which core a process is running on in Linux Reviewed by Deepak Prasad on Saturday, July 08, 2017 Rating: 5

    2 comments:

    1. The commande "ps -o pid,psr,time,comm -p $(pgrep -x fio)" do not work on Oracle Linx 6.x and Ubuntu 17.04...

      ReplyDelete
      Replies
      1. I have only tested on RHEL and SuSE so may be these might not work. You can use "top" command in that case.

        Delete

    Powered by Blogger.