documentation. 여기서 설명하는 것 이상으로 유용한 command 및 top에서 출력하는 정보에 대한 내용이 써져 있으니 궁금하면 찾아보자.
ps는 command 실행 순간의 process들 상태의 snapshot을 보여주지만, top은 실시간 process 상태에 대한 정보를 준다.
top - 19:01:12 up 1:44, 0 users, load average: 0.00, 0.00, 0.00
Tasks: 19 total, 1 running, 18 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.1 us, 0.1 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 25592.2 total, 25105.4 free, 374.3 used, 112.5 buff/cache
MiB Swap: 7168.0 total, 7168.0 free, 0.0 used. 24945.1 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
85 sycho 20 0 992640 125812 40476 S 1.0 0.5 0:51.66 node
24 sycho 20 0 959228 94088 40332 S 0.3 0.4 0:06.82 node
123 sycho 20 0 656884 71852 38508 S 0.3 0.3 0:05.05 node
1 root 20 0 908 536 472 S 0.0 0.0 0:00.01 init
12 root 20 0 916 84 20 S 0.0 0.0 0:00.00 init
13 root 20 0 916 92 20 S 0.0 0.0 0:00.00 init
14 sycho 20 0 2884 1012 920 S 0.0 0.0 0:00.00 sh
15 sycho 20 0 2884 960 868 S 0.0 0.0 0:00.00 sh
20 sycho 20 0 2884 952 856 S 0.0 0.0 0:00.00 sh
35 root 20 0 916 84 20 S 0.0 0.0 0:00.00 init
36 root 20 0 916 92 20 S 0.0 0.0 0:00.71 init
37 sycho 20 0 602240 56428 36324 S 0.0 0.2 0:01.82 node
62 root 20 0 916 84 20 S 0.0 0.0 0:00.00 init
63 root 20 0 916 92 20 S 0.0 0.0 0:00.71 init
64 sycho 20 0 597536 51516 36236 S 0.0 0.2 0:01.84 node
71 sycho 20 0 849288 59252 37856 S 0.0 0.2 0:03.09 node
160 sycho 20 0 6236 5316 3532 S 0.0 0.0 0:00.06 bash
187 sycho 20 0 603412 54028 37144 S 0.0 0.2 0:00.25 node
10938 sycho 20 0 7788 3740 3140 R 0.0 0.0 0:00.00 top
top with keyshtop을 누른 다음에 어떻게 조작을 해야 할지 모르겠으면, h를 누르면 바로 어떤 key들을 눌러 상호작용을 할 수 있는지 알려준다. 아니면 그냥 위의 documentation을 읽자.Help for Interactive Commands - procps-ng 3.3.17
Window 1:Def: Cumulative mode Off. System: Delay 3.0 secs; Secure mode Off.
Z,B,E,e Global: 'Z' colors; 'B' bold; 'E'/'e' summary/task memory scale
l,t,m,I Toggle: 'l' load avg; 't' task/cpu; 'm' memory; 'I' Irix mode
0,1,2,3,4 Toggle: '0' zeros; '1/2/3' cpu/numa views; '4' cpus two abreast
f,F,X Fields: 'f'/'F' add/remove/order/sort; 'X' increase fixed-width
L,&,<,> . Locate: 'L'/'&' find/again; Move sort column: '<'/'>' left/right
R,H,J,C . Toggle: 'R' Sort; 'H' Threads; 'J' Num justify; 'C' Coordinates
c,i,S,j . Toggle: 'c' Cmd name/line; 'i' Idle; 'S' Time; 'j' Str justify
x,y . Toggle highlights: 'x' sort field; 'y' running tasks
z,b . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')
u,U,o,O . Filter by: 'u'/'U' effective/any user; 'o'/'O' other criteria
n,#,^O . Set: 'n'/'#' max tasks displayed; Show: Ctrl+'O' other filter(s)
V,v . Toggle: 'V' forest view; 'v' hide/show forest view children
k,r Manipulate tasks: 'k' kill; 'r' renice
d or s Set update interval
W,Y,! Write config file 'W'; Inspect other output 'Y'; Combine Cpus '!'
q Quit
( commands shown with '.' require a visible task display window )
Press 'h' or '?' for help with Windows,
Type 'q' or <Esc> to continue
qtop이 종료된다.목록을 스크롤링 할 때 사용한다.
또 이미 맨 위에 있을 때 PGUP이나 ↑을 누르면 갱신이 된다. 그래서 이를 꾹 누르고 있으면 거의 실시간으로 상태가 어떻게 변하고 있는지 알 수 있다.
꾹 누르지 않고 가만히 지켜보면 대충 3초마다 갱신을 한다.
scroll coordinates: y = 1/19 (tasks), x = 1/12 (fields)
SHIFT + P : CPU 사용률에 따라 정렬
SHIFT + M : 메모리 사용률에 따라 정렬
SHIFT + R : 현재 정렬 기준의 반대로 정렬 (오름차순 -> 내림차순 / 내림차순 -> 오름차순)
굳이 단축키를 안 쓰고 원하는 기준으로 정렬하는 것도 가능하다. 메인 화면에서 f를 누르면 여러 항목 중 하나를 선택할 수 있다.
Fields Management for window 1:Def, whose current sort field is %CPU
Navigate with Up/Dn, Right selects for move then <Enter> or Left commits,
'd' or <Space> toggles display, 's' sets sort. Use 'q' or <Esc> to end!
* PID = Process Id nTH = Number of Threads nsPID = PID namespace Inode
* USER = Effective User Name P = Last Used Cpu (SMP) nsUSER = USER namespace Inode
* PR = Priority TIME = CPU Time nsUTS = UTS namespace Inode
* NI = Nice Value SWAP = Swapped Size (KiB) LXC = LXC container name
* VIRT = Virtual Image (KiB) CODE = Code Size (KiB) RSan = RES Anonymous (KiB)
* RES = Resident Size (KiB) DATA = Data+Stack (KiB) RSfd = RES File-based (KiB)
* SHR = Shared Memory (KiB) nMaj = Major Page Faults RSlk = RES Locked (KiB)
* S = Process Status nMin = Minor Page Faults RSsh = RES Shared (KiB)
* %CPU = CPU Usage nDRT = Dirty Pages Count CGNAME = Control Group name
* %MEM = Memory Usage (RES) WCHAN = Sleeping in Function NU = Last Used NUMA node
* TIME+ = CPU Time, hundredths Flags = Task Flags <sched.h>
* COMMAND = Command Name/Line CGROUPS = Control Groups
PPID = Parent Process pid SUPGIDS = Supp Groups IDs
UID = Effective User Id SUPGRPS = Supp Groups Names
RUID = Real User Id TGID = Thread Group Id
RUSER = Real User Name OOMa = OOMEM Adjustment
SUID = Saved User Id OOMs = OOMEM Score current
SUSER = Saved User Name ENVIRON = Environment vars
GID = Group Id vMj = Major Faults delta
GROUP = Group Name vMn = Minor Faults delta
PGRP = Process Group Id USED = Res+Swap Size (KiB)
TTY = Controlling Tty nsIPC = IPC namespace Inode
TPGID = Tty Process Grp Id nsMNT = MNT namespace Inode
SID = Session Id nsNET = NET namespace Inode
s를 누르고 Esc를 누르면 그 항목을 기준으로 정렬이 이루어진다.메인 화면에서 SHIFT + L을 누르면 단어를 입력하라고 한다. 그걸 누르고 enter을 치면 해당 단어가 나오는 경우들이 전부 하이라이트가 된다.
o를 사용하면 특정 조건을 만족하는 process들만 보이게 할 수 있다. (filtering) 조건들은 전부 {field name}{comparator}{value}의 형식을 가진다.
예를 들어 sycho라는 사용자가 소유하는 process들을 보고 싶으면 o를 누른 다음, USER=sycho를 사용하면 된다.
아니면 메모리를 0.3% 넘게 사용하는 process들을 보고 싶으면 o를 누른 다음 %MEM>0.3을 사용하면 된다.
현재 top에서 사용중인 filter을 보고 싶으면 Ctrl + O 를 누르면 된다.
현재 top에서 사용중인 filter을 전부 지우고 싶으면 =을 누르면 된다.
맨 처음 출력을 보면 메모리 관련 정보가 나오는데, 이것을 끄거나, 그래프 형식으로 보이게 하고 싶으면 m을 메인 화면에서 누르면 된다.
k를 누르면 특정 process에게 signal을 보내는게 가능하다. k를 누른 다음 처음에 signal을 보낼 PID를 입력하고 enter, 이후 보낼 signal의 이름이나 대응되는 번호를 누르고 enter을 누르면 그게 전달된다. 아무것도 안 누를시 보낼 signal, 그리고 이게 보내질 process가 창에 나타나니 유의. 취소하고 싶으면 Esc를 누르면 된다.
d를 누르면 갱신 주기를 조절하는게 가능하다. 단위는 초다. 다만 소수점 한자릿수 까지만 허용해주는것 같다.
Shift + W를 누르면 현재 top에 적용된 설정이 .toprc라는 파일에 저장이 된다. 그리고 다음에 top을 실행할 때 이 설정으로 실행이 된다.
Shift + E를 누르면 memory metric의 단위을 KB, MB, GB, TB, PB 순서로 바꾼다. E를 누르면 process별 memory 사용량에 대한 단위를 앞의 순서처럼 바꾼다.