Monitoring FreeBSD Server Activity With the ps Command

For someone who works in the field of network and system administration, it is very important to master the ps utility command. Because with its help, users can find out a lot of useful information about processes running on an operating system such as FreeBSD.

The ps command is used to view the processes currently running on the operating system. This command really helps a system administrator to determine which processes are running and doing what in the operating system, how much memory is used, how much CPU space is occupied, user ID, command name, etc.


1. What is ps Command

The ps command shows detailed selection of currently running processes. If a network administrator wants repeated selection updates and displayed information, then he can use the ps command for the job.

The ps command is one of the most widely used utilities in FreeBSD. The ps utility provides a snapshot of ongoing processes and their status. This is helpful in monitoring running processes, identifying process ID (PID), terminal type (TTY), CPU time usage, command name, user ID, and other information. This article provides a comprehensive overview of various real-life use cases of the ps command.

The ps command supports three different syntax styles. The following are the ps command versions of the three options:
  1. UNIX options can be combined and must be followed by a hyphen.
  2. The GNU long option is followed by two hyphens.
  3. BSD options can be combined and should not be used with hyphens.
Different types of options can be mixed freely, but clashes may occur. There are several synonymous, functionally identical options, due to multiple ps implementations and standards that are compatible with the ps command.


2. Implementation of the ps Command

The "ps" command in FreeBSD stands for "process status", an abbreviation of the full name. You can use it to learn more about what is happening in your system's background processes. Depending on the input parameters, this command may produce different results. However, this tutorial will use an illustrative example to teach you how to use the "ps" command in FreeBSD.

The "ps" command has certain parameters that can be found in the "help" documentation. This command, however, can be executed independently without errors.

The following is the Header line of the ps command:

  1. %CPU: Shows how many processes are using the CPU.
  2. %MEM: Shows how many processes are using memory.
  3. ADDR: Displays the memory address of a process.
  4. CP or C: Displays scheduling and CPU usage information.
  5. COMMAND*: Displays the process name, including arguments if available.
  6. NI: Showing good grades.
  7. F: Displays flag options.
  8. PID: Displays the Process ID number.
  9. PPID: Displays the parent process number of the process.
  10. PRI: Displays the process priority.
  11. RSS: Abbreviation for Resident set size.
  12. STAT or S: Displays the status code of the ongoing process.
  13. STIME or START: Displays the start time of the process.
  14. TIME: Displays the amount of CPU time used by a process.
  15. VSZ: Displays the virtual memory used.
  16. TTY or TT: Displays the terminal corresponding to the process.
  17. USER or UID: Displays the user name and owner of the current process.
  18. WCHAN: Indicates the memory address for which processing is pending.

3. Example of Using the ps Command

a. Shows all processes

root@ns1:~ # ps
PID TT STAT TIME COMMAND
816 v0- I 0:00.20 /usr/local/bin/GoBlog
2085 v0- S 0:00.40 tor --DataDirectory /tmp/data-dir-1382725963 --Co
2134 v0 Is+ 0:00.00 /usr/libexec/getty Pc ttyv0
2135 v1 Is+ 0:00.01 /usr/libexec/getty Pc ttyv1
2136 v2 Is+ 0:00.00 /usr/libexec/getty Pc ttyv2
2137 v3 Is+ 0:00.00 /usr/libexec/getty Pc ttyv3
2138 v4 Is+ 0:00.00 /usr/libexec/getty Pc ttyv4
2139 v5 Is+ 0:00.00 /usr/libexec/getty Pc ttyv5
2140 v6 Is+ 0:00.00 /usr/libexec/getty Pc ttyv6
2141 v7 Is+ 0:00.00 /usr/libexec/getty Pc ttyv7
2159 0 Ss 0:00.02 -csh (csh)
2162 0 R+ 0:00.00 ps


b. Displays currently running processes

root@ns1:~ # ps -e
PID TT STAT TIME COMMAND
816 v0- I 0:00.21 LANG=C.UTF-8 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/
2085 v0- S 0:00.40 LANG=C.UTF-8 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/
2134 v0 Is+ 0:00.00 TERM=xterm /usr/libexec/getty Pc ttyv0
2135 v1 Is+ 0:00.01 TERM=xterm /usr/libexec/getty Pc ttyv1
2136 v2 Is+ 0:00.00 TERM=xterm /usr/libexec/getty Pc ttyv2
2137 v3 Is+ 0:00.00 TERM=xterm /usr/libexec/getty Pc ttyv3
2138 v4 Is+ 0:00.00 TERM=xterm /usr/libexec/getty Pc ttyv4
2139 v5 Is+ 0:00.00 TERM=xterm /usr/libexec/getty Pc ttyv5
2140 v6 Is+ 0:00.00 TERM=xterm /usr/libexec/getty Pc ttyv6
2141 v7 Is+ 0:00.00 TERM=xterm /usr/libexec/getty Pc ttyv7
2159 0 Ss 0:00.02 USER=root LOGNAME=root HOME=/root PATH=/sbin:/bin
2163 0 R+ 0:00.00 USER=root LOGNAME=root HOME=/root PATH=/sbin:/bin


c. View processes that do not have a controlling terminal

root@ns1:~ # ps -ax
PID TT STAT TIME COMMAND
0 - DLs 0:01.26 [kernel]
1 - ILs 0:00.04 /sbin/init
2 - DL 0:00.00 [KTLS]
3 - DL 0:00.00 [crypto]
4 - DL 0:00.05 [cam]
5 - DL 0:00.14 [zfskern]
6 - DL 0:00.01 [rand_harvestq]
7 - DL 0:00.05 [pagedaemon]
8 - DL 0:00.00 [vmdaemon]
9 - DL 0:00.00 [bufdaemon]
10 - DL 0:00.00 [audit]
11 - RNL 22:06.59 [idle]
12 - WL 0:00.76 [intr]
13 - DL 0:00.00 [geom]
14 - DL 0:00.00 [sequencer 00]
15 - DL 0:00.01 [usb]
16 - DL 0:00.01 [acpi_thermal]
17 - DL 0:00.00 [vnlru]
18 - DL 0:00.00 [syncer]
536 - Is 0:00.00 /sbin/devd
732 - Is 0:00.01 /usr/sbin/syslogd -s
814 - Is 0:00.00 sshd: /usr/local/sbin/sshd [listener] 0 of 10-10
832 - Ss 0:00.03 /usr/sbin/ntpd -p /var/db/ntp/ntpd.pid -c /etc/n
866 - Ss 0:00.00 /usr/sbin/cron -s
878 - Is 0:00.05 /bin/sh /usr/local/bin/mysqld_safe --defaults-ex
2082 - I 0:03.43 /usr/local/libexec/mysqld --defaults-extra-file=
2103 - Ss 0:00.11 redis-server: /usr/local/bin/redis-server 127.0.
2122 - Ss 0:00.02 /usr/local/sbin/httpd
2142 - I 0:00.00 /usr/local/sbin/httpd
2143 - S 0:00.00 /usr/local/sbin/httpd
2144 - I 0:00.00 /usr/local/sbin/httpd
2145 - I 0:00.00 /usr/local/sbin/httpd
2146 - I 0:00.00 /usr/local/sbin/httpd
2156 - Ss 0:00.03 sshd: root@pts/0 (sshd)
816 v0- I 0:00.25 /usr/local/bin/GoBlog
2134 v0 Is+ 0:00.00 /usr/libexec/getty Pc ttyv0
2135 v1 Is+ 0:00.01 /usr/libexec/getty Pc ttyv1
2136 v2 Is+ 0:00.00 /usr/libexec/getty Pc ttyv2
2137 v3 Is+ 0:00.00 /usr/libexec/getty Pc ttyv3
2138 v4 Is+ 0:00.00 /usr/libexec/getty Pc ttyv4
2139 v5 Is+ 0:00.00 /usr/libexec/getty Pc ttyv5
2140 v6 Is+ 0:00.00 /usr/libexec/getty Pc ttyv6
2141 v7 Is+ 0:00.00 /usr/libexec/getty Pc ttyv7
2159 0 Ss 0:00.03 -csh (csh)
2175 0 R+ 0:00.00 ps -ax


d. Displays all detailed info of running processes

root@ns1:~ # ps auwwx


e. Shows the most active processes

root@ns1:~ # ps -aux | head -5
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 11 200.0 0.0 0 32 - RNL 17:21 35:09.10 [idle]
root 0 0.0 0.1 0 1104 - DLs 17:21 0:01.31 [kernel]
root 1 0.0 0.1 11768 1164 - ILs 17:21 0:00.04 /sbin/init
root 2 0.0 0.0 0 32 - DL 17:21 0:00.00 [KTLS]


f. Displays root user processes

root@ns1:~ # ps -aux | grep root
root 11 200.0 0.0 0 32 - RNL 17:21 39:52.35 [idle]
root 0 0.0 0.1 0 1104 - DLs 17:21 0:01.33 [kernel]
root 1 0.0 0.1 11768 1164 - ILs 17:21 0:00.04 /sbin/init
root 2 0.0 0.0 0 32 - DL 17:21 0:00.00 [KTLS]
root 3 0.0 0.0 0 48 - DL 17:21 0:00.00 [crypto]
root 4 0.0 0.0 0 32 - DL 17:21 0:00.06 [cam]
root 5 0.0 0.0 0 704 - DL 17:21 0:00.15 [zfskern]
root 6 0.0 0.0 0 16 - DL 17:21 0:00.02 [rand_harvestq]
root 7 0.0 0.0 0 48 - DL 17:21 0:00.10 [pagedaemon]
root 8 0.0 0.0 0 16 - DL 17:21 0:00.00 [vmdaemon]
root 9 0.0 0.0 0 32 - DL 17:21 0:00.00 [bufdaemon]
root 10 0.0 0.0 0 16 - DL 17:21 0:00.00 [audit]
root 12 0.0 0.0 0 352 - WL 17:21 0:01.19 [intr]
root 13 0.0 0.0 0 48 - DL 17:21 0:00.00 [geom]
root 14 0.0 0.0 0 16 - DL 17:21 0:00.00 [sequencer 00]
root 15 0.0 0.0 0 160 - DL 17:21 0:00.01 [usb]
root 16 0.0 0.0 0 16 - DL 17:21 0:00.01 [acpi_thermal]
root 17 0.0 0.0 0 16 - DL 17:21 0:00.00 [vnlru]
root 18 0.0 0.0 0 16 - DL 17:21 0:00.00 [syncer]
root 536 0.0 0.1 11568 1572 - Is 17:21 0:00.00 /sbin/devd
root 732 0.0 0.2 12868 2764 - Ss 17:21 0:00.01 /usr/sbin/syslogd -s
root 814 0.0 0.4 21072 7584 - Is 17:21 0:00.00 sshd: /usr/local/sbin/sshd [listener] 0 of 10-100 startups (sshd)
root 866 0.0 0.1 12908 2544 - Ss 17:21 0:00.00 /usr/sbin/cron -s
root 2122 0.0 0.9 37592 15768 - Ss 17:21 0:00.03 /usr/local/sbin/httpd
root 2156 0.0 0.5 21440 8792 - Ss 17:23 0:00.04 sshd: root@pts/0 (sshd)
root 816 0.0 2.5 803336 44164 v0- I 17:21 0:00.30 /usr/local/bin/GoBlog
root 2134 0.0 0.1 12836 2348 v0 Is+ 17:21 0:00.00 /usr/libexec/getty Pc ttyv0
root 2135 0.0 0.1 12836 2356 v1 Is+ 17:21 0:00.01 /usr/libexec/getty Pc ttyv1
root 2136 0.0 0.1 12836 2348 v2 Is+ 17:21 0:00.00 /usr/libexec/getty Pc ttyv2
root 2137 0.0 0.1 12836 2348 v3 Is+ 17:21 0:00.00 /usr/libexec/getty Pc ttyv3
root 2138 0.0 0.1 12836 2344 v4 Is+ 17:21 0:00.00 /usr/libexec/getty Pc ttyv4
root 2139 0.0 0.1 12836 2340 v5 Is+ 17:21 0:00.00 /usr/libexec/getty Pc ttyv5
root 2140 0.0 0.1 12836 2348 v6 Is+ 17:21 0:00.00 /usr/libexec/getty Pc ttyv6
root 2141 0.0 0.1 12836 2352 v7 Is+ 17:21 0:00.00 /usr/libexec/getty Pc ttyv7
root 2159 0.0 0.3 16496 4616 0 Ss 17:23 0:00.04 -csh (csh)
root 2204 0.0 0.2 13444 3120 0 R+ 17:41 0:00.00 ps -aux
root 2205 0.0 0.1 12812 2420 0 S+ 17:41 0:00.00 grep root


g. Displays cron processes

root@ns1:~ # ps aux | grep cron
root 866 0.0 0.1 12908 2544 - Is 17:21 0:00.00 /usr/sbin/cron -s
root 2211 0.0 0.1 12812 2428 0 S+ 17:43 0:00.00 grep cron

Apart from the command above, there are lots of ps options, below we will give examples of several options from the ps command that you can try.

root@ns1:~ # ps aux | less

root@ns1:~ # ps -x

root@ns1:~ # ps -t pts/0

root@ns1:~ # ps -fL -C sshd

root@ns1:~ # ps -eo pid,ppid,user

root@ns1:~ # ps -A | grep -i sshd
814 - Is 0:00.00 sshd: /usr/local/sbin/sshd [listener] 0 of 10-100 startups (sshd)
2156 - Ss 0:00.04 sshd: root@pts/0 (sshd)
2236 0 S+ 0:00.00 grep -i sshd

The ps command is a very powerful tool for managing processes in FreeBSD. Whether you want to monitor a specific process, find processes that are taking up too much memory or CPU, or monitor all processes running on your system, the ps command provides the information you need. This is an essential tool for every FreeBSD administrator.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post