I. Overview of the process
1. Documents
file: a marked storage space on a disk, essentially a stream of data, called a file name
The file name can refer to this piece of data
file storage format :
Binary format:
Text Format (ASCII code):
executable : Unique elf format, the first few bytes identify the format of the file,
2. Procedures and processes
program = instruction + data = algorithm + structure
a process is a copy of a program , you can have multiple
Each process is unaware of the existence of another process, thinking that only itself and the kernel occupy the entire memory
Process start-up and dispatch are kernel-completed
Linear address Space (virtual memory): The kernel has a virtual memory space for each process,
Page frame: Memory leaf box,
Init is the parent process for all processes
The parent process generates child processes through fork (),
each process has a task structure : Task_struct, save the various information of the process, the kernel can trace the process
Kernel tracing process: Two-way loop linked list
Thread: Is the execution flow of the process, can share the resources, the thread is implemented by the line libraries,
Linux Single core: No dedicated thread management tool, also as process, lightweight process
3. Process scheduling
mode switching: user mode (normal instruction), kernel mode (Privileged command)
Process Switching: clock driver, clock interrupt
Process scheduling: process priority,
140 queues, representing priority, 0-139,
Real-time Priority: 1-99, the higher the number, the higher the priority level
Static priority: 100-139:nice value adjustment, the higher the number, the lower the priority
Dynamic priority: maintained by the kernel, dynamically adjusted
Process classification:
CPU-Intensive
IO-intensive
Status of the process:
Operating state: Running
Sleep state: Sleeping
Interrupted sleep: interuptible
Non-terminal sleep: uninteruptible, blocked by IO
Ready state: Runnable
Stop state: Stopped, cannot be scheduled and run
Zombie State: Zombie, no parent process
All child processes except init on a Linux system are made by the parent process fork () itself, followed by the cow mechanism, and the process is presented as a "process tree"
Linux running kernel information is output through the/proc pseudo-file system, each process has a sub-directory named after its PID, each subdirectory has many files stored the process related state information
Linux process viewing and management tools:
Pstree,ps,pidof,pgrep,top,htop,glances,pmap,vmstat,dstat,iostat
Kill,killall
Pstree command:
Process tree view:
-P: and show PID for each process
PS: Command
A snapshot of the current process state information is displayed, as a static result
$ps
:
Ps
Explanation: By default, the PS command displays only the processes that are part of the current user and are running in the current terminal. Default PS, only run bash and PS
$ps –ef
Many options are supported:
BSD style: No "-" before option
SYSV style
User-centric organization of process status information display: U
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
Common option combinations: 1:axu
USER PID%cpu%MEM VSZ RSS TTY STAT START time Comman Process The main process number occupies percent of CPU memory percent The start time occupies the CPU cumulative time the command that starts the current process, [] represents the kernel thread
VSZ: 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;
TTY: Terminal
STAT: Process Status
R: Run
S:interruptible sleeping, can interrupt sleep
D:uniterruptible sleeping, non-disruptive sleep
t:stopped stop
Z:zombie Zombie
S:session leader Process leader
+: Foreground process, occupy a terminal
L: Multithreaded Process
<: high-priority process
N: Low-priority process
Common option Combination 2:-ef ppid: Parent Process number
-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
3, Pgrep:
Syntax format: pgrep [OPTIONS] "PATTERN"
-U UID: Displays only the process number that is running as the specified user, and the user name or UID can be connected
-G GID
-L: Show PID and process name;
4. Pidof: Displays the PID initiated by the specified command
PIDOF Program
Program: Given a command-line procedure
5. Top command:
Top is a dynamic display process where the current state can be refreshed continuously with the user key. If the command is executed in the foreground, it will monopolize the foreground until the user terminates the program. More accurately, the top command provides real-time status monitoring of the system's processor. It will display the most "sensitive" CPU in the system. Task List. This command can be used by CPU. Memory usage and execution time to sort tasks, and many of the features of the command can be set through interactive commands or in personal customization files.
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; the 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 the percentage of CPU that processes that have changed priority
Id:idle Idle
Wa:wait IO
Hi:hardware Interrupt Hardware Interrupt
Si:software Interrupt
St:stolen, percentage of "stolen" by virtual machine
1: Whether the load status is displayed;
T: whether to display CPU and process statistics
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;
6, 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;
#: Quickly position the cursor on the specified PID process
7, Vmstat
procs-----------Memory-------------Swap-------io------System-------CPU-----
R b swpd free buff cache si so bi bo in CS us sy ID WA St
0 0 0 657680 23308 191544 0 0 8 2 15 21 0 0 99 0 0
Procs
R: The number of processes running or waiting for CPU time slices
B: The length of the process that is blocked (typically waiting for I/O completion)
Memory
SWPD: The amount of data that interacts from physical memory to swap
Free: Unused memory size
Buffer:buffer space size, usually related to cache write operations
Cache:cache space size, usually related to cache read operations
Swap
The amount of data that si:swap in data enters the swap, usually the rate. kb/s
The amount of data that so:swap out data from swap, usually the rate. kb/s
Io:
Bi:block in: The amount of data read from a block device, usually the rate, kb/s
Bo:block out: The amount of data saved to a block device, usually the rate, kb/s
In: Frequency of interrupt occurrence. Number of interrupts per second
Cs:context switch Context switch, process switch, usually rate, kb/s
Cpu:
US: Utilization of user space
SY: Usage of kernel space
ID: Idle
WA: Process queue to be run
ST: Stolen
Use formatting
Vmstat [delay [counts]]
Time-lapse refresh refresh several times
-S: Show memory statistics
Vmstat 1
Vmstat 1 3
8, Dstat: Integration of Vmstat, Iostat, Netstat and ifstat four tools of the function;
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
9, Pmap: View the memory mapping relationship of the specified process;
Pmap [OPTIONS] pid ...
-X: Show Extended information
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;
Killall-signal Process Name
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 abort a running process, kill the signal used by default
Sigstop:19, pausing the process
SIGCONT:18, continue running the specified process
Second, the operation
1. Operation 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: After 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;
3, the relationship between the stripping process and the terminal:
Nohup COMMAND &
2. Job View
Jobs
Job number, job status, Startup command-line program
Jobs can display the status of the jobs that are started in the current shell environment.
When using Linux, often encounter similar situations, copy, download a large file or edit a file, the task occupies the interface can not do other operations, this time to do not pause or abort the task to do other operations can be executed to the background to run the command.
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;
3, Process priority adjustment:
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;
Linux kick-out user command (Pkill)
1. Kick the user out of a terminal
Pkill-kill-t PTS/2 (terminal number) or pkill-9-T PTS/2
2. Kick the user by user name
Pkill-kill-u Test (System user name)
"Linux Fundamentals" 18, Process management