9-17 Linux process View and management

Source: Internet
Author: User
Tags message queue network function terminates

Linux process viewing and management

Basic features of the OS: file system, network functions, process management, memory management, drivers, security features

program = instruction + data

Cpu:
Privileged Directives
General Instructions

Program execution Environment:
Kernel mode: Run kernel-level directives
User mode: Run General Instructions

Application:
Run normal command: Run directly on the CPU
Run privileged command: via system call

Memory: 8bits, 1byte
32bits, 2^32, 0-2^32-1, 2^10*2^10*2^10*2^2 bytes = 2^10*2^10*2^2 Kilo bytes = 2^10*2^2 MB = 4GB
64bits, 2^64, 4billions 4G

4G:1G, kernel
3G, App

Rom+ram
ROM, RAM

Address space:
Physical Address space
Linear address space

Ipc:inter Process Communication
Same host:
Signal
Semerphor
SHM (Shared memory)

Different hosts:
Rpc:remote Procedure Call
Socket

Process scheduling:

Multitasking: Multi-process running at the same time
Preemptive multi-tasking

Process classification:
CPU Bound:cpu Intensive
I/O Bound:io intensive

Process priority:
140:0-139
1-99: Real-time priority, the higher the number, the greater the priority
100-139: The smaller the number, the higher the priority;
Static priority
Dynamic priority

Algorithm time complexity: Big O
O (1)
O (LOGN)
O (N)
O (n^2)
O (2^n)

Process creation:
Request Issuer: Process
Process: Fork (), Clone ()

Cow:copy on Writing
Copy when writing

Status of the process:
Operating state: Running
Sleep state: Sleeping
Interrupted sleep: interruptible
Non-disruptive sleep: uninterruptible
Processes that are blocked by IO
Ready state: Runnable
Stop state: Stopped, can not be scheduled to run state;
Zombie State: Zombie

Process Management:
Task struct: Used to hold each process meta-data information
Example: PID, Ppid, memory, thread, files

Task List: Saves the task struct for each process with a data structure called a "linked list"

Process switching: Context switch
Save site:
Recovery site:

OS: The provision of virtual computers, which enables the use of limited resources through the "protection" mechanism to allocate multiple simultaneous programs, that is, "process" to achieve the so-called multi-tasking;

Process:
Thread: Tread
Share the resources of the process, such as open files, etc.;
A lighter-weight, individually-scheduled operating unit;

Lwp:light Weight Process

Linux process viewing and management tools: Top, Pstree, PS, Pidof, Pgrep, Pkill, Htop, Glances, Pmap, Vmstat, Dstat, Iostat, SAR, kill, Job, BG, FG

All child processes except Init on Linux systems are made up of their parent process fork (), followed by the cow mechanism, and the process is presented as a "process tree";

Pstree command:
Process tree view;
-P: Shows the PID of each process;

Ps:process State

The information about kernel in Linux running is output by/proc pseudo file system; Each process has a subdirectory named after its PID, and many files in each subdirectory store the related state information of the process;

The display is a snapshot of the current process state information on the system when the PS command executes, so, for static results;

Many options are supported:
BSD Style
SYSV style

Depending on whether the process started interactively from the user interface on the terminal, the process can be divided into two categories:
Terminal-related processes: a
Terminal-independent processes: X

User-centric organization of process status information display: U

Common option Combination 1:axu
USER PID%cpu%MEM VSZ RSS TTY STAT START time COMMAND

Vsz:virtual Memory Size
The amount of space occupied by the linear address space;
RSS: Commonly used in memory sets, refers to the amount of data that can not be exchanged to swap space to occupy space;

STAT: Process Status
R:running, running state;
S:interruptible sleeping, can interrupt sleep
D:uniterruptible sleeping, non-disruptive sleep
t:stopped
Z:zombie

S:session leader
+: Foreground process, occupy a terminal
L: Multithreaded Process
<: high-priority process
N: Low-priority process

Start: Startup time
Time: Occupy CPU cumulative duration
Command: Starts the shell of the current process or thread, [] represents a kernel thread;

Common option Combination 2:-ef
-e: Show All Processes;
-F: Display rich formatting information

Common option Combination 3:-EFH
-F: Show additional information
-H: Show the inter-process relationship in a hierarchical form;

Customizing the information you need to display: Axo
PS Axo Pid,command,psr,pri,ni
PSR: The CPU number of the current process running;
PRI: Priority of the current process;
NI: The nice value of the current process;
-20, 19

Pgrep:
Syntax format: pgrep [OPTIONS] "PATTERN"
-U UID: Displays only the processes running as the specified user;
-G GID
-L: Show PID and process name;

Pidof:
PIDOF Program
Program: Given a command-line procedure

Top command:
There are many interactive sub-commands;
P: Sort by the percentage of CPU occupied;
M: In order to occupy memory space size;
T:CPU cumulative occupancy time sequencing;

L: Whether the system load line is displayed;
Reasonable interval of queue Length: number of CPUs *0.7
T: whether to display the process summary information and CPU load status;
Cpu (s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Us:user Space
Sy:system (kernel space)
Ni:nice
Id:idle
Wa:wait IO
Hi:hardware Interrupt
Si:software Interrupt
St:stolen, percentage of "stolen" by virtual machine
1: Average or separate display of CPU load status;
M: Whether to display memory-related status information;

Q: Exit command
S: Modify the delay length
K: Terminates the specified process

Options for the top command:
-b:batch, Batch Display
-N #: Number of batches displayed
-D #: Indicates how long the delay is

Uptime command: Displays the current system time, the running time, the number of users logged in and the average system load;

Command summary: Pstree, PS, Pgrep, top, uptime, pidof


Review:
Process Management
Task struct: Meta-data information for each process, such as the pid,ppid of the process, thread, files
Task List: Lists of tasks, linked tables

Linear address space for the process:
Text Segment
Data Segment
BSS Segment
Heap
Stack

Process Status:
Ready state, operating state, sleep (interruptible, non-interruptible), stop state, zombie state

Process priority:
Real-time priority
Static priority:
100-139
Dynamic priority

Process View Basic tools: Pstree, PS, top, pidof, pgrep, uptime
Ps:axu,-ef,-EFH, Axo
Top:p,m,t,l,t,m,s,q,k

Linux process View and management (2)

Htop
Interactive commands:
U: Filter only shows the process of the selected user;
S: Tracks the system calls initiated by the selected process;
L: Displays the files opened by the selected process;
T: Displays the hierarchy of processes;
A: Sets the CPU affinity of the process; (binds the selected process to the specified CPU)

Options:
-D #: Delay duration
-U USERNAME: Displays only the process of the specified user;
-S COLUMN: Sorts according to the specified field;

Vmstat command:

Usage: vmsate [delay [count]]

Procs:
R: The number of processes waiting to run; (Queue Length)
B: The number of processes that handle the non-disruptive sleep state (that is, IO blocking queue Length)

Memory
SWPD: Swap memory usage;
Free: The amount of physical memory in space;
Buffer: The total amount of memory used for buffer;
Cache: The total amount of memory used for the cache;

Swap
Si: The rate at which data enters the swap (KB/S)
So: the rate at which data leaves swap (kb/s)

Io
BI: The rate at which data is read from the block device to the system (KB/S)
Bo: The rate at which data is saved to a block device (KB/S)

System
In: Interrupt rate
CS: Rate of process switching

Cpu
us
Sy:
Id:
Wa
St:

Options:
-S: Displays status statistics for memory

/proc/#接口:

Pmap: View the memory mapping relationship of the specified process;
Pmap [OPTIONS] pid ...
-X: Show Extended information

Cat/proc/#/maps

Glances:
glances [-BDEHMNRSVYZ1] [-B bind] [-C Server] [-C conffile] [-P port] [-p password] [--password] [-t refresh] [-f file] [- O Output]

Common options:
-B: Display the data exchange rate of the network card device in BYTE/S;
-D: Turn off the disk I/O function module;
-f/path/to/somefile: Set the location and format of the output file;
-O {html| CSV}:
-M: Turn off the Mount function module
-N: Turn off network function module
-r: Close Process List Function module
-T #: Specifies the length of the delay, which defaults to 3 seconds;
-1: Display each CPU related load data information separately;

Glances supports remote mode:
That can work in C/s mode:
Server: Start glances in listening mode;
Client: Start glances in remote mode, connect to the specified server remotely, and correlate data on server;

Service mode:
Glances-s-B ipaddr
-B: Used to indicate the local address of the listener;

Client mode:
Glances-c ipaddr
-C: The address of the server used for the connection;

Dstat: Integrates the functions of the Vmstat, Iostat, Netstat and ifstat four tools;
Dstat [-AFV] [options:] [Delay [Count]]

-C: Displays statistical data related to CPU performance indicators;
-D: Show disk-related rate data;
-G: Displays page-related rate data;
-I: Show interrupt related rate data;
-L: Displays statistics related to load average;
-M: Display memory related statistics;
-N: Shows the rate of data sent and received by the network;
-P: Displays process-related statistics,
The rate of-r:io requests;
-S: Show data about swap
-Y: Displays system-related data, including interrupts and process switching;

--TOP-CPU: Displays the most CPU-intensive processes;
--top-bio: Shows the process that consumes block IO most;
--top-io: The most IO-intensive process;
--top-mem: Shows the most memory-intensive processes;

--IPC: Shows the rate data related to interprocess communication;
--raw: Displays data related to raw sockets;
--TCP: Displays data related to TCP sockets;
--UDP: Displays data related to UDP sockets;
--unix: Displays statistics related to UNIX sock interfaces;
--socket:

-A:-cdngy

IPC: Inter-process communication
Common forms:
Message Queue
Semerphore
Shared memory
Signal

Signal: Short information passed to a process
Information that is available between processes supported by Linux hosts:
(1) kill-l
(2) Man 7 signal

Signal to process:
Kill [-signal] PID
The default signal is sigterm;

Signal representation:
(1) Full name, e.g. SIGINT
(2) abbreviated name, e.g. int
(3) Data McCartney, e.g. 2
Common signals:
Sighup:1, notifies the process to reread its configuration file for the new configuration to take effect without restarting the process;
Sigint:2, interrupting a running process, equivalent to a keyboard key combination CTRL + C
Sigkill:9, forcibly aborting a running process
Sigterm:15, safely aborting a running process
Sigstop:19, pausing the process
SIGCONT:18, continue running the specified process

Kill a similar set of processes:
Killall [-signal] Program

Command summary: Htop, Vmstat, glances, Dstat, kill, Killall

Job Management:
Front-end operation: Start through the terminal, and will occupy the terminal until it stops;
Background job: When the job starts, it is not related to the terminal, or it is started in the foreground, but it is switched to terminal-independent mode.

How do I get my job running in the background?
1. For jobs that are already up and running:
CTRL + Z

Note: When the job is sent backstage, the default is in stopped state;
2. For jobs that have not been started:
COMMAND &

Note: This two-way related job is still related to the terminal, which means that termination of the terminal will cause all jobs associated with this terminal to be terminated;

The relationship between the stripping process and the terminal:
# Nohup COMMAND &

Job View:

Jobs command
Job number, job status, Startup command-line program

Job Control Commands:
FG [[%]job_num]: The assigned assignment is recalled to the foreground;
BG [[%]job_num]: The designated job in the background to start up, let its background silently run, but this job must support running in the background;
Kill [%job_num]: terminates the specified job;

Process Priority tuning:
Static priority:
The priority is adjusted by specifying the nice value of the process, and the process of user space running generally has its nice value;
Nice value:-20, 19
Priority: 100, 139

When the process is started by default, its nice value is 0 and its priority is 120;

(1) For processes that have not yet started:
# nice-n N COMMAND

(2) for a process that is already up and running:
# renice-n N PID

Note: Ordinary users can only adjust the size of nice, lower priority;

Orders not yet spoken: SAR, Iostat, Ifstat, tsar;

Command summary: Jobs, FG, BG, Nice, Renice

Blog job: The use of process management tools htop/glances/dstat;

9-17 Linux process View and management

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.