Linux process Management--process management related commands

Source: Internet
Author: User
Tags terminates cpu usage pkill

Process-related commands on Linux systems:

To view the class command:

Ps,pstree,pidof,pgrep\pkill,top,htop,glances,dstat,vmstat,pmap

Management class Commands:

Bg,fg,jobs,kill,killall,nohup,nice,renice


Pstree command:

Pstree-display a tree of processes

Show relationships between processes, represented by a tree chart


PS Command:

Ps-report a snapshot of the current processes.

Displays information about the current process;

PS [option]

1 UNIX style; must be added to the front of the option-;

2 BSD style; not available in front of options-;

3 GUN style; There must be two in front of the second option-;


Field Meaning:

User: The owner of the process, the initiator of the process;

PID: A numeric identifier that identifies the uniqueness of the process;

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

%MEM; Percentage of physical memory occupied by the process;

VSZ: Virtual memory set, exchangeable memory set;

RSS: Resident memory set, non-exchangeable memory set;

TTY: Which terminal the process is associated with, "?" is not related to terminal;

STAT:

R operating state; running or runnable (on run queue)

S can interrupt sleep state; interruptible sleep (waiting for a event to complete)

D non-terminal sleep state; uninterruptible sleep (usually IO)

T is stopped during tracking; stopped by debugger during the tracing

T stop Process Control signal; Stopped by job controls signal

X-Dead process; dead (should never be seen)

Z Zombie Process, defunct ("zombie") process, terminated but not reaped by its parent

< high priority; High-priority (not good to other users)

N low priority; Low-priority (Nice-to-other users)

L pages are locked into memory; have pages locked into memories (for real-time and custom IO)

s conversation leader; is a session leader

l multithreading; is multi-threaded (using Clone_thread, like NPTL pthreads do)

+ Pre-process group; are in the foreground process groups

Start: The time stamp at which the process that has not been closed has been opened so far;

Time: The total duration of CPU occupied by the current process;

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


BSD-style options:

A: Display all terminal-related processes;

X: Shows all processes unrelated to the terminal;

U: Displays the user account name of the initiating process;

O Format: Displays the execution results of the PS command in a custom field;


UNIX-style options:

-U: Displays the processes associated with the specified user;

-e: Show All Processes

-F: Displays process information in full format:

PPID: PID of the parent process

C: Percentage of time that represents the CPU consumed by the process


-F: Displays memory information in full format: (several more items)

SZ: Virtual Memory Set

RSS: Resident Memory Set

PSR: Core number of the CPU executing this process


-H: Displays the hierarchy of processes (parent-child relationship)

-O Format: Displays the results of the PS command execution in a custom field;




Pgrep,pkill command

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

Pgrep is the query process

Pkill is killing the process.


pgrep [option] pattern

pkill [option] pattern

-U,--uid: Displays the real user ID of the process

-u: Displays a valid user ID for the process

-T Terminal: Displays the process associated with the specified terminal;

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


Like what:

After I kill my ssh, my x shell is disconnected because the X shell is remotely connected based on the SSH protocol, and I can only restart the SSH process on my virtual machine.

Then, my X shell can connect normally;



Pidof:

Pidof-Find the process ID of a running program.

Finds the process number for which it is based, according to the specified running process name;



Top command:

Top-display Linux Processes


When you enter top in Linux, we will see the dynamic display information: Explain the specific information

First line:

Current system time;

The total length of time the system has been running since the last power outage;

The total number of users currently logged into the system;

In the last 1 minutes, 5 minutes, 15 minutes of three time periods, the CPU waits for the length of the queue of the process to execute.

Second line:

The total number of processes running in the system;

The number of processes that are running;

The number of processes in the sleep state;

The number of processes that have been stopped;

The number of processes in a dead state;

Third line: Statistics on the percentage of CPU time consumed by various processes

Us:user space, the percentage of CPU time consumed by processes in the user space;

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

Ni:nice, the percentage of CPU time that is adjusted after the priority of the process with the nice value;

ID:IDEL,CPU percentage of idle time;

Wa:waiting the percentage of CPU time that the process waits for IO to complete;

