Linux Process Management

Source: Internet
Author: User
Tags cpu usage

A process is a copy of a program running, a life cycle exists, the CPU runs on a per-process basis by time, and a process that is not yet closed is saved in a fixed format in memory storage (task struct), and a list of task structs consisting of multiple tasks is called a task list. The result of our instruction is actually the data that is stored in the task list, and the data between processes is independent by cow when it is written.

    • Process priority
      • Real-time Priority: 0-99, the higher the number, the higher the priority, the real-time optimization is not adjustable, the highest priority.
      • Static priority: 100-139, the smaller the number, the higher the priority; non-kernel programs generally belong to this class, the default 120, can be adjusted with nice value, good value range in-20-19, for easy display, priority display by default 20, the range is between 0-39, The actual is 100-139.

Process memory allocation, a 4G memory machine, the kernel allocates physical memory to each process in the form of page frame, Max 3G, so each process is itself a process that is unique to the kernel, and the data in the process is divided into two categories.

    1. VSZ: Virtual Memory collection, containing a large number of library references
    2. RSS: Resident memory, some important instruction sets

Process Status:

    1. Operating state: Running
    2. Ready state: Readiness
    3. Sleep state:
      1. Interruptible: interruptable No additional data preparation is required
      2. Non-disruptive: uninterruptable, such as IO, is not yet loaded to complete
    4. Stop state: Paused in memory, but not dispatched unless manually initiated; stopped
    5. Zombie State: Zombie
Ps

PS has 3 kinds of display style
Unix style, option with one-
BSD style option does not take-
GNU with two-long options

BSD Style:

Common options

A: All terminal-related processes;
x: All processes unrelated to the terminal;
U: The user-centric organization process status information display;

[[email protected] ~]# ps axuUSER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMANDroot          1  0.0  0.3 193700  6848 ?        Ss   12:28   0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 21USERPID%CPU    cputime/realtime  cpu使用时间 除 进程累计运行时间%MEM    占整个内存比率VSZ     虚拟内存集      虚拟内存集中可能包含很多共享库   单位是kbRSS    常驻内存集  (resident set size, the non-swapped physical memory that a task has used (in kiloBytes).(alias rssize, rsz).)单位是kbSTAT           R:running        S:interruptable sleeping        D:uninterruptable sleeping        T:Stopped        Z:zombie        +:前台进程        l:多线程进程        N:低优先级进程        <:高优先级进程        s:session leader TIME   累计cpu使用时间
UNIX style

Common options

-e: Show All Processes
-F: Show process information in full format
-F: Displays process information in full format;
C:CPU Utilization Cputime/realtime CPU usage time In addition to process cumulative run time
PSR: on which CPU to run
-H: Displays information about the process in a hierarchical structure;

[[email protected] ~]# ps -efUID         PID   PPID  C STIME TTY          TIME CMDroot          1      0  0 12:28 ?        00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 21root          2      0  0 12:28 ?        00:00:00 [kthreadd]UIDPIDPPID   父pidC      cputime/realtime  cpu使用时间 除 进程累计运行时间STIME  启动时间TTY 相关终端TIME   cpu累计时间CMD

Custom options, O field1, field2,..., personal feel very useful
Common custom Fields

Uid
Uname
Group
Fuid FileSystem Access User ID
Fuser
Gid
%cpu PCPU
%mem Pmem
PSR processor that process was currently assigned to run on which CPU
Pid
Ppid
Tty
Rtprio Realtime priority real-time priority the higher the precedence level
Priority user Precedence (PRI is not the same algorithm)
Ni nice and nice value. This ranges (nicest) to-20 (no nice to others)
Vsz vsize Virtual Memory
RSS rssize Rsz resident Memory
S stat Status
Start command Starting Time
args cmd command

[[email protected] ~]# ps axo uname,pid,ppid,tty,pcpu,pmem,rtprio,priority,ni,vsz,rsz,s,start,cmd,priUSER        PID   PPID TT       %CPU %MEM RTPRIO PRI  NI    VSZ   RSZ S  STARTED CMD                         PRIroot          1      0 ?         0.0  0.3      -  20   0 193700  6848 S 12:57:49 /usr/lib/systemd/systemd --  19
Top

Top-display Linux Processes

  top-01:51:36 up 13:22, 3 users, load average:0.00,0.01,0.05 current time run often 3 user average load last 1 minutes, 5 minutes       Clock and 15 minutes of average load; cpu* (0-0.7 means smooth 1 full load 5 near death) tasks:112 Total, 2 running, sleeping, 0 stopped, 0 zombie how many processes 2 in running 110 in sleep 0 stops 0 zombie%cpu (s): 0.0 us, 0.1 sy, 0.0 NI, 99.9 ID, 0.0 WA, 0 .0 Hi, 0.0 si, 0.0th User space occupancy percentage the kernel occupies a process that has changed the priority of the user process to take up free idle standby (IO) hardware interrupts hardware Interru           PT software interrupt stolen Stealkib mem:1867048 Total, 1383244 free, 166956 used, 316848 buff/cache overall memory space  Free space uses recyclable buffer to write to the cache read Buffer KiB swap:2097148 total, 2097148 0 used. 1501796 avail Mem switched partition PID USER PR priority NI virt Virtual memory set Res resident memory shr shared memory S%cpu%MEM time+ (CPU cumulative time taken                 (room) COMMAND 607 root 0 305100 6168 4800 S 0.3 0.3 0:48.91 VMTOOLSD  

Interaction

M  根据内存排序 T  cpu累计占用时间  time排序P:以占据CPU百分比排序;首部信息:        uptime信息:l命令        tasks及cpu信息:t命令                1 分别显示每个cpu        内存信息:m命令修改刷新时间间隔:s终止指定的进程:k退出命令:q
Htop use

Finish top, in introducing an upgrade version of top htop, compared to top,htop provides more mouse convenient operation, more visual visualization.

[[email protected] yum.repos.d]# yum install htop

Help description

/Search
P Verbose/Concise program path
T-tree display to view process relationships
U filter based on user
K Show/Hide kernel threads while top is displayed
H Show/Hide User threads
F Cursor Tracking Program
P Sort by CPU M based on memory sort T based on CPU occupied time
I Reverse
custom field Sorting
Space next often
K End Process
A binding process on which CPU
L Show files opened by the process
S view system calls initiated by the current process
I involve priority
] Increase the priority level
[Reduce priority

Options:
-D #: Specify the delay interval;
-U UserName: Displays only the process of the specified user;
-S Colume: Sort by the specified field;
Sub-command:
L: Displays the list of files opened by the selected process;
S: Tracks system calls for the selected process;
T: Show the status of each process in a hierarchical relationship;
A: Binds the selected process to a specified CPU core;

Dstat

Versatile tool for generating system resource statistics, very powerful systems monitoring tools
Installation

[[email protected] ~]# yum install dstat

Common options?

-C,--CPU CPU information
-C 0,3,total which CPU
-D,--disk disk read-write
-D TOTAL,SDA Displays information about the disk
-G,--page displays page-related rate data;
-I.,--int terminal
-L,--load enable load average stats (1 min, 5 mins, 15mins)
-M,--MEM memory statistical data
-N,--net the relevant statistics of the network;
-N Eth1,total
-P,--proc process status
-R:--io displays relevant statistics for IO requests;
-S--swap: Displays the relevant statistics of swapped;
-T,--time current time
-Y,--sys CPU interrupt switch
--aio Asynchronous IO
--fs,--filesystem number of files and inodes
--IPC Queue Semaphore Shared memory
--raw all sockets
--socket TCP UDP, etc.
--tcp--UDP
--output file
--TOP-CPU Maximum CPU Usage
--top-cputime
--top-io: The most IO-intensive process;
--top-mem: The most memory-intensive process;
--top-latency: the most deferred process;

Dstat Delay Count

[[email protected] ~]# dstat 1 2  You did not select any stats, using -cdngy by default.----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int中断   csw-上下文切换  0   0 100   0   0   0|3413B 4582B|   0     0 |   0     0 |  87    64  0   0 100   0   0   0|   0     0 | 120B  818B|   0     0 |  71    53  0   0 100   0   0   0|   0     0 |  60B  338B|   0     0 |  48    41

View CPU

[[email protected] ~]# dstat -c  1 1----total-cpu-usage----usr用户占用比率  sys内核  idl空闲  wai等待   hiq硬件中断  siq软件中断  0   0 100   0   0   0  0   0 100   0   0   0

View Memory

[[email protected] ~]# dstat -m  1 1------memory-usage----- used  buff  cach  free 294M 2080k  472M 1055M 294M 2080k  472M 1055M

Disk Read and Write

[[email protected] ~]# dstat -d  1 1-dsk/total- read  writ3406B 4573B   0     0

Average load past 1,5,15 minute load, 0-0.8 smooth, 1 is full load over 5 is fast dying

[[email protected] ~]# dstat -l  1 1---load-avg--- 1m   5m  15m   0 0.01 0.05   0 0.01 0.05

Network IO Speed

[[email protected] ~]# dstat -n  1 1-net/total- recv接收  send发送   0     0  60B  194B

Process status

[[email protected] ~]# dstat -p  1 1---procs---run(运行) blk(阻塞 不可中断) new(新)0.0   0 0.2  0   0   0

Socket status

[[email protected] ~]# dstat --socket  1 1------sockets------tot tcp udp raw frg574   4   3   0   0574   4   3   0   0

TCP Status

[[email protected] ~]# dstat --tcp  1 1----tcp-sockets----lis监听  act确认   syn同步 tim等待 clo关闭  4   2   0   0   0  4   2   0   0   0

Maximum CPU Usage

[[email protected] ~]# dstat --top-cpu  1 1-most-expensive-  cpu processvmtoolsd     0.0

Use up to CPU time

[[email protected] ~]# dstat --top-cputime  1 1--highest-total-- cputime processvmtoolsd     1055vmtoolsd      635

Up to IO

[[email protected] ~]# dstat --top-io  1 1----most-expensive----     i/o processbash         34k 3198Bsshd: [email protected] 146B  180B

Max memory

[[email protected] ~]# dstat --top-mem  1 1--most-expensive-  memory processfirewalld   27.0Mfirewalld   27.0M

Maximum delay

[[email protected] ~]# dstat --top-latency  1 1--highest-total-- latency processvmtoolsd       85kworker/1:1  60
Process Tuning

Non-kernel process default priority=120, in order to facilitate the reading of many scenarios using 20
Nice value range at-20-19
0<=priority<=39 after tuning

Increase the priority level

[[email protected] yum.repos.d]# nice -n -5 htop   

[[email protected] 14511]# cat /proc/13828/schedhtop (13828, #threads: 1)-------------------------------------------------------------------......prio                                         :                  115.......

Lower the priority level

[[email protected] yum.repos.d]# nice -n 5 htop   [[email protected] ~]# ps axo uname,pid,ppid,tty,pcpu,pmem,rtprio,priority,ni,vsz,rsz,s,start,cmd|grep  htoproot      13851   2368 pts/1     0.2  0.1      -  25   5 122432  2116 S 08:42:53 htop

The running program can be tuned with Renice

#renice  [-n]  NICE  PID...[[email protected] ~]# renice -n -3  1385113851 (进程 ID) 旧优先级为 5,新优先级为 -3

Linux Process Management

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.