Linux process and job management related commands

Source: Internet
Author: User
Tags terminates cpu usage

As a beginner, Linux is always so mysterious, tall on the content I will not, so here can only tidy up the management-related commands, if there is wrong or inaccurate place, please correct me.

Refer to: Linux kernel--process management and scheduling http://www.linuxidc.com/Linux/2014-08/105366.htm

Pstree: Show process status tree

Role: Lists the current processes, as well as their tree-like structure

Usage: pstree [options]

    • -A: Shows the command and full parameters of the executing program

PS: View the status of processes in the system

The/proc/directory contains the pseudo-files generated by the process and kernel simulations, where each process uses its own PID to name the directory, and the directory contains each parameter that the process runs.

Kernel parameters in the/proc/sys/directory, you can set their values to dynamically adjust the characteristics of the kernel running.

Usage: PS [options]

Options available in three different styles

1 UNIX options, which may grouped and must is preceded by a dash.

2 BSD options, which may is grouped and must not being used with a dash.

3 GNU long options, which is preceded by and dashes.

one of the common options combinations:

# Pstree aux

    • A: All terminal-related processes

    • x: All processes unrelated to the terminal

    • U: Display of process status information in user-centric organization

Show field Meaning:

User indicates who the process is running as

PID indicates the process number

%CPU indicates CPU utilization percentage

%MEM represents the percentage of physical memory consumed

VSZ represents the virtual memory set size, which contains the shared data space

RSS represents the size of a resident memory set, located in physical memory, and cannot be swapped out

TTY indicates which terminal this process starts from, question mark? Represents a process that is not related to a terminal

STAT indicates process status

R:running

S:interruptable sleeping

D:uninterruptable sleeping

t:stopped

Z:zombie

+: Foreground process

L: Multithreaded Process

N: Low-priority process, which generally indicates that the process priority value is negative

<: high-priority process

S:session leader

Start indicates the process start time

Time indicates the cumulative CPU consumption

command indicates which commands are started with the kernel thread in brackets

Two common combinations of options:

# PSTREE–EF

    • -e: Show All Processes

    • -F: Show process information in full format

Partial field Meaning:

PPID represents the parent process number of this process

C indicates the percentage of CPU occupied

Three common option combinations:

# PS–EFH

    • -F: Show process information in full format

    • -H: Displays information about the process in a hierarchical structure

Partial field Meaning:

SZ represents the virtual memory set size, which contains the shared data space

PSR indicates which CPU this process is running on

Four common option combinations:

# Ps–eo <field1,field2,... >

Or

# PS Axo <field1,field2,... >

    • o field1,field2,...: Customize the list of fields to display, separated by commas

Commonly used Field:pid, Ni, pri, PSR, PCPU, stat, comm, TTY, Ppid, Rtprio

Ni:nice value

Pri:priority Priority level

Rtprio:real Time Priority

Utilization of PCPU:CPU

Pgrep: Finding the process for matching criteria

Usage: pgrep [options] Pattern

    • -U uid:effective User

    • -U uid:read User

    • -T TERMINAL: Processes associated with the specified terminal

    • -L: Show process name

    • -A: Displays the process name in full format

    • -P PID: Show child processes for this process

Pidof: According to the process name, take its PID

[Email protected] ~]# pidof sshd
3987 2368 1062

Uptime: Display system time, number of user logins, runtime, and average load

[Email protected] ~]# uptime
00:06:21 up 7:12, 2 users, load average:0.00, 0.01, 0.05

Load average: The average load that waits for the length of the process queue to run in the last 1 minutes, 5 minutes, and 15 minutes

Top: Displays the current process status of the system

Usage:

# top-d 2: Specifies a 2-second delay time to refresh the display, in seconds

# Top-b: Batch Mode

# top-bn 2: In batch mode, total 2 batches are displayed

Display meaning:

The first line of information is what the uptime command displays

The second line shows the number of processes that are started, currently running, suspended (sleeping), and useless (Zombie)

The third number shows the current usage of the CPU, followed by

US User usage ratio

SY system occupies a specific column

Percentage of extra time after NI adjustment

ID Idle (idle) scale

WA waits for IO to complete the percentage occupied

Hi processing percent of hardware interrupt consumption

Si processing% of software interrupt consumption

The percentage of St that is divided by virtualization technology on the current host

Row four shows the use of physical memory, including the total amount of memory that can be used, free memory, used memory, Buff/cache occupied memory

Buffers and cached are memory operations that are used to save files and file attribute information that have been opened by the system, so that when the operating system needs to read some files, it will first look in the buffers and cached memory areas, and if found, read them directly to the application. If no data is found, it will be read from disk.
Buffers is used to buffer the block device, it only records the file system metadata (metadata) and tracking in-flightpages, and cached is used to buffer the file. More commonly said: buffers is mainly used to store content in the directory, file attributes and permissions and so on. and cached is used directly to memorize the files and programs we have opened.

Row five shows the usage of the swap partition, including total, idle, used, and available memory space 650) this.width=650; "class=" Wlemoticon Wlemoticon-nyahnyah "style=" Border-top-style:none;border-bottom-style:none;border-right-style:none;border-left-style:none, "alt=" Spit The Tongue "src=" Http://s3.51cto.com/wyfs02/M00/78/94/wKioL1Z_y0aiRRRkAAAEKlXprTU050.png "/>

Line six shows the following items:


PID: Process Number

USER: Process Owner

PR: Priority level of the process

Ni:nice value 650) this.width=650; "class=" Wlemoticon wlemoticon-winkingsmile "style=" border-top-style:none; Border-bottom-style:none;border-right-style:none;border-left-style:none; "alt=" Blink "src=" http://s3.51cto.com/ Wyfs02/m00/78/94/wkiol1z_y0ficstgaaaeb3c_r5k770.png "/>

VIRT: Virtual memory value for process consumption

RES: The physical memory value that the process occupies

SHR: Shared memory value for process consumption

S: Status of the process, see PS command

%CPU: CPU usage consumed by this process

%MEM: The percentage of physical memory that the process occupies

Time+: The length of time to run on the CPU after the process starts

Command: Startup commands for process startup


In the process of using the top command, you can also use some interactive commands to accomplish other functions, using the following shortcut keys:

M: Sort based on the size of the resident memory

P: Sort by CPU percent usage

T: Sort by cumulative time

L: Show average load and start time

T: whether to display process and CPU status related information

M: whether memory-related information is displayed

C: Whether to display full command line information

S: Modify Refresh time interval

< space bar;: Refresh Now

K: Terminates the specified process

Q: Exit Top

Htop: System Status Display

Htop is an upgrade command on the function of the top command, so the display and usage of the two are similar, but the htop command needs to be installed manually, and there is no installation package on the release CD, which needs to be obtained by other means, it is recommended to install 650 with Yum pointing to the Epel source) this.width=650, "class=" Wlemoticon wlemoticon-turtle "style=" border-top-style:none;border-bottom-style:none; Border-right-style:none;border-left-style:none, "alt=" turtle "src=" http://s3.51cto.com/wyfs02/M01/78/95/wKiom1Z_ Yy7bwcvlaaaes1flgm0834.png "/>

The htop is powerful, supports mouse operation, displays project content similar to the top command, and only says its interactive commands


U: Show only the process of the specified user

S: Displayed in the specified field

L: Displays the list of files opened by the selected process

S: Track system calls for selected processes

T: Show the status of each process in a hierarchical relationship

A: Binds the selected process to a specified CPU core

More help press F1 key to get

Vmstat: Reporting Virtual memory statistics

Usage: vmstat [options] [delay [count]]

# vmstat 2 5//5-second acquisition, total acquisition 5 times

    • -S: Show memory-related statistics

    • -D: Display disk-related statistics

    • -s:switches outputs between (k), 1024x768 (k), 1000000 (m), or 1048576 (m) bytes. Note This does not a change of the swap (SI/SO) or block (Bi/bo) fields.

Show field Meaning:

------procs------

R: The number of processes waiting to run; the queue length of the task waiting to run on the CPU
B: The number of processes in the non-disruptive sleep state; the length of the blocked task queue


------Memory------
SWPD: Total swap memory usage;
Free: The total amount of physical memory available;
Buffer: The total amount of memory used for buffer;
Cache: The total amount of memory used for the cache;

------Swap------
SI: Data rate for data entry into swap (KB/S)
So: the rate at which data leaves swap (kb/s)


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

------system------
In:interrupts, Interrupt rate
Cs:context switch, the rate of context switching


------CPU------

Us:user Space
Sy:system
Id:idle
Wa:wait
St:stolen

If Bi and Bo are not equal to 0 for a long time, it means that the physical memory is too small

PMAP reporting Process Memory mapping table

Usage: pmap [options] pid [...]
-X: Display detailed format information

Another way to view: Cat/proc/pid/maps

Kill

-terminate a process

Role: Used to send signals to a process for management of the process

Show current system available signals:

# kill–l

There are three ways to identify each signal:
1) Digital identification of the signal
2) Full name of the signal
3) abbreviated name of the signal

Signal to process:

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

Common signals:
1) SIGHUP: No need to close the process and let it reread the configuration file
2) SIGINT: Terminates the running process, which is equivalent to CTRL + C
9) SIGKILL: Kill the Running process
SIGTERM: Terminating a running process
) Sigcont
SIGSTOP)

Killall

-kill processes by name

# killall [-signal] Program

Jobs


Front-end operation (Foregroud): Starts with terminal and occupies terminal after startup
Background Job (Backgroud): Can be started through the terminal, but after the boot into the background to run (release terminal)

How do I get my job running in the background?
(1) Operations in operation
CTRL + Z

Note: After sending to the backstage, the job will be switched to a stop state;
(2) Jobs that have not been started
# COMMAND &

Note: While this type of job is sent backstage, it is still relevant to the terminal, if you want to take the jobs sent back to the backend with the terminal relationship:
# Nohup COMMAND &

To view all jobs:
# jobs

Common commands to implement job control:
# FG [[%]job_num]: Bring the assigned job back to the foreground
# BG [[%]job_num]: Allow jobs sent to the background to continue running in the background
# Kill%job_num: Terminates the specified job


Nice: Change the priority level

0-139 priority, the smaller the number, the higher the priority

100-139: Users can control

0-99: Kernel-tuned


High priority can:

1. Get more CPU Run time

2, more preferential access to operational opportunities


Priority ranges that can be adjusted with the nice value: 100-139

The nice values correspond to:-20, 19, respectively


When the process starts, its nice value defaults to 0 and its priority is 120

Nice value: the smaller the number, the higher the priority level

Ordinary users can only adjust the nice value of their own process

Only administrators can adjust the nice value down

Starts and runs the command with the specified nice value
# Nice [OPTION] [COMMAND [ARGU] ...]
Option:-N Nice
# nice–n 1 ls > 1.txt

Renice

Allow users to modify the priority of a running process

# Renice [-n] Nice PID ...

View nice values and priorities:
# PS Axo pid, NI, priority, comm

Linux process and job 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.