Hi:hardware interupting, the percentage of CPU time that handles hardware interrupt event limits;

Si:software interupting, the percentage of CPU time that handles software interrupt event limits;

St:stolen, the percentage of CPU time that is secretly occupied by processes such as virtualization programs;

Line four: Displays the statistics of the usage of the physical memory space in KiB units;

Total: The overall size of the physical memory space;

Free: The size of the idle physical space;

UserD: The size of the physical space that has been used, not recyclable;

Buff/cache: The amount of physical memory used for buffers and buffers; This memory can be recycled at any time, not really consumed;

Row five: Displays statistics on the use of swap space in KiB units;

The total size of the total:swap space;

Free:swap space remaining space size;

Used: the size of the swap space already occupied;

Avail mem: The space size of the real available physical memory;


Interactive commands: (commands that do not take effect until the interface is entered)

1: Show or hide details of CPU cores;

P: The percentage of CPU time is sorted in descending order according to each process;

M: The percentage of physical memory space occupied by each process is sorted in descending order;

T: The percentage of CPU time consumed by each process is sorted in descending order;

L: Show or hide the first line, uptime and other information;

T: Show or hide the second to third line of information

M: Show or hide the fourth to fifth line of information

Q: Exiting the top interactive mode

S: Modify the Refresh time interval of the top command;

K: sends the specified signal to the process of the specified PID;

Signal: Kill-l Query


Common options:

-D #: Specifies the refresh interval in top interactive mode, which defaults to 3 seconds;

-B: Non-interactive display results



Vmstat command:

Procs

R: Number of processes waiting to run

B: Number of processes in non-disruptive sleep state

W: The number of running processes that have been swapped out.

This number is calculated by Linux, but Linux does not run out of swap space


Memory

SWPD: Virtual memory usage, unit: KB

Free: idle memory, in kilobytes

Buff: The amount of memory that is used as a cache, in kilobytes: KB


Swap

Si: Number of swap pages from disk swap to memory, in kb/seconds

o: Number of swap pages from memory swap to disk, in kb/seconds


Io

BI: Number of blocks sent to block device, units: Blocks/sec

Bo: Number of blocks received from a block device, units: Blocks/sec


System

In: Number of interrupts per second, including clock interrupts

CS: The number of environment (context) switches per second


Cpu

Display as a percentage of total CPU usage

Us:cpu Use time

SY:CPU System Usage Time

ID: Idle Time


Common options:

-a,--active: Shows the number of active and inactive memory spaces;

-s,--stats: The information extracted from the/proc/meminfo file, the output after processing;

Delay: Indicates that the VMSTAT command is repeatedly executed at the specified time, and the default unit is seconds;

Count: The number of times the Vmstat command was repeatedly executed;


PMAP command:

Pmap-report memory Map of a process


PMAP [options] pid [...]


-X,--extended: Displays extended information;


Htop-interactive Process Viewer


Htop [-DCHUSV]

Common options:

-d--delay=delay:htop Command data refresh time interval;

-S: Sort according to the specified field;

-U: Displays only the processes owned by the specified user;


Common Interactive Commands:

L: Displays a list of all open files specified;

T: Show the process tree structure, can show the process of the parent-child relationship, equivalent to the function of the F5 key;

A: Set the CPU affinity of the process, bind the selected process to a CPU core to run;



Glances:

Glances-a cross-platform curses-based Monitoring Tool


glances [-bdmn] [-t refresh] [-f file] [-O output]


Common options:

-B: Displays the data communication rate of the NIC in bytes, by default, bits per second;

-D: Disable disk I/O module;

-M: Disables the Mount module;

-N: Disable the network module;

-T refresh: Specifies the data refresh time interval in seconds;

-f/path/to/output_dir: Specifies the path of the output file;

-o {html| CSV}: Specifies the data format for data output to a file;

-S: The glances process is used as a service process, so it can provide network access based on sockets;

-B @IP | HOST: Binds the glances process to the specified IP address and is usually used with the-s option;


Glances can work in the C/S model;

S: Server mode

# glances-s-B ipaddr


ipaddr refers to a locally available IP address on the server;


C: Client mode

