#21 process Management in Linux, with Pstree, PS, Pgrep, Pkill, pidof, top command applications

Source: Internet
Author: User
Tags pkill

Process Management:

The so-called process: a copy of the entity that processes, an activity program;

Life cycle;

May contain one or more execution flows;


To create a process:

The organizational structure of each process is consistent:


After the kernel starts up and takes over the hardware resources, it creates an init process, and the process called Init is responsible for the process management of the user space;


Centos5 and before: SysV init,classic Init

Defective: When booting the system, Init creates the individual sub-processes by writing a script, which is implemented by the shell, so it executes very slowly, causing the system to start faster and the process to be created very slowly;


Centos6:upstart, a new init process developed by Ubuntu, can start some associated service processes in parallel, and can create processes at the time of creation, and if there are multiple CPUs or multiple CPU cores, the process will be created with more noticeable changes. ; The first process name is still init;


CENTOS7:SYSTEMD, referring to the startup logic of Mac OS to develop a new version of the INIT program, which can be independent of its own to complete the operation of the entire operating system, that is, after booting and loading the kernel, Only one SYSTEMD process can be started to start the other service processes, which will lead the whole system to start up;


/sbin/init

/sbin/systemd


In addition to the INIT process, each process is created by its parent process;


Implemented by the fork () system call;


Each parent process uses the fork () system call to replicate its own data to the child process, which is not replicated immediately, but rather as a write-time copy (cow);


To terminate a process:

The child processes created by the task parent process must be destroyed by the parent process himself;


The parent-child relationship of any process is preserved in the task struct;


Process priority:

0-139

1-99: Real-time priority, the higher the number priority, the process started at the start of the system;

100-139: Static priority, the smaller the number the higher the priority, the process that starts when the user executes certain applications;


Nice value:

-20~19: The default nice value is 0;


Only administrators can use the nice value of a negative integer to elevate the priority of the process;

The normal user can only use the nice value of a positive integer to reduce the priority of the process;


140 process queues were divided;


Big O Standard:

O (1), O (Logn), O (N), O (n^2), O (2^n)


Classification of processes:

Follow the way the process starts;

Daemon process:

Daemon, which is usually initiated in the system boot process, is independent of any terminal, or can be started through a terminal;

User process:

After the user logs on to the system, the process starts through the terminal;


Follow the running location of the process:

Foreground process:

After the process has been started, the process has always occupied standard output or standard input or both standard output and standard input;

Background process:

After the process is started, the process does not occupy standard output and standard input;


By process for resource consumption:

Cpu-bond: A non-interactive process;

Io-bond: Various interactive processes such as editors;



Process-related commands on Linux systems (view commands and Management class commands):

Pstree,ps,pidof,pgrep,pkill,top,htop,glances,dstat,pmap,vmstat,bg,fg,jobs,kill,killall,nohup,nice,renice, ...


Pstree:

Pstree-display a tree of processes

Ps:

Ps-report a snapshot of the current processes.


PS [Options]


1 UNIX options, which may grouped and must is preceded by a dash.

2 BSD options, which may is grouped and must not being used with a dash.

3 GNU long options, which is preceded by and dashes.


Common options:

A: Display all terminal-related processes;

X: Shows all processes unrelated to the terminal;

U: Displays the account name of the user who initiated the process;


One of the most common combinations of options: aux


The PS aux command looks like the meaning of each field in the result:

USER PID%cpu%MEM VSZ RSS TTY STAT START time COMMAND

USER: Owner of the process

PID: Process Identifier

%CPU: The percentage of CPU processing time consumed by the process;

%MEM: The percentage of physical memory that the process occupies;

VSZ: Virtual Memory Set (exchangeable memory set)

RSS: A resident memory set

TTY: Which terminal is associated with the process;? indicates that the terminal is irrelevant;

STAT:

R:running, the running process;

S:interuptible sleeping, interrupted sleep state;

D:unintelligible sleeping, non-disruptive sleep state, disk block;

t:trace/stopped, tracked/stopped;

Z:zombie, zombie State;

+: Foreground process

L: processes that contain multithreading;

<: high-priority process

N: Low-priority process

S:session leader, has the parent process of the child process;

Start: Time stamp when the process starts executing

Time: The cumulative CPU consumption of the process;

Command: Start the process with the commands-line arguments;


UNIX-style options:

-e: Show All Processes

-F: Show process information in full format

-F: Displays process information in full format, almost the same as-F;

-H: A parent-child relationship with a hierarchical body oath process

o| -O field1,field2,... : Displays process-related information in a custom field;

Field:pid,ppid,ni,rtprio,psr,pcpu,stat,comm,user,tty,vsz,rss,...


Two common combinations of options:-ef

PPID: Parent Process PID

C: Indicates the percentage of CPU time consumed by the process


Three common combinations of options:-ef

SZ: Virtual Memory Set

RSS: Resident Memory Set

PSR: Indicates which CPU core the process is running on;


Four common option combinations:-EFH


Common choice combination of five:-eo | Axo Fielde1,fielde2,...


Pgrep, Pkill:

Pgrep, pkill-look up or signal processes based on name and other attributes


View or send a signal to a process based on the process name or other attributes;

pgrep [Options] Pattern

Pkill [Options] Pattern


Common options:

-U UID: Displays the active user of the process;

-U UID: Displays the true user of the process;

-T term: Displays the processes associated with the specified terminal;

-L: Displays the process name;

-A: Displays the full command-line parameters of the process;


Pidof:

Displays the process ID corresponding to the specified process name;


Top

Top-display Linux Processes

Top header:

First line: uptime information;

Current system time

Operating time of the system

The total number of users currently logged on to the system

The average length of the process queue that was waiting to run on the CPU for the last 1 minutes, 5 minutes, and 15 minutes


Second line:

Total number of processes running in the system

Number of processes that are running

Number of processes in the sleep state

Number of processes that have been stopped

The number of processes in a zombie state


Third line: CPU time consumption percent

Us:user space, the percentage of CPU time occupied by the process of user space;

Sy:system, the percentage of CPU time that is consumed by kernel processes in and out of space;

Ni:nice, using the Nice value to adjust the percentage of CPU time that is more occupied by the process priority;

ID:IDLE,CPU percentage of idle time;

Wa:waiting, the percentage of CPU time that is spent waiting for IO to complete

Hi:hardware interupting, the percentage of CPU time spent processing hardware interrupt time;

Si:software interupting, the percentage of CPU time consumed by the processing of the software interrupt time;

St:stolen, percentage of CPU time stolen by virtualization programs, etc.


Line four: Displays the usage of the physical memory space in kilobytes;

Total: The overall size of the physical memory space;

Free: The amount of idle physical memory space;

UserD: The size of the physical memory space that has been used;

Buffer/cache: The amount of physical memory space consumed by buffer and buffers; this memory space can be recycled at any time, not real consumption;

Avail mem: The actual amount of memory space available;


Line five: Displays the swap space usage in kilobytes;

Total: Overall size of virtual memory space

Used: The amount of virtual memory space that has been used;

Free: The amount of idle virtual memory space;


Interactive commands:

1: Show or hide CPU core information;

P: Sort by CPU occupancy percentage;

M: Sort According to the percentage of physical memory occupied;

T: According to the cumulative CPU occupied time to sort;

L: Close or display uptime information;

T: Close or display the second, third line of information;

M: Close or show the information of the four and five lines;

Q: Exit top switch mode;

S: Change the refresh interval of top;

K: Terminate the run of a specified PID process


Common options:

-D #: Specifies the time interval for top refresh, which is 3 seconds by default;

-B: Show process information by batch

-N #: Typically used with the-B option to indicate how many batches are displayed;


#21 process Management in Linux, with Pstree, PS, Pgrep, Pkill, pidof, top command applications

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.