{"id":319,"date":"2018-08-12T09:49:38","date_gmt":"2018-08-12T06:49:38","guid":{"rendered":"http:\/\/kifarunix.com\/?p=319"},"modified":"2024-03-11T08:19:10","modified_gmt":"2024-03-11T05:19:10","slug":"viewing-system-processes-using-ps-and-top-commands","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/viewing-system-processes-using-ps-and-top-commands\/","title":{"rendered":"Viewing System Processes using ps and top commands"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1061\" height=\"596\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/ps-n-top-htop-command.png\" alt=\"Viewing System Processes using ps and top commands\" class=\"wp-image-16525\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/ps-n-top-htop-command.png?v=1683808655 1061w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/ps-n-top-htop-command-768x431.png?v=1683808655 768w\" sizes=\"(max-width: 1061px) 100vw, 1061px\" \/><\/figure>\n\n\n\n<p>This tutorial will guide you on viewing system processes using ps and top commands. When commands are run on a system, various processes associated with them are created. Among the roles of a system administrator, being able to determine what processes are running, monitor and manage them is a critical skill. There are several program tools that can be used to achieve this. In this tutorial, we are going to explore some of these tools, <strong>ps<\/strong> and <strong>top<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#view-system-processes-using-ps-and-top-commands\">ViewSystem Processes using ps and top commands<\/a><ul><li><a href=\"#view-system-processes-using-ps-command-in-linux\">View System Processes using ps command in Linux<\/a><ul><li><a href=\"#basic-ps-command-syntax\">Basic ps command Syntax<\/a><\/li><li><a href=\"#commonly-used-ps-command-options\">Commonly Used ps Command Options<\/a><\/li><li><a href=\"#the-ps-command-output-headers\">The ps command Output Headers<\/a><\/li><li><a href=\"#ps-command-process-status-codes\">ps command Process Status codes<\/a><\/li><li><a href=\"#display-wide-ps-command-output\">Display wide ps command output<\/a><\/li><li><a href=\"#managing-processes-based-on-ps-command-output\">Managing Processes based on ps command output<\/a><\/li><\/ul><\/li><li><a href=\"#check-system-processes-using-top-command-in-linux\">Check System Processes using top command in Linux<\/a><ul><li><a href=\"#most-important-parameters-displayed-by-top\">Most Important Parameters displayed by top<\/a><\/li><\/ul><\/li><li><a href=\"#options-that-can-be-used-when-launching-top-command\">Options that can be used when launching top command<\/a><ul><li><a href=\"#reference\">Reference:<\/a><\/li><\/ul><\/li><li><a href=\"#other-tutorials\">Other Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"view-system-processes-using-ps-and-top-commands\">ViewSystem Processes using ps and top commands<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"view-system-processes-using-ps-command-in-linux\">View System Processes using ps command in Linux<\/h3>\n\n\n\n<p><strong>ps<\/strong>(<strong>process status<\/strong>) command is a program that is used to display the status of the current active processes on the system. It accepts three kinds of options:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>UNIX options<\/strong>, These are options which can be grouped together and must be preceded by a dash (-).<\/li>\n\n\n\n<li><strong>BSD options<\/strong>, These options may be grouped and must not be used with a dash.<\/li>\n\n\n\n<li><strong>GNU long options<\/strong>, These are multi-character options preceded by two dashes (&#8211;).<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"basic-ps-command-syntax\">Basic ps command Syntax<\/h4>\n\n\n\n<p>The basic ps syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps &#91;options]<\/code><\/pre>\n\n\n\n<p>NB. If ps is used without options, it will display only current processes run from its terminal.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>PID TTY          TIME CMD\n5727 pts\/0    00:00:05 zsh\n31393 pts\/0    00:00:00 ps<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"commonly-used-ps-command-options\">Commonly Used ps Command Options<\/h4>\n\n\n\n<p>Some of the commonly used options include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>-A<\/code><\/strong>, <strong><code>-e<\/code><\/strong> \u2013 Displays all the processes running on the system.<\/li>\n\n\n\n<li><code><strong>-u<\/strong> <em>user<\/em><\/code>, <code><strong>-U<\/strong> <em>user<\/em><\/code>, <strong><code>--User<\/code><\/strong> \u2013 Displays the processes owned by the specified user.<\/li>\n\n\n\n<li><strong><code>--pid<\/code><\/strong>, <strong>-p<\/strong> \u2013 Select processes by process ID.<\/li>\n\n\n\n<li><strong><code>--ppid<\/code><\/strong> \u2013 Select processes by parent process ID.<\/li>\n\n\n\n<li><strong><code>-F<\/code><\/strong> \u2013 extra full format listing.<\/li>\n\n\n\n<li><strong><code>-w<\/code><\/strong> \u2013 displays wide output. When using this option, its good to direct the output to some file.<\/li>\n\n\n\n<li><strong><code>-j<\/code><\/strong> \u2013 shows session ID and process group ID.<\/li>\n\n\n\n<li><strong><code>-l<\/code><\/strong> \u2013 long listing.<\/li>\n\n\n\n<li><strong><code>--help<\/code><\/strong> \u2013 display help information.<\/li>\n\n\n\n<li><strong><code>--forest<\/code>, -f, -H<\/strong> \u2013 show process hierarchy.<\/li>\n\n\n\n<li><strong><code>--sort<\/code><\/strong> \u2013 specify sort order.<\/li>\n\n\n\n<li><strong><code>--tty<\/code><\/strong> \u2013 select processes by attached terminal.<\/li>\n\n\n\n<li><strong><code>--no-heading<\/code>, <code>--no-headers<\/code><\/strong> \u2013 suppress headers.<\/li>\n\n\n\n<li><strong><code>--version<\/code><\/strong> \u2013 displays version information.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"the-ps-command-output-headers\">The ps command Output Headers<\/h4>\n\n\n\n<p>By default, ps selects all processes with the same effective user ID (euid=EUID) as the current user and associated with the same terminal as the user who run them.<\/p>\n\n\n\n<p>It displays the process ID (pid=PID), the terminal associated with the process (tname=TTY), the cumulated CPU time in [DD-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD).<\/p>\n\n\n\n<p>Using BSD-style options will add process state (stat=STAT) to the default display and show the command args (args=COMMAND) instead of the executable name, change the process selection to include processes on other terminals (TTYs) that are owned by logged in user.<\/p>\n\n\n\n<p>The ps header has different columns each with different meaning as discussed below.<\/p>\n\n\n\n<p>A sample output of the <strong>ps<\/strong> command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps aux<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nUSER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND\nroot         1  0.0  0.1 200828  5588 ?        Ss   Jan30   0:02 \/sbin\/init nosplash\nroot         3  0.0  0.0      0     0 ?        S    Jan30   0:06 [ksoftirqd\/0]\nroot         5  0.0  0.0      0     0 ?        S&lt;   Jan30   0:00 [kworker\/0:0H]\nroot       331  0.0  0.0      0     0 ?        D    Jan30   0:17 [rtsx_usb_ms_1]\nroot       448  0.0  0.4 787916 16220 ?        Ssl  Jan30   0:00 \/usr\/bin\/libvirtd\nroot       331  0.0  0.0      0     0 ?        D    Jan30   0:17 [rtsx_usb_ms_1]\nkoromic+   516  0.0  0.0  13692  3192 tty1     Ss+  Jan30   0:00 \/bin\/sh \/usr\/bin\/startx\nkoromic+ 14919  0.0  0.0  40952  3520 pts\/0    R+   09:21   0:00 ps aux\n\n<\/code><\/pre>\n\n\n\n<p>Demystifying the ps command headers;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>USER<\/strong> \u2013 Defines the name of the user owns the process\/runs the program.<\/li>\n\n\n\n<li><strong>PID<\/strong> \u2013 This is the process ID of the process.<\/li>\n\n\n\n<li><strong>%CPU<\/strong> \u2013 Specifies the percentage of the CPU the process is consuming.<\/li>\n\n\n\n<li><strong>%MEM<\/strong> \u2013 This s the percentage of memory the program is using.<\/li>\n\n\n\n<li><strong>VSZ<\/strong> \u2013 Specifies the amount of virtual memory, in KiB, being used by a process.<\/li>\n\n\n\n<li><strong>RSS<\/strong> \u2013 Resident Set Size, specifies the amount of physical memory, in KiB, being used by the process.<\/li>\n\n\n\n<li><strong>TTY<\/strong> \u2013 TeleType code, specifies the type of terminal from which the process was launched. This can be tty1 (normal terminal on your server) or pts\/0 (pseudo-terminal slave e.g xterm).<\/li>\n\n\n\n<li><strong>STAT<\/strong> \u2013 Defines the status codes of different processes. Some of the codes are explained below.<\/li>\n\n\n\n<li><strong>START<\/strong> \u2013 States the time when the process was started.<\/li>\n\n\n\n<li><strong>TIME<\/strong> \u2013 Displays the total CPU time consumed by the process.<\/li>\n\n\n\n<li><strong>COMMAND<\/strong> \u2013 States the command used to launch the process including arguments used if any.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"ps-command-process-status-codes\">ps command Process Status codes<\/h4>\n\n\n\n<p>Some of the <strong>Process Status codes<\/strong> include;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>Sleeping (S)<\/code><\/strong>: This is an <strong>Interruptible sleep<\/strong>. The process is waiting for an event to complete or for a system resource to become available.<\/li>\n\n\n\n<li><strong><code>s<\/code><\/strong> Indicates that the process is a <strong>session leader<\/strong>. A session leader is a process that creates a new session and group ID for a group of related processes. When a session leader terminates, its process group is sent a SIGHUP signal, which typically causes the processes in that group to terminate as well<\/li>\n\n\n\n<li><strong><code>R (Running or runnable)<\/code><\/strong> Indicates that the process is actively running or is in the queue waiting to be it is waiting to be executed by the CPU.<\/li>\n\n\n\n<li><strong><code>uninteruptible sleep (D)<\/code><\/strong> The process is in a sleep state that cannot be stopped especially if its waiting for I\/O. This usually happens when a process is waiting for a system resource that is not currently available.<\/li>\n\n\n\n<li><strong><code>l<\/code><\/strong> shows that the process is multi-threaded and has threads that are executing concurrently.<\/li>\n\n\n\n<li><strong><code>+<\/code><\/strong> Indicates that the process is in the foreground process group.<\/li>\n\n\n\n<li><strong><code>-<\/code><\/strong> Process is in the background process group of its control terminal.<\/li>\n\n\n\n<li><strong><code>Zombie\/Defunct (Z)<\/code><\/strong> Indicates a process that has been stopped but could not be removed by a parent process.<\/li>\n\n\n\n<li><strong><code>&lt;<\/code><\/strong> Indicates a process with high-priority.<\/li>\n\n\n\n<li><strong><code>N<\/code><\/strong> Indicates a process with scheduling low-priority.<\/li>\n\n\n\n<li><strong><code>L<\/code><\/strong> Indicates that the process has pages locked into memory.<\/li>\n\n\n\n<li><code><strong>T<\/strong><\/code> &#8211; Stopped. This means that the process has been stopped by a signal or a user action and it can be resumed later.<\/li>\n\n\n\n<li><code><strong>X<\/strong><\/code> &#8211; Dead. This indicates that the process has been terminated or crashed.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"display-wide-ps-command-output\">Display wide ps command output<\/h4>\n\n\n\n<p>The output of a ps command is usually truncated so as to fit the display screen.<\/p>\n\n\n\n<p>To display a wide output, option <strong>&#8211; w<\/strong> can be passed as stated in options above. <\/p>\n\n\n\n<p>The <code>-w<\/code> option tells <code>ps<\/code> to use 132 columns to display output instead of the default 80 columns.<\/p>\n\n\n\n<p>Here&#8217;s the command to display the <code>ps<\/code> output in wide format:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps -efw<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"managing-processes-based-on-ps-command-output\">Managing Processes based on ps command output<\/h4>\n\n\n\n<p>From the ps output, one can be able to manage processes that are consuming unrealistic CPU time or memory based on their PID (Process ID) which is usually shown in the second column of the <code>ps<\/code> output. Some common management commands you can use:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>kill<\/code>: Sends a signal to a process to request it to terminate. For example, <code>kill 1234<\/code> will send the default <code>TERM<\/code> signal to process ID 1234 to request it to terminate.<\/li>\n\n\n\n<li><code>killall<\/code>: Sends a signal to all processes with a certain name. For example, <code>killall chrome<\/code> will send the default <code>TERM<\/code> signal to all processes named <code>chrome<\/code> to request them to terminate.<\/li>\n\n\n\n<li><code>pkill<\/code>: Sends a signal to a process based on its name. For example, <code>pkill firefox<\/code> will send the default <code>TERM<\/code> signal to all processes named <code>firefox<\/code> to request them to terminate.<\/li>\n\n\n\n<li><code>renice<\/code>: Changes the priority of a running process. You can use <code>renice<\/code> command followed by the priority level and the PID of the process to change its priority. For example, <code>renice +10 1234<\/code> will increase the priority of process ID 1234 by 10.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"check-system-processes-using-top-command-in-linux\">Check System Processes using top command in Linux<\/h3>\n\n\n\n<p>The <strong>top<\/strong> utility is a dynamic variant of <strong>ps<\/strong> provides a dynamic real-time overview of all the processes running on the system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.<\/p>\n\n\n\n<p>By default, top sorts its entries by percentage CPU usage.<\/p>\n\n\n\n<p>Sample output of the top command is shown below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>top<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\ntop - 12:14:36 up 14 min,  1 user,  load average: 0.28, 0.34, 0.28\nTasks: 122 total,   1 running, 121 sleeping,   0 stopped,   0 zombie\n%Cpu(s):  2.2 us,  0.8 sy,  0.0 ni, 96.8 id,  0.0 wa,  0.0 hi,  0.2 si,  0.0 st\nMiB Mem :   1975.8 total,     62.7 free,   1468.9 used,    444.2 buff\/cache\nMiB Swap:   1870.0 total,   1781.5 free,     88.5 used.    347.6 avail Mem \n\n    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                                              \n   1016 elastic+  20   0 3270644 902772  23716 S   5.0  44.6   2:00.14 java                                                                                                 \n    679 kibana    20   0   11.1g 344300  27532 S   2.3  17.0   0:48.46 node                                                                                                 \n    675 elastic+  20   0 2602252  25528  20172 S   0.3   1.3   0:03.94 java                                                                                                 \n   1639 root      20   0       0      0      0 I   0.3   0.0   0:00.17 kworker\/1:2-events                                                                                   \n   2363 kifarun+  20   0   10472   4020   3332 R   0.3   0.2   0:00.04 top                                                                                                  \n      1 root      20   0  167768  12828   7960 S   0.0   0.6   0:03.13 systemd                                                                                              \n      2 root      20   0       0      0      0 S   0.0   0.0   0:00.00 kthreadd                                                                                             \n      3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp                                                                                               \n      4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_par_gp                                                                                           \n      5 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 slub_flushwq                                                                                         \n      6 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 netns                                                                                                \n      8 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 kworker\/0:0H-events_highpri                                                                          \n      9 root      20   0       0      0      0 I   0.0   0.0   0:00.73 kworker\/u4:0-ext4-rsv-conversion                                                                     \n     10 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 mm_percpu_wq                                                                                         \n     11 root      20   0       0      0      0 S   0.0   0.0   0:00.00 rcu_tasks_rude_                                                                                      \n     12 root      20   0       0      0      0 S   0.0   0.0   0:00.00 rcu_tasks_trace                                                                                      \n     13 root      20   0       0      0      0 S   0.0   0.0   0:00.36 ksoftirqd\/0                                                                                          \n     14 root      20   0       0      0      0 I   0.0   0.0   0:00.38 rcu_sched                                                                                            \n     15 root      rt   0       0      0      0 S   0.0   0.0   0:00.00 migration\/0                                                                                          \n     16 root     -51   0       0      0      0 S   0.0   0.0   0:00.00 idle_inject\/0                                                                                        \n     17 root      20   0       0      0      0 I   0.0   0.0   0:00.40 kworker\/0:1-inode_switch_wbs                                                                         \n     18 root      20   0       0      0      0 S   0.0   0.0   0:00.00 cpuhp\/0                                                                                              \n     19 root      20   0       0      0      0 S   0.0   0.0   0:00.00 cpuhp\/1                                                                                              \n     20 root     -51   0       0      0      0 S   0.0   0.0   0:00.00 idle_inject\/1                                                                                        \n     21 root      rt   0       0      0      0 S   0.0   0.0   0:00.16 migration\/1                                                                                          \n     22 root      20   0       0      0      0 S   0.0   0.0   0:00.19 ksoftirqd\/1                                                                                          \n     23 root      20   0       0      0      0 I   0.0   0.0   0:00.02 kworker\/1:0-cgroup_destroy\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"most-important-parameters-displayed-by-top\">Most Important Parameters displayed by top<\/h4>\n\n\n\n<p>Some of the most important parameters displayed by the top utility include; load average,system Tasks, system uptime, CPU usage, Memory usage and Swap memory usage.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>load average<\/strong> indicates the average number of processes waiting to be served at any given time. It shows system load average over the last <strong>1, 5<\/strong> and <strong>15<\/strong> minutes. It is related to the number of CPU core in a system and therefore it should not be higher than the number of CPU cores. In case the load average is way higher than the number of CPU cores, inspect the system to find out the cause and ensure that the system is not overloaded.<\/li>\n\n\n\n<li><strong>System uptime<\/strong> \u2014 Top command can also show the length of time the system has been running. The same result can be obtained using the <strong>uptime<\/strong> utility which also shows the system load average.<\/li>\n\n\n\n<li><strong>Tasks<\/strong> \u2014 Displays system summary information of all the tasks currently being managed by the Linux kernel.<\/li>\n\n\n\n<li><strong>CPU usage (%Cpu(s):)<\/strong> \u2014 This is another performance indicator which summarizes performance of all the CPU cores in the system. Some of the performance indicators are described below:\n<ul class=\"wp-block-list\">\n<li><strong>us<\/strong>: Specifies the percentage of CPU time spend on handling user space processes.<\/li>\n\n\n\n<li><strong>sy<\/strong>: Indicates the percentage of CPU time spend in kernel space for handling system calls.<\/li>\n\n\n\n<li><strong>ni<\/strong>: Amount of CPU time spend while handling processes whose priority (nice value) has been adjusted.<\/li>\n\n\n\n<li><strong>id<\/strong>: CPU time spend in idle loop, that is when no program is using the processor.<\/li>\n\n\n\n<li><strong>wa<\/strong>: Amount of CPU time spend while waiting for non-interruptible I\/O processes such as disks requests to complete.<\/li>\n\n\n\n<li><strong>hi<\/strong>: This is the time the processor spends on handling hardware interrupts.<\/li>\n\n\n\n<li><strong>si<\/strong>: This is the time the processor spends on handling software interrupts.<\/li>\n\n\n\n<li><strong>st<\/strong>: In virtualization environment, this displays amount of the CPU time stolen by the virtual machines from the hypervisor.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Memory usage (KiB Mem:)<\/strong> \u2014 This gives an overview of RAM usage. Some of the RAM usage parameters include:\n<ul class=\"wp-block-list\">\n<li><strong>total<\/strong>: Total amount of RAM in KiB with 1 KiB being equal to 1024 bytes.<\/li>\n\n\n\n<li><strong>free<\/strong>: The amount of RAM that is not being used.<\/li>\n\n\n\n<li><strong>used<\/strong>: Total amount of RAM that is being used by various processes.<\/li>\n\n\n\n<li><strong>buffers<\/strong>: Amount of RAM memory used hold data temporarily while it is being moved from one place to another.<\/li>\n\n\n\n<li><strong>cache<\/strong>: Amount of memory being used to temporarily store frequently accessed data for quick access, thus improving system performance.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Swap space Usage<\/strong> \u2014 This is the memory space, located in the hard-drive, that can be used in case there is a shortage in RAM memory. If the system needs more memory resources and the RAM is full, <strong>inactive pages<\/strong> (caches that have not been used recently) in memory are moved to the swap space to free up space.<\/li>\n<\/ul>\n\n\n\n<p>Another important program to check current memory usage is <strong>free<\/strong> utility.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"options-that-can-be-used-when-launching-top-command\">Options that can be used when launching top command<\/h3>\n\n\n\n<p>Options that can be used when launching the top command include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>-d<\/strong> <em>delay<\/em>: specifies delay between updates. Default rate is usually 5 seconds.<\/li>\n\n\n\n<li><strong>-p<\/strong> <em>pid<\/em>: used to monitor specific processes based on their PIDs. PIDs can be obtained using <strong>ps<\/strong> utility.<\/li>\n\n\n\n<li><strong>-n<\/strong> <em>iter<\/em>: tells top to display certain number of updates (iter) and quit.<\/li>\n\n\n\n<li><strong>-b<\/strong>: This causes top to operate in batch mode,i.e direct the output to some file instead of displaying them on the screen.<\/li>\n<\/ul>\n\n\n\n<p>For example, to log a single update of the system performance to a top.txt file in the current directory;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>top -b -n 1 &gt; top.txt<\/code><\/pre>\n\n\n\n<p>There are other interactive commands that can be used when top is running (You can press these on the keyboard when top is running);<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>M<\/strong> or <strong>&gt;<\/strong> key \u2013 sorts the display by memory usage.<\/li>\n\n\n\n<li><strong>P<\/strong> or <strong>&lt;<\/strong> key \u2013 sorts the display by the CPU usage (default).<\/li>\n\n\n\n<li><strong>s<\/strong> \u2013 alters the display update rate.<\/li>\n\n\n\n<li><strong>q<\/strong> \u2013 quits the top utility.<\/li>\n\n\n\n<li><strong>r<\/strong> \u2013 alters the priority of a process.<\/li>\n\n\n\n<li><strong>k<\/strong> \u2013 kills a process,you will be prompted for a PID value.<\/li>\n\n\n\n<li><strong>?<\/strong>, <strong>h<\/strong> \u2013 displays help.<\/li>\n\n\n\n<li><strong>u<\/strong> \u2013 sorts the display by the user, it prompts for username.<\/li>\n<\/ul>\n\n\n\n<p><strong>htop<\/strong> is an alternative process-viewer for <strong>top<\/strong> but unlike top, it provides a full listing of processes rather than top-resource consuming processes allowing a user to scroll vertically or horizontally to view all processes and full commands. Besides, one does\u2019t necessarily have to type in the PID nor the priority renice value to kill a process or adjust a priority of a process.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"reference\">Reference:<\/h4>\n\n\n\n<p><a href=\"https:\/\/man7.org\/linux\/man-pages\/man1\/ps.1.html\" target=\"_blank\" rel=\"noreferrer noopener\">man ps<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/man7.org\/linux\/man-pages\/man1\/top.1.html\" target=\"_blank\" rel=\"noreferrer noopener\">man top<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"other-tutorials\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/lock-linux-user-account-after-multiple-failed-login-attempts\/\" target=\"_blank\" rel=\"noreferrer noopener\">Lock Linux User Account after Multiple Failed Login Attempts<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-get-byte-count-in-a-file-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to get byte count in a file in Linux<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will guide you on viewing system processes using ps and top commands. When commands are run on a system, various processes associated with<\/p>\n","protected":false},"author":1,"featured_media":16525,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[49,121],"tags":[52,50,6646,51,6648,6647,6645,6644],"class_list":["post-319","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-cheatsheets","category-howtos","tag-htop","tag-ps","tag-ps-wide-output","tag-top","tag-top-sort-by-cpu","tag-top-sort-by-memory","tag-view-linux-processes-using-ps-command","tag-view-system-processes-usng-top-command","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/319"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=319"}],"version-history":[{"count":3,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/319\/revisions"}],"predecessor-version":[{"id":20965,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/319\/revisions\/20965"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/16525"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}