Management of processes and processes

Source: Internet
Author: User
Tags pkill

First you have to understand the meaning of the process, the process is different from the program, the process is a running instance of the program, when a program runs, it will produce the corresponding process, therefore, the program is dead, and the process is alive. A process can contain a number of threads, the thread can help the application to do a few things at the same time (such as a thread to the disk to write files, the other to receive the user's keystrokes and react in a timely manner, do not interfere with each other), after the program is running, the system first is to create a default thread for the program process, The program can then add or remove related threads on its own, if necessary.

The process is managed by the kernel, and 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 user space, and the organizational structure of each process is consistent.

CentOS5 and previous: SysV Init,classic init, this approach is flawed: when booting the system, Init creates individual sub-processes by writing scripts, using the shell to implement them, so it executes very slowly , causing the system to start faster and process creation speed is very slow;

Centos6:upstart, with the new INIT process developed by Ubuntu, can start some associated service processes in parallel, can create a process in a multi-line process, if there are multiple CPUs or if there are multiple CPU cores, the speed of its process will be more obvious change ; 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 the entire operating system to start work, that is, after the boot and load the kernel, Only one SYSTEMD process can be started to start the other service processes, which will lead the whole system to start up;

As you can see, Centos7 is the fastest way to create a process, which is the root cause of why CENTOS7 is starting fast.

In addition to the INIT process, each process is created by its parent process, and any process parent-child relationship is saved in the task struct, and the life cycle of each child process is determined by the parent process, and a special case arises when the parent process "dies". Its child processes will always be in memory and become "zombies", which must be harmful to the system.

Each parent process uses the fork () system call to replicate its own data to the child process, which is not replicated immediately, but is copy-on-write (CoW), so-called copy-on-write, that is, only the content of the process space to change, the contents of the parent process will be copied to the child process .

the priority of the process is 140 integers in 0-139, where 1-99 is the real-time priority, the higher the number priority is, the process started at system startup, and 100-139 is the static priority, the smaller the number the higher the priority, and the process that starts when the user executes certain applications;

The priority is changed by using the nice value, the nice value has a range of-20-19, the default nice value is 0, and only the administrator can use the nice value of a negative integer to elevate the priority of the process, whereas a normal user can only use the nice value of a positive integer to reduce the priority of the process;

The types of processes are categorized as follows:

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;



Related commands for process management on Linux systems:

1,pstree, as the name implies, is to explicitly form the parent process as a tree

2,ps, a snapshot of the current process is reported, followed by options in three styles, Unix,bsd, and GNU, the following are the meanings of each option:

BSD-style 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 meaning of each field in the results displayed by the PS aux 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: 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:uninteruptible 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;


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;


-H: Show the parent-child relationship of the process in a hierarchical organization;

Four common option combinations:-EFH


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,...


Common choice combination of five:-eo | Axo Field1,field2,...


3,pgrep,pkill, depending on the process name or other attributes to view or send a signal to the process;

pgrep [Options] Pattern

Pkill [Options] Pattern


Common options:

-U UID: Shows the active user of the process

-U UID: Shows the real user of the process

-T term: Displays processes associated with the specified terminal

-L: Show process name

-A: Displays the full command-line arguments of the process

4,pidof, specifying the process ID corresponding to the process name

5,top:

The rest of the order to be continued!




Management of processes and processes

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.