# glances-c SERVER_IPADDR


server_ipaddr refers to the IP address of the target server from which the remote client originated the connection;

Glances interactive operation command;

B: Rate statistics in the network module are switched between BPS and bps;

C: Process sequencing based on CPU utilization;

m: Process sequencing based on memory usage;

N: Hide or show the Nerwork module;

D: Hide or show disk module;

F: Hide or show the file module;

T: Restore default process sequencing;

H: Display Help information;

....


Dstat

Dstat-versatile tool for generating system resource statistics


Stat [-AFV] [options:] [Delay [Count]]


Common options:

-c,--cpu: Displays only CPU-related statistics;

-d,--disk: Displays only statistics related to IO devices such as disks;

-g,--page: Displays only information related to the page;

-n,--net: Displays only statistics related to the network interface;

-s,--swap: Displays only statistics related to the swap partition;

-y,--system: Displays only statistics related to the system;

--tcp: Displays only statistics related to the connection status of the TCP protocol;

--udp: Displays only statistics related to the connection status of the UDP protocol;


Kill

Kill-Terminates the process


Kill [-S signal|-p] [--] pid ...


Kill-l [signal]: View the types and signal names of the signals supported in the current system;


Valid signal representation method:

1. Use the digital encoding of the signal for signal representation;

2. Use the full name of the signal for signal representation;

3. Use the abbreviated name of the signal for signal representation; The abbreviated name does not contain the remainder of the SIG;


Commonly used signals:

1) SIGHUP: No need to close the corresponding process and let it re-read its own configuration file;

2) SIGINT: Terminate the process running in the foreground, using CTRL + C key combination, you can send this signal;

9) SIGKILL: There is no warning to terminate the running process, all the resources occupied by the process will not be recovered immediately;

Sigterm:kill commands the signal sent by default, terminates the operation of the process,

Sigcont: Let the process in the background continue to run in the background;

SIGSTOP: Let the process in the background stop running in the background;

Killall

Killall-Kill the process by name


killall [Options] ... Procrss_name.


Common options:

-U: Sends a signal only to processes owned by the specified owner;

-S: sends a specified non-sigterm signal to the process of the specified name;

-I: Ignores the difference in the case of process names;


Process jobs:

Front Desk jobs:

foreground jobs, which is usually initiated through the terminal and occupies the terminal after the start-up process;


Background jobs:

Background jobs, the general system starts with the system boot, can also be started through the terminal, but after starting to understand the release of the use of the terminal, at this time we call it "background operation";


To move a process from the foreground to the background:

1. The running foreground job;

Ctrl + Z

2. For processes that have not yet started, make them automatically go back to the background after startup:

# COMMAND &

Note: This class is initiated directly from the foreground to the process running in the background, and is always a terminal-related process, so if the terminal is shut down, or the shell process is terminated, such processes will also be terminated;

3. For a process that has not yet started, it automatically goes back to the backend after start-up, and at the same time stripping its associated relationship with the terminal;

# nohup COMMAND &


To view information about a background job:

Jobs



Move the background job into the foreground to run:

FG [JOB_ID]

Note: If job_id is omitted, the job identified with "+" in the background process will be transferred to the foreground;


To terminate a background process job:

Kill%job_id: End the background job;

A command that adjusts the priority of a process;

Nice,renice


Priority of the process:

0-139

0

1-99

100-139: Dynamic priority; Change the process's dynamic priority by adjusting the nice value of the process;

Value range for nice values: -20~19


By default, all user processes have a dynamic priority of 120, and the nice value of all processes defaults to 0;


Only Superuser root can use the attached nice value, thereby increasing the priority of the process, and the average user can only use the nice value of positive numbers, thus reducing the priority of the process;


Nice

Nice-run a program with modified scheduling priority


Nice [OPTION] [COMMAND [ARG] ...]


-N: Adjusts the nice value for the subsequent process; default is 10;




Renice

Renice-alter priority of running processes


Renice [-N] Priority [-GPU] identifier ...


Common options:

-N Priority: Set the nice value to be adjusted, i.e. append the number specified here above the original nice value;

-P PID:




Linux process Management--process management related commands

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.