Performance analysis of [Linux operating system series]

Keywords: Linux Operation & Maintenance ssh


3, Performance analysis

1. Process query: ps

The man ps manual is very large and not easy to refer to, so I mainly remember several commands


#1. List the processes that are only related to their own environment. The parent process at the top layer is the bash that allows the ps command, but does not extend to the init process
ps -l

#2. List the information of all processes in the system
ps aux
ps -ef    #aux truncates the COMMAND column, -ef not. aux is BSD style and -ef is System V style
ps axjf   #Display all processes as a "process tree"
ps -lA    #The output format is the same as ps -l

  • F: Process flag, indicating the permissions of the process
    • 4: root privileges
    • 1: Only fork but not exec
    • 0: neither 4 nor 1
  • S: Status of the process
    • R(running): running
    • S(Sleep): wakeable sleep
    • D: Non wakeable sleep (usually waiting for I/O)
    • T: Stop, possibly in the background
    • Z(Zombie): Zombie process
  • C: CPU utilization
  • PRI/NI: abbreviation of Priority/Nice, CPU priority (the smaller the higher)
  • ADDR/SZ/WCHAN: memory related. ADDR indicates which part of memory the process is in. The running process generally displays' - '. SZ is the memory used by the process. WCHAN indicates whether the process is currently running '-'. When the process is sleeping, it indicates the events the process is waiting for
  • TTY: the terminal where the process runs
  • TIME: CPU TIME used by the process

  • USER: the USER to which the process belongs
  • %CPU/%MEM: percentage of CPU and memory consumed by the process
  • VSZ: virtual memory used by the process (KB)
  • RSS: fixed memory occupied by the process (KB)
  • TTY: the terminal where the process is running. If it is not related to the terminal, it will display '?'. tty1~tty6 are the login programs of this machine. pts/0 indicates the process of connecting to the host from the network
  • STAT: the current state of the process, which is equivalent to S in the ps -l result
  • START: the time when the process started
  • TIME: the CPU running TIME actually used by the process

2. Process monitoring: top

usage method

top [option]

    -d: Specifies the update interval in seconds
    -n: And-b Match, specify how many times it needs to be done top Output, commonly used in redirection
    -p: appoint PID´╝îMonitor specific processes

Commands in top mode:

  • ?: Displays the available commands
  • P: Sort by CPU usage
  • M: Sort by memory usage
  • N: Sort by PID
  • q: Exit
  • 1: Switching CPU in case of multi-core

%"wa" after Cpu(s) indicates I/O wait. Too high indicates that I/O is waiting for a long time and there is a bottleneck in I/O

3. Open file query: lsof

usage method

lsof [option]

    -i: -i:Port number: check whether the port is occupied
    -u: Follow the user name to view the files opened by the specific user
    -p: Heel PID View files opened by the specified process
    +d: Follow the directory to view the files opened by the process in the specified directory,"+D"recursion

4. Memory usage: free

usage method

free [option]

    -b|-k|-m|-g: Company
    -t: List physical memory and swap Summary of    

  • buffers: mainly caches metadata such as dentry and inode
  • cached: mainly caches the contents of the file, that is, page cache
  • -buffers/cache: memory actually used. used-buffers-cached
  • +buffers/cache: available memory. free+buffers+cached (buffers and cached can be recycled when memory is tight)

Detailed result description

5. Resource limitation of shell process: ulimit

usage method

ulimit [option]       #see
ulimit [option] New value  #modify

    -a: list shell All resource constraints for the process(-a The command lists options (parameters) for viewing a resource limit

Modifying the resource limit with ulimit will only be effective for the current terminal environment. If you want to permanently take effect, you can modify the file / etc/security/limits.conf. The contents of the file are as follows;

# /etc/security/limits.conf
#Each line describes a limit for a user in the form:
#<domain>        <type>  <item>  <value>
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#        - NOTE: group and wildcard limits are not applied to root.
#          To apply a limit to the root user, <domain> must be
#          the literal username root.
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open files
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#        - chroot - change root to directory (Debian-specific)
#<domain>      <type>  <item>         <value>

#*               soft    core            0
#root            hard    core            100000
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#ftp             -       chroot          /ftp
#@student        -       maxlogins       4

# End of file


root@068ca8da6d06:/# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 7863
max locked memory       (kbytes, -l) 82000
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1048576
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Posted by titaniumtommy on Mon, 06 Sep 2021 12:30:02 -0700