using top and htop

top and htop provide real-time summary information about the set of processes and threads currently running on the system and their resource usage. Below is a brief summary of using and configuring top to show different data, particularly in the context of using it for multi-threaded processes. See the man page for top for more information (it is super configurable).

getting system specs and state via /proc and /sys
For running threaded programs, you often want to see state for individual threads as they run. You can start by getting the specs from the particular linux machine via /proc and /sys.
top (and htop) for real-time system usage info
top and htop are Unix utilities that list information about processes and threads and how they are using resources like memory and CPU.

If you run top with no command line options, then it displays per-process statistics. If you run top with -H, top will display statistics for individual threads (if you run the synch program for a large number of threads, you can see them show up in top):

top -H
htop has a slightly different display of these data, and includes per-cpu summary data. You can also sort the data on different fields using the function key (F6). Try running htop and try sorting the output on different fields:
htop

Selecting what top displays

Top can display a lot of different information about running processes and threads. Start top again:
top -H
While top is running, you can change what information it displays by typing f, and you should see something like this:
Fields Management for window 1:Def, whose current sort field is %CPU
Navigate with Up/Dn, Right selects for move then <Enter> or Left commits,
'd' or <Space> toggles display, 's' sets sort.  Use 'q' or <Esc> to end!

* PID     = Process Id          
* USER    = Effective User Name 
* PR      = Priority            
* NI      = Nice Value          
* VIRT    = Virtual Image (KiB) 
* RES     = Resident Size (KiB) 
* SHR     = Shared Memory (KiB) 
* S       = Process Status      
* %CPU    = CPU Usage           
* %MEM    = Memory Usage (RES)  
* TIME+   = CPU Time, hundredths
* COMMAND = Command Name/Line   
  PPID    = Parent Process pid  
  UID     = Effective User Id   
  RUID    = Real User Id        
...
  P       = Last Used Cpu (SMP) 
...
  nsUTS   = UTS namespace Inode 

The starred items are the current values. To select different items or units for top to display, use arrow keys then type d or space. For example, to get top to print information about the last CPU each process or thread ran on, select the P option and hit return and the top window will now have a new column P that list this information.
 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+   P COMMAND          
 8249 newhall   20   0  153m 4488  472 R   47  0.0   0:02.78 6 gol              
 8250 newhall   20   0  153m 4488  472 R   47  0.0   0:02.76 2 gol              
 8236 newhall   20   0  153m 4488  472 R   46  0.0   0:02.77 6 gol              
 8237 newhall   20   0  153m 4488  472 S   46  0.0   0:02.77 4 gol              
 8243 newhall   20   0  153m 4488  472 R   46  0.0   0:02.76 1 gol              
 8239 newhall   20   0  153m 4488  472 S   46  0.0   0:02.76 7 gol              
 8240 newhall   20   0  153m 4488  472 R   46  0.0   0:02.76 5 gol              
 8244 newhall   20   0  153m 4488  472 R   46  0.0   0:02.72 2 gol              
 8251 newhall   20   0  153m 4488  472 R   46  0.0   0:02.78 4 gol              
Type q to exit top.