如何查询进程中占用CPU的线程

如何查询进程中占用CPU的线程

(1)命令查找进程PID

top -c  或jps -v 

(2)找进程中的线程号

top -Hp PID

(3)将线程转换成16进制(对应nid)

printf %x PID 线程号 

(4)查看具体的线程

jstack PID |grep 线程ID转换的4位16进制数 -C5 --color 找到线程
或者 
jstack [PID] > jstack.txt
cat jstack.txt | grep -i 线程ID转换的4位16进制数

cpu状态和负载

top命令

展示一个summary,然后进程的细节信息,如

top - 16:45:08 up 372 days, 20:06,  2 users,  load average: 0.68, 0.61, 0.64
Tasks: 411  
%Cpu(s):  8.4 us,  0.3 sy,  0.0 ni, 91.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 13177932+total, 86366936 free, 13936328 used, 31476060 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 11138535+avail Mem

PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
.......

man top

NAME
top - display Linux processes

SYNOPSIS

       top -hv|-bcHiOSs -d secs -n max -u|U user -p pid -o fld -w [cols]

DESCRIPTION

(1)The top program provides a dynamic real-time view of a running system.
(2)It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.
(3)The types of system summary information shown and the types, order and size of information displayed for processes are all user configurable and that configuration can be made persistent across restarts.
(4)The program provides a limited interactive interface for process manipulation as well as a much more extensive interface for personal configuration – encompassing every aspect of its oper‐ation. And while top is referred to throughout this document, you are free to name the program anything you wish. That new name, possibly an alias, will then be reflected on top’s displayand used when reading and writing a configuration file.

-H  :Threads-mode operation
        Instructs top to display individual threads.  Without this command-line option a summation of all threads in each process is shown.  Later this can be changed with  the  `H'  interactive
            command.
-p  :Monitor-PIDs mode as:  -pN1 -pN2 ...  or  -pN1,N2,N3 ...
    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.

    A pid value of zero will be treated as the process id of the top program itself once it is running.

    This  is a command-line option only and should you wish to return to normal operation, it is not necessary to quit and restart top  --  just issue any of these interactive commands: `=',
    `u' or `U'.

    The `p', `u' and `U' command-line options are mutually exclusive
          

SUMMARY Display

       Each of the following three areas are individually controlled through one or more interactive commands.  See topic 4b. SUMMARY AREA Commands for additional information regarding these  provi‐
       sions.

   2a. UPTIME and LOAD Averages
       This portion consists of a single line containing:
           program or window name, depending on display mode
           current time and length of time since last boot
           total number of users
           system load avg over the last 1, 5 and 15 minutes

   2b. TASK and CPU States
       This portion consists of a minimum of two lines.  In an SMP environment, additional lines can reflect individual CPU state percentages.

       Line 1 shows total tasks or threads, depending on the state of the Threads-mode toggle.  That total is further classified as:
           running; sleeping; stopped; zombie

       Line 2 shows CPU state percentages based on the interval since the last refresh.

       As a default, percentages for these individual categories are displayed.  Where two labels are shown below, those for more recent kernel versions are shown first.
           us, user    : time running un-niced user processes
           sy, system  : time running kernel processes
           ni, nice    : time running niced user processes
           id, idle    : time spent in the kernel idle handler
           wa, IO-wait : time waiting for I/O completion
           hi : time spent servicing hardware interrupts
           si : time spent servicing software interrupts
           st : time stolen from this vm by the hypervisor

       In the alternate cpu states display modes, beyond the first tasks/threads line, an abbreviated summary is shown consisting of these elements:
                      a    b     c    d
           %Cpu(s):  75.0/25.0  100[ ...

       Where: a) is the combined us and ni percentage; b) is the sy percentage; c) is the total; and d) is one of two visual graphs of those representations.  See topic 4b. SUMMARY AREA Commands and
       the `t' command for additional information on that special 4-way toggle.

   2c. MEMORY Usage
       This portion consists of two lines which may express values in kibibytes (KiB) through exbibytes (EiB) depending on the scaling factor enforced with the `E' interactive command.

       As a default, Line 1 reflects physical memory, classified as:
           total, free, used and buff/cache

       Line 2 reflects mostly virtual memory, classified as:
           total, free, used and avail (which is physical memory)

       The avail number on line 2 is an estimation of physical memory available for starting new applications, without  swapping.   Unlike  the  free  field,  it  attempts  to  account  for  readily
       reclaimable page cache and memory slabs.  It is available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free.

       In the alternate memory display modes, two abbreviated summary lines are shown consisting of these elements:
                      a    b          c
           GiB Mem : 18.7/15.738   [ ...
           GiB Swap:  0.0/7.999    [ ...

       Where: a) is the percentage used; b) is the total available; and c) is one of two visual graphs of those representations.

       In  the case of physical memory, the percentage represents the total minus the estimated avail noted above.  The `Mem' graph itself is divided between used and any remaining memory not other‐
       wise accounted for by avail.  See topic 4b. SUMMARY AREA Commands and the `m' command for additional information on that special 4-way toggle.

cpu负载.

Understand Linux Load Averages and Monitor Performance of Linux,understanding-load-averages

~$ uptime
 17:08:25 up 372 days, 20:29,  2 users,  load average: 1.68, 0.98, 0.75

The numbers are read from left to right, and the output above means that:

load average over the last 1 minute is 1.98
load average over the last 5 minutes is 2.15
load average over the last 15 minutes is 2.21
High load averages imply that a system is overloaded; many processes are waiting for CPU time.
  • System load/CPU Load – is a measurement of CPU over or under-utilization in a Linux system; the number of processes which are being executed by the CPU or in waiting state.
  • Load average – is the average system load calculated over a given period of time of 1, 5 and 15 minutes.
    In Linux, the load-average is technically believed to be a running average of processes in it’s (kernel) execution queue tagged as running or uninterruptible

你可能感兴趣的:([27]JVM)