I have access to an 8-core node of a Linux cluster. When logged in to the node, I can see a list of processors using this command:

more /proc/cpuinfo

In my 8-core node, the processors are numbered from 0 to 7. Each processor is an Intel Xeon CPU (E5430 @ 2.66GHz).

Now suppose I call the program foo with some arguments args:

foo args

The program foo takes a long time to execute (hours or days, for example). Having called foo, is it possible to determine the particular processor (i.e., 0 to 7) on which foo is running? The top program shows me the process ID and similar information, but I don't see the processor number. Is such information available?

  • 1
    Unless you've done something specific, the process won't stay on the same CPU all the time. Why do you need that info?
    – Mat
    Jun 15, 2013 at 16:33
  • @Mat Thanks for your time. This is a separate question, but ultimately I would like to see if I can assign two calls to foo to two different processors. When I call foo once, it runs with %CPU very close to 100% (according to top). But when I call foo a second time, both foo processes run such that the %CPU for both processes sum to less than 100% (usually about 45% for each foo process). To me, this suggests that the two calls to foo are running on the same processor (even though there are eight processors available); I would like to verify that this is the case.
    – Andrew
    Jun 15, 2013 at 16:40
  • 1
    The term is called processor affinity
    – slm
    Jun 15, 2013 at 17:50
  • 1
    The scheduler allows things to run on multiple (different) processors....HOWEVER, your program must be constructed as a multi-threaded program to take advantage of using concurrent multiple processing on a specific program or task. Depending on who programs the application, java programs try to do this.
    – mdpc
    Jun 16, 2013 at 5:38
  • If on a constrained embedded Linux device with Busybox implementations of all your standard binaries, such as ps, top, etc, this is the only answer which seems to work! Nov 30, 2021 at 20:08

4 Answers 4


ps can give you that information if you ask for the psr column (or use the -F flag which includes it).


$ ps -F $$
me        6415  6413  0  5210  2624   2 18:52 pts/0    SN     0:00 -su


$ ps -o pid,psr,comm -p $$
 6415   0 bash

My shell was running on CPU 2 when I ran the first command, on CPU 0 when I ran the second. Beware that processes can change CPUs very, very quickly so the information you actually see is, essentially, already stale.

Some more info in this Super User question's answers:

Linux: command to know the processor number in which a process is loaded?


With the top from procps (generally the default on Linux distributions nowadays), in top, press f, navigate to P = Last User CPU (SMP) and press Space to select (you can also move the field for instance before the COMMAND field with the Right key and then move up and down). q to return to the main screen (where you'll see your process move from processor to processor unless you explicitly configured it to stay with one). You can press W to save that as the default.

Press ? for help.


The command taskset is what you're looking for:

taskset - retrieve or set a process's CPU affinity


$ taskset -p 12345
pid 12345's current affinity mask: f

A mask of f means all processors, 0x00000001 would be just processor 0.

$ taskset -c -p 24389 
pid 24389's current affinity list: 0-3

Shows the cpu's in list format. I have 4 cores on my laptop in this example.

See the man page has more details.


You can also get this info directly from /proc/[pid]/stat. It is the 39th space-delimited field (since Linux 2.2.8).

E.g. to display which CPU processor the current shell is running on (at this instance):

cat  /proc/$$/stat | cut -d' ' -f39
  • Nice! This works on embedded Linux systems which have busybox-based implementations of ps (which binary executable lacks the options specified in other answers), and on which systems taskset doesn't exist! In other words, this answer works on small embedded Linux systems where none of the other answers work! Nov 30, 2021 at 19:57
  • Do you have a reference or source for the fact this is the "39th space-delimited field"? If so, can you post it? Dec 1, 2021 at 17:16
  • 1
    I am sorry I didn't see your comments earlier, @GabrielStaples. This is a kernel-version-specific thing, and much more generic, therefore. You can check the proc manual. E.g. on a SLES distro: man 5 proc /proc/[pid]/stat (39) processor %d (since Linux 2.2.8) CPU number last executed on.
    – drgnfr
    Feb 19, 2023 at 15:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .