The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.
top - 12:32:15 up 11 days, 17:00, 2 users, load average: 0.01, 0.03, 0.00
Tasks: 131 total, 1 running, 130 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 821.2 total, 185.4 free, 216.3 used, 419.5 buff/cache
MiB Swap: 2116.0 total, 2095.9 free, 20.1 used. 465.3 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 179176 13480 9140 S 0.0 1.6 0:11.96 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.18 kthreadd
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp
6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-kblockd
8 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq
9 root 20 0 0 0 0 S 0.0 0.0 0:06.55 ksoftirqd/0
10 root 20 0 0 0 0 I 0.0 0.0 0:21.09 rcu_sched
11 root rt 0 0 0 0 S 0.0 0.0 0:00.03 migration/0
12 root rt 0 0 0 0 S 0.0 0.0 0:00.14 watchdog/0
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0
14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/1
15 root rt 0 0 0 0 S 0.0 0.0 0:00.68 watchdog/1
16 root rt 0 0 0 0 S 0.0 0.0 0:00.02 migration/1
17 root 20 0 0 0 0 S 0.0 0.0 0:00.34 ksoftirqd/1
19 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/1:0H-kblockd
21 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
22 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 netns
23 root 20 0 0 0 0 S 0.0 0.0 0:00.03 kauditd
25 root 20 0 0 0 0 S 0.0 0.0 0:00.21 khungtaskd
Remember that top
can display:
Important Keyboard shortcuts:
t
- change CPU displaym
- Change memory displayf
- Select sorting field<
>
- Walk through sorting fieldu
- Filter by userr
- Renice taskk
- Kill taskR
- Reverse sortc
- Command/line1
- CPUsps
displays information about a selection of the active processes.
# ps
PID TTY TIME CMD
27278 pts/1 00:00:00 bash
27385 pts/1 00:00:00 ps
# ps -ef | grep rsyslogd
root 1162 1 0 Nov28 ? 00:00:41 /usr/sbin/rsyslogd -n
root 27501 27278 0 12:42 pts/1 00:00:00 grep --color=auto rsyslogd
This version of ps accepts several kinds of options:
Important Options:
Note that
ps -aux
is distinct fromps aux
. The POSIX and UNIX standards require thatps -aux
print all processes owned by a user named "x", as well as printing all processes that would be selected by the-a
option. If the user named "x" does not exist, this ps may interpret the command asps aux
instead and print a warning. This behavior is intended to aid in transitioning old scripts and habits. It is fragile, subject to change, and thus should not be relied upon.
The command kill sends the specified signal to the specified processes or process groups. If no signal is specified, the TERM signal is sent.
📌 EXAM TIP: Use kill -l
to list all the kill signals.
# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
pgrep
looks through the currently running processes and lists the process IDs which match the selection criteria to stdout.
# pgrep sshd
857
22574
22591
27262
27277
pkill
will send the specified signal (by default SIGTERM) to each process instead of listing them on stdout
pidof
finds the process id's (pids) of the named programs. It prints those id's on the standard output.
pidof
is similar to pgrep
but without kill and regex capability.
You can use top
# top -b -n 1 | grep "load average"
top - 21:36:13 up 1:06, 3 users, load average: 0.68, 0.96, 1.07
Or w
# w | grep "load average"
21:36:13 up 1:06, 3 users, load average: 0.68, 0.96, 1.07
Or uptime
uptime | grep "load average"
21:36:13 up 1:06, 3 users, load average: 0.68, 0.96, 1.07