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
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
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
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:
See vmstat and top command man page for more info.