Linux Process Management commands

Source: Internet
Author: User
Tags pkill

Linux Process Management commands

Process-related commands on Linux:

View class commands:

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

Management commands:

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

Pstree command:

Pstree-display a tree of processes

Displays the relationship between processes, represented in 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 before the option -;

2 BSD style; there cannot be-at the front of the option -;

3 GUN style; the front side must have two -;

Field description:

USER: owner of the process; initiator of the process;

PID: A unique digital identifier that identifies a process;

CPU: the percentage of CPU processing time that a process occupies during execution;

% MEM; percentage of physical memory occupied by processes;

VSZ: Virtual Memory set, swap memory set;

RSS: resident memory set, not swap memory set;

TTY: Which terminal is associated with the process ,"? "Indicates it has nothing to do with the terminal;

STAT:

R running status; running or runnable (on run queue)
S can interrupt the sleep state; interruptible sleep (waiting for an event to complete)
D is not terminal sleep; uninterruptible sleep (usually IO)
T is stopped during tracking; stopped by debugger during the tracing
T stop the process control signal; stopped by job control signal
X dead processes; dead (shocould never be seen)
Z botnets; defunct ("zombie") process, terminated but not reaped by its parent
<High priority; high-priority (not nice to other users)
N low priority; low-priority (nice to other users)
L whether the page is locked into the memory; has pages locked into memory (for real-time and custom IO)
S session leader; is a session leader
L multithreading; is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
+ Pre-process group; is in the foreground process group

START: the START timestamp of a process that has not been terminated;

TIME: The total CPU usage of the current process;

COMMAND: the COMMAND line parameter for starting the process;

BSD style options:

A: displays all terminal-related processes;

X: displays all processes unrelated to the terminal;

U: displays the name of the user account that initiated the process;

O format: displays the execution result of the ps command with a custom field;

UNIX-style options:

-U: displays processes related to the specified user;

-E: displays all processes.

-F: displays process information in the complete format:

PPID: pid of the parent process

C: The percentage of CPU time occupied by the Process

-F: displays memory information in the complete format: (A few more items are added)

SZ: Virtual Memory set

RSS: resident memory set

This is the core number of the CPU that executes this process.

-H: displays the process hierarchy (parent-child relationship)

-O format: displays the execution result of the ps command with 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 used to kill a process.

Pgrep [option] pattern

Pkill [option] pattern

-U, -- uid: displays the real User ID of the process.

-U: displays the valid user ID of a process.

-T terminal: displays the processes associated with the specified terminal;

-A: displays the complete command line parameters of a process;

For example:

After I kill my ssh, my X shell is disconnected because X shell is remotely connected Based on the ssh protocol, I can only restart the ssh process on my VM;

Then, my X shell can be connected normally;

Pidof:

Pidof -- find the process ID of a running program.

Find the corresponding process id based on the name of the running process;

Top command:

Top-display Linux processes

When top is input in linux, we will see the dynamic display information: Explain the specific information

The first line:

Current system time;

The total duration of the system operation since the last power-off;

Total number of users currently logged on to the system;

The length of the queue of processes waiting for execution on the CPU in the past 1 minute, 5 minutes, and 15 minutes.

Row 2:

The total number of processes running in the system;

Number of running processes;

Number of sleeping Processes;

Number of stopped processes;

Number of dead processes;

Row 3: statistical information on the percentage of CPU time used by various processes

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

Sy: system, percentage of CPU time occupied by kernel processes in kernel space;

Ni: nice. The percentage of extra CPU time after the process priority is adjusted using the nice value;

Id: idel, percentage of CPU idle time;

Wa: waiting, percentage of CPU time occupied by processes waiting for IO completion;

Hi: hardware interupting, percentage of CPU time limit for handling hardware interruption events;

Si: software interupting, percentage of CPU time limit for handling software interrupt events;

St: stolen, percentage of CPU time secretly occupied by virtualization programs and other processes;

Row 4: displays statistics on the usage of physical memory space in kib units;

Total: the total size of the physical memory;

Free: The size of idle physical space;

Userd: the size of the used physical space, which cannot be recycled;

Buff/cache: the size of the physical memory used in the buffer zone and the buffer zone. This memory can be recycled at any time and is not actually consumed;

Row 5: displays the usage statistics of swap space in kib;

Total: the total size of swap space;

Free: The remaining size of swap space;

Used: the occupied swap space;

Avail mem: the actual available physical memory space;

Interactive command: (a command that takes effect after entering the interface)

1: displays or hides detailed information about each CPU core;

P: sort the CPU usage percentage of each process in descending order;

M: sort the percentage of physical memory space occupied by each process in descending order;

T: sort the percentage of CPU time used by each process in descending order;

L: displays or hides information such as the first line and uptime;

T: displays or hides the second and third rows of information.

M: displays or hides the fourth and fifth rows of information.

Q: exit the top interactive mode.

S: Modify the refresh interval of the top command;

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

Signal: kill-l Query

Common options:

-D #: Specifies the Refresh Interval in top interactive mode. The default value is 3 seconds;

-B: non-interactive display result

Vmstat command:

Procs

R: Number of processes awaiting running

B: Number of non-interrupted sleep Processes

W: Number of processes that can be switched out.

This number is calculated by linux, but linux does not exhaust swap space.

Memory

Swpd: virtual memory usage, in KB

Free: idle memory, in KB

Buff: the number of memories used as cache. Unit: KB

Swap

Si: Number of swap pages from disk swap to memory, measured in KB/second

O: the number of pages switched from memory to disk. Unit: KB/second

IO

Bi: number of blocks sent to block devices. Unit: block/second

Bo: number of blocks received from the block device. Unit: block/second

System

In: The number of interrupts per second, including clock interruptions.

Cs: Number of environment (context) switches per second

CPU

Display by CPU usage percentage

Us: CPU usage time

Sy: CPU system usage time

Id: idle time

Common options:

-A, -- active: displays the number of active and inactive Memory Spaces;

-S, -- stats: information extracted from the/proc/meminfo file, which is output after processing;

Delay: Indicates repeated execution of the vmstat command at the specified time. The default unit is seconds;

Count: the number of times the vmstat command is repeatedly executed;

Pmap command:

Pmap-report memory map of a process

Pmap [options] pid [...]

-X, -- extended: displays extension information;

Htop-interactive process viewer

Htop [-dChusv]

Common options:

-D -- delay = DELAY: interval of data refresh for the htop command;

-S: sort by specified fields;

-U: Only processes owned by the specified user are displayed;

Common interactive commands:

L: displays the list of all opened files;

T: displays the process tree structure, showing the parent-child relationship between processes; equivalent to the F5 key function;

A: Set the CPU affinity of the process and bind the selected process to a CPU Core for running;

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 network adapter in bytes. The default value is bits per second;

-D: Disable the disk I/O module;

-M: Disable the mount module;

-N: Disable the network module;

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

-F/PATH/TO/OUTPUT_DIR: Specifies the PATH of the output file;

-O {HTML | CSV}: Specifies the data format for the data output to the file;

-S: uses the glances process as a service process, so it can provide socket-based network access;

-B @ IP | HOST: binds the glances process to a specified IP address. It is usually used with the-s option;

Glances can work under the C/S model;

S: Server Mode

# Glances-s-B IPADDR

IPADDR refers to a local available IP address on the server;

C: client Mode

# Glances-c SERVER_IPADDR

SERVER_IPADDR refers to the IP address of the target server that initiates the connection from the remote client;

Glances Interactive Operation Command;

B: The rate statistics in the network module are switched between bps and Bps;

C: Process sorting based on CPU usage;

M: Process sorting based on memory usage;

N: hides or displays the NERWORK module;

D: Hide or display the DISK module;

F: Hide or display the FILE module;

T: Restore the default Process Order;

H: displays help information;

....

Dstat:

Dstat-versatile tool for generating system resource statistics

Stat [-afv] [options...] [delay [count]

Common options:

-C, -- cpu: Only CPU-related statistics are displayed;

-D, -- disk: Only displays statistics related to IO devices such as disks;

-G, -- page: displays only page-related information;

-N, -- net: Only displays statistics related to network interfaces;

-S, -- swap: only displays statistics related to swap partitions;

-Y, -- system: displays only system-related statistics;

-- Tcp: Only displays statistics related to the TCP connection status;

-- Udp: Only displays statistics related to the connection status of the UDP protocol;

Kill:

Kill-terminate a process

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

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

Valid Signal Representation Method:

1. Use the digital code of the signal to represent the signal;

2. Use the complete name of the signal to represent the signal;

3. Use the abbreviated name of the signal to represent the signal. The abbreviated name does not include the rest of "SIG;

Common signals:

1) SIGHUP: directly re-read its configuration file without shutting down the corresponding process;

2) SIGINT: stops the process running on the foreground. use Ctrl + c to send this signal;

9) SIGKILL: no warning is given to terminate a running process. All resources occupied by the process are not immediately recycled;

15) SIGTERM: indicates the signal sent by the kill command by default. processes are terminated,

18) SIGCONT: Let the process transferred to the background continue to run in the background;

19) SIGSTOP: stop the process transferred to the background in the background;

Killall

Killall-kill a process by name

Killall [options]... PROCRSS_NAME ..

Common options:

-U: only sends signals to processes owned by the specified owner;

-S: sends the specified non-SIGTERM signal to the process with the specified name;

-I: ignore the differences in Case sensitivity between process names;

Process job:

Foreground job:

Foreground jobs is generally a process that is started through a terminal and occupies the terminal after it is started;

Background job:

Background jobs. Generally, when the system is started, it can also be started through the terminal. However, after the system is started, we understand the occupation of the terminal. In this case, we call it "background running ";

Transfer the process from the foreground to the background:

1. A running foreground job;

Ctrl + z

2. for a process that has not been started, make it automatically transferred to the background after startup:

# COMMAND &

Note: This type of process that is directly transferred from the foreground to the background for running is always a terminal-related process. Therefore, if the terminal is closed or the shell process is terminated, such processes will also be terminated;

3. for a process that has not been started, enable it to be automatically transferred to the background after startup, and at the same time strip its relationship with the terminal;

# Nohup COMMAND &

View the background job information:

Jobs

Transfer background jobs to the foreground to run:

Fg [JOB_ID]

NOTE: If JOB_ID is omitted, jobs marked with "+" in the background process will be transferred to the foreground;

Terminate a background process job:

Kill % JOB_ID: end the background job;

Command to adjust the process priority;

Nice, renice

Process Priority:

0-139

0

1-99

100-139: dynamic priority. The dynamic priority of a process is changed by adjusting the nice value of the process;

NICE value range:-20 ~ 19

By default, the dynamic priority of all user processes is 120, and the NICE value of all processes is 0 by default;

Only the Super User root can use the affiliated NICE value to increase the priority of the process. Normal users can only use the positive NICE value, thus reducing the priority of the process;

Nice

Nice-run a program with modified scheduling priority

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

-N: Adjust the nice value for subsequent processes. The default value 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 this time. That is, the number specified here is appended to the original nice value;

-P pid:

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151483.htm

Related Article

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.