Blog

03/06/2019

How to display cpu wise usage using top command on FreeBSD Unix operating system



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

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
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

See vmstat and top command man page for more info.

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....
12/08/2019

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...