1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
| # strace / ltrace
# systemcalls examples:
# process, files networking, signal, inter-process, comunication, terminals, threads, i/o devices
#---------------------------------------
strace -s 2000 -f ./traceme
strace -c [command] # summary
strace -p 1,2,3... -e trace=close,open -Ttrf -iq -o output.strace
strace -o /tmp/strace.out -s 2000 -fp 12152 # -e raw=select
# trace=network,memory,process,signal,file
ltrace -e fwrite_unlocked ls
ltrace -c /usr/bin/id # summary of libraries
open,read,write,connect,socket
# ps
#----------------------------------------
ps -e # all processes
ps aux
ps -C firefox-bin
ps axo pid,ppid,command
ps o pid,ppid,command,uid
pstree -p | grep httpd
#nohup webservices/env/bin/gunicorn -b 0.0.0.0:8000 apm.wsgi:application --chdir=webservices/apm/ > $WORKSPACE/scriptoutput.txt 2>&1 &
BUILD_ID=dontKillMe nohup webservices/env/bin/gunicorn -b 0.0.0.0:8000 apm.wsgi:application --chdir=webservices/apm/ &
# see what is eating RAM
ps -e -o pid,vsz,comm= | sort -n -k 2
# lsof
#----------------------------------------
lsof -a -u root -d txt
lsof -p ^1
lsof -i tcp/udp
lsof -i :80
lsof -i tcp:80
lsof -d txt/mem # lsof -d 0-2
lsof -i # show all connections
lsof -Pi
lsof -i6 # ipv6 connections
lsof -i -sTCP:LISTEN # listen state
lsof -a -u apache -i # all conenctions by user apache
lsof /var/log/messages # who is using this file
lsof +D /usr/lib
lsof -u apache # files opened by apache user
lsof -p 666 # opened files by a PID
lsof -c sendmail # opened files by sendmail
# others
#----------------------------------------
ldd /usr/bin/ls
# /proc filesystem information
cmdline, cmd process
maps, memory map
status, processes privileges
fd, file desc in use by processes
cwd, link to proc current dir
root, link to proc root dir
mounts, mount table
# quickly
strings /usr/bin/who # strings
ldd /usr/bin/yes # dependecies
nm -D -l -S /usr/bin/yes # symlbs
objdump -h /usr/bin/who # sections
objdump -s -j .rodata /yes # data
objdump -d -r -j .text /yes # code
# others
pstack <pid>
# OPENBSD
ktrace -o output.txt -p <PID>
kdump -f output.txt
# killing process without same
pids=( $(pgrep -f resque) )
for pid in "${pids[@]}"; do
if [[ $pid != $$ ]]; then
kill "$pid"
fi
done
# Memory stuff
#------------------------------
memstat -p 666
### BASIC
# check for uptime and load average
uptime
# top check cpu usage
top
# check processes
ps -ef f
ps -eo user,sz,rss,minflt,majflt,pcpu,args
# check virtual mem usage
vmstat -Sm 1
# check disk i/o status
iostat -xmdz 1
# check for multi-processor
mpstat -P ALL 1
# check memory
free -m
### INTERMEDIATE
# system call tracer
strace -tttT -p 313
# sniff network packets
tcpdump -i <iface> -w /tmp/out.tcpdump
# network stadistics
netstat -p -c 1
# network iface stats
nicstat 1
# process status
pidstat -t 1
pidstat -d 1
# check swap
swapon -s
# file descriptor checks
lsof -iTCP -sTCP:ESTABLISHED
# system activity reporter
sar -n TCP,ETCP,DEV 1
### ADVANCED
# socket stadistics
ss -mop
ss -i
# network usage
iptraf
# block device i/o by process
iotop
# kernel slab allocator mem usage
slabtop
# perf
perf_events
|