I recently switched from Linux to FreeBSD. On Linux, I press 1 which show me a breakdown of CPU usage per CPU, but it is not working on FreeBSD. How do I find out the usage of individual CPU core usage using the top command on FreeBSD operating system?

You can easily get the usage of individual cpu core on FreeBSD based system using top command itself.

How to display per-cpu CPU usage statistics on FreeBSD

Type the following command:
$ top -P
Sample outputs:

Fig.01: How to find the usage of Individual cpu core usage on FreeBSD Unix system

Fig.01: How to find the usage of Individual cpu core usage on FreeBSD Unix system

From the above output it is clear that I have total 8 core in my system from cpu0 to cpu7 and you can see stats easily. Pass the -C option to turn on CPU display mode. To see each thread for a multithreaded process individually pass the -H option:
$ top -PCH
You can set the environment variable named TOP to set your own defaults. For bash/sh/ksh shell set the following in your shell startup file:
$ export TOP='-P'
OR for tcsh:
$ setenv TOP -P

Say hello to vmstat

You can use the vmstat command as follows:
$ vmstat -P
You should see per-cpu system/user/idle cpu statistics with vmstat as follows

 procs      memory      page                    disks     faults         cpu0     cpu1     cpu2     cpu3     cpu4     cpu5     cpu6     cpu7     
 r b w     avm    fre   flt  re  pi  po    fr  sr ad0 ad1   in   sy   cs us sy id us sy id us sy id us sy id us sy id us sy id us sy id us sy id
 0 2 0   3493M    21G   333   0   0   0   312  36   0   0  236 2769 1281  0  1 99  1  1 99  0  0 99  0  0 99  0  1 99  0  1 99  0  1 99  0  1 99

(Hold your mouse over above box to see full outputs)

Install htop command

Htop is a free (GPL) ncurses-based process viewer for Linux and Unix-like system including FreeBSD. Type the following command to install htop:
$ sudo pkg install htop
Sample outputs:

Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 3 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	htop: 2.0.2
	libexecinfo: 1.1_3
	lsof: 4.90.g,8

Number of packages to be installed: 3

183 KiB to be downloaded.

Proceed with this action? [y/N]: y
[webserver] Fetching htop-2.0.2.txz: 100%   63 KiB  21.5kB/s    00:03    
[webserver] Fetching libexecinfo-1.1_3.txz: 100%    8 KiB   8.6kB/s    00:01    
[webserver] Fetching lsof-4.90.g,8.txz: 100%  112 KiB  57.3kB/s    00:02    
Checking integrity... done (0 conflicting)
[webserver] [1/3] Installing libexecinfo-1.1_3...
[webserver] [1/3] Extracting libexecinfo-1.1_3: 100%
[webserver] [2/3] Installing lsof-4.90.g,8...
[webserver] [2/3] Extracting lsof-4.90.g,8: 100%
[webserver] [3/3] Installing htop-2.0.2...
[webserver] [3/3] Extracting htop-2.0.2: 100%

To view stats, type:
$ htop
Sample outputs:

Fig.02: htop command on FreeBSD

Fig.02: htop command on FreeBSD

See vmstat and top command man page for more info.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Anastasios Feb 28, 2017 @ 3:58

    Nice. I did not know that I could press ‘1’ to see cpu threads and always installed htop instead, which is also great. I think you got the export wrong, did you mean `export TOP=’top -P’`

    • K. R. Mar 1, 2017 @ 7:00

      No, that is correct. From man top:

             TOP  user-configurable defaults for options.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum