********* simple selection ********* ********* selection by list ********* -A all processes -C by command name -N negate selection -G by real group ID (supports names) -a all w/ tty except session leaders -U by real user ID (supports names) -d all except session leaders -g by session OR by effective group name -e all processes -p by process ID T all processes on this terminal -s processes in the sessions given a all w/ tty, including other users -t by tty g OBSOLETE -- DO NOT USE -u by effective user ID (supports names) r only running processes U processes for specified users x processes w/o controlling ttys t by tty *********** output format ********** *********** long options *********** -o,o user-defined -f full --Group --User --pid --cols --ppid -j,j job control s signal --group --user --sid --rows --info -O,O preloaded -o v virtual memory --cumulative --format --deselect -l,l long u user-oriented --sort --tty --forest --version -F extra full X registers --heading --no-heading --context ********* misc options ********* -V,V show version L list format codes f ASCII art forest -m,m,-L,-T,H threads S children in sum -y change -l format -M,Z security data c true command name -c scheduling class -w,w wide output n numeric WCHAN,UID -H process hierarchy
S PROCESS STATE CODES D Uninterruptible sleep (usually IO) R Running or runnable (on run queue) S Interruptible sleep (waiting for an event to complete) T Stopped, either by a job control signal or because it is being traced. W paging (not valid since the 2.6.xx kernel) X dead (should never be seen) Z Defunct (“zombie”) process, terminated but not reaped by its parent.
lwp (light weight process, or thread) ID 线程ID
C processor utilization. Currently, this is the integer value of the percent usage over the lifetime of the process.
NLWP 轻量级进程的个数
ni NI nice value. This ranges from 19 (nicest) to -20 (not nice to others)
size SZ approximate amount of swap space that would be required if the process were to dirty all writable pages and then be swapped out. This number is very rough!
wchan WCHAN name of the kernel function in which the process is sleeping, a “-“ if the process is running, or a “*” if the process is multi-threaded and ps is not displaying threads.
线程信息
线程线程的选项:
H Show threads as if they were processes 显示正在处理的线程
-L Show threads, possibly with LWP and NLWP columns 显示线程
-H : Threads toggle Starts top with the last remembered ’H’ state reversed. When this toggle is On, all individual threads will be displayed. Otherwise, top displays a summation of all threads in a process. 当此开关打开时,将显示所有单个线程。否则,top显示进程中所有线程的总和。
-p : Monitor PIDs as: -pN1 -pN2 ... or -pN1, N2 [,...] Monitor only processes with specified process IDs. This option can be given up to 20 times, or you can provide a comma delimited list with up to 20 pids. Co-mingling both approaches is permitted. This is a command-line option only. And should you wish to return to normal operation, it is not necessary to quit and and restart top -- just issue the ’=’ interactive command. 打开top后,= 可以切换回全部进程
jstack Java线程栈信息
jstack中的线程id为16进制,需要将从top或ps获取的线程id转换为16进制,
1
printf %x <tid>
注意:
jstack必须和运行的JVM进程是同一个用户
1 2 3 4 5
Options: -F to force a thread dump. Use when jstack <pid> does not respond (process is hung) -m to print both java and native frames (mixed mode) -l long listing. Prints additional information about locks -h or -help to print this help message
The -XX:+PrintFlagsFinal (emphasis on "Final") option displays what options HotSpot ended up using for running Java code while -XX:+PrintFlagsInitial (emphasis on "Initial") displays what options were provided to HotSpot initially, before HotSpot has made its own tweaks.
jinfo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
jinfo -flags $PID
Attaching to process ID 29893, please wait... Debugger attached successfully. Server compiler detected. # 服务器版本的编译器 JVM version is 25.232-b09 # jvm版本 Non-default VM flags: -XX:CICompilerCount=2 -XX:InitialHeapSize=33554432 # 初始堆大小 33M -XX:MaxHeapSize=524288000 # 最大堆大小 524M -XX:MaxNewSize=174718976 #年轻代最大大小 174M -XX:MinHeapDeltaBytes=196608 #堆自动增加步长最小196K -XX:NewSize=11141120 #年轻代大小11M -XX:OldSize=22413312 #老年代大小22M -XX:+UseCompressedClassPointers #压缩类指针 -XX:+UseCompressedOops #压缩 -XX:+UseParallelGC # 使用并行回收器
class: Displays statistics about the behavior of the classloader. compiler: Displays statistics about the behavior of the Java HotSpot VM Just-in-Time compiler. gc: Displays statistics about the behavior of the garbage collected heap. gccapacity: Displays statistics about the capacities of the generations and their corresponding spaces. gccause: Displays a summary about garbage collectionstatistics(same as -gcutil), with the cause of the last andcurrent(when applicable) garbage collection events. gcnew: Displays statistics of the behavior of the newgeneration. gcnewcapacity: Displays statistics about the sizes of the newgenerations and its corresponding spaces. gcold: Displays statistics about the behavior of the old generation and metaspace statistics. gcoldcapacity: Displays statistics about the sizes of the old generation. gcmetacapacity: Displays statistics about the sizes of the metaspace. gcutil: Displays a summary about garbage collection statistics. printcompilation: Displays Java HotSpot VM compilation method statistics.
jstat -gc 12196 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 512.01024.0496.00.067584.038337.9437248.075268.883992.080411.09496.08854.43885.64330.3906.033
-gc option Garbage-collected heap statistics.
S0C: Current survivor space 0 capacity (kB). #s0区当前容量 S1C: Current survivor space 1 capacity (kB). #s1区当前容量 S0U: Survivor space 0 utilization (kB). #s0区使用量 S1U: Survivor space 1 utilization (kB). #s1区使用量 EC: Current eden spacecapacity(kB). #eden区容量 EU: Eden spaceutilization(kB). #eden区使用量 OC: Current old spacecapacity(kB). #old区容量 OU: Old spaceutilization(kB). #old区使用量 MC: Metaspacecapacity(kB). #metaspace容量 MU: Metacspaceutilization(kB). #metaspace使用量 CCSC: Compressed classspace capacity (kB). #压缩类空间容量 CCSU: Compressed classspace used (kB). #压缩类空间使用量 YGC: Number of young generation garbage collection events. # YGC次数 YGCT: Young generation garbage collection time. #YGC耗时 FGC: Number of full GC events. # Full GC次数 FGCT: Full garbage collection time. # Full GC耗时 GCT: Total garbage collection time. # GC总耗时
GC统计
1 2 3
jstat -gcutil 12196 S0 S1 E O M CCS YGC YGCT FGC FGCT GCT 96.880.0089.9617.2195.7493.243885.64330.3906.033
1 2 3 4 5 6 7 8 9 10 11 12 13 14
-gcutil option Summary of garbage collection statistics.
S0: Survivor space 0 utilization as a percentage of the space's current capacity. # s0区使用率 S1: Survivor space 1 utilization as a percentage of the space's current capacity. # S1区使用率 E: Eden space utilization as a percentage of the space's current capacity. # eden区使用率 O: Old space utilization as a percentage of the space's current capacity. # old区使用率 M: Metaspace utilization as a percentage of the space's current capacity. # Metaspace使用率 CCS: Compressed class space utilization as a percentage. # 压缩类空间使用率 YGC: Number of young generation GC events. # YGC次数 YGCT: Young generation garbage collection time. # YGC耗时 FGC: Number of full GC events. # Full GC次数 FGCT: Full garbage collection time. # Full GC耗时 GCT: Total garbage collection time. # GC总耗时
Prints shared object memory maps or heap memory details for a process, core file, or remote debug server. This command is experimental and unsupported. 打印进程、核心文件或远程调试服务器的共享对象内存映射或堆内存详细信息