The 12th Chapter Linux System Management

Source: Internet
Author: User
Tags pkill dmesg

1. Process Management

1.1 Process View

(1) Process Introduction

A process is a program or command that is executing ( such as the LS command is also a process ), and each process is a running entity that has its own address space and consumes a certain amount of system resources.

(2) Role of process management

  ① Determine server health status

② viewing all processes in the system

③ Kill Process

(3) View all processes in the system

  #ps The BSD format of the AUX//Unix operating system, where a represents all foreground, x represents the background process, and U represents the user who created the process.

  #ps-le //using the Linux Standard command format, where L is the details and E represents all processes

①user: Which user generated the process.

②pid: ID number of the process

③%CPU: The process consumes a percentage of CPU resources, the higher the consumption, the more resources the process consumes

④&MEM: The process consumes a percentage of physical memory, and the higher the process, the more resources it consumes

⑤vsz: The size of the virtual memory that the process occupies, in kilobytes

⑥rss: The process consumes the actual physical memory size, in kilobytes

⑦tty: Which terminal the process is running on. The TTY1-TTY7 represents the local console terminal, Tty1-tty67 is the local character interface terminal, Tty7 is a graphics terminal. PTS/0-255 represents a virtual terminal.

⑧stat: Process state. Common states are: R-run; s-sleep; t-stop state; s-contains child processes; + + is in the background.

⑨start,time: Process start time and CPU-intensive operation time.

⑩command: The name of the command that generated this process.

(4) View the health status of the system :#top [ options] // Windows-like Task Manager

① One of the options: "-D seconds" to specify that the top command is updated every few seconds. Default is 3 seconds

② commands that can be executed in the interactive mode of the top command

Command

Role

? or h

Show Help for interactive mode

P

Sort by CPU usage, which is the default

M

Sort by use of memory

N

Sort by PID

Q

Exit Top

Information displayed by ③top

Number of rows

Content

Description

Line 1th

Task Queue Information

12:02:46

System Current Time

Up min

The operating time of the system, the machine has been running for 45 minutes

1 Users

1 users are currently logged in

Load Average:

0.03,0.04,0.05

The system has an average load of 1 minutes, 5 minutes, and 15 minutes before. Less than 1 is generally considered to indicate a small load. If it is greater than 1, the system has already exceeded the load.

Line 2nd

(Process information)

tasks:84 Total

Total number of processes in the system

1 Running

Number of processes that are running

Sleeping

The process of sleep

0 stopped

Processes that are stopping

0 Zombie

Zombie process. If not 0, you need to manually check the zombie process

Line 3rd

CPU Information

Cpus (s): 0.0%us

Percentage of CPU consumed by user mode

0.0%sy

Percentage of CPU consumed by system mode

0.0%ni

Percentage of CPU consumed by user processes that have changed precedence

99.7%id

Percentage of idle CPU

0.0%wa

CPU percent waiting for input/output process

0.0%hi

Percentage of CPU consumed by the hard interrupt request service

0.3%si

Percentage of CPU consumed by soft interrupt request Service

0.0%st

The St (steal Time) virtual percentage. is the percentage of time that the virtual CPU waits for the actual CPU when there is a virtual machine

Line 4th

Physical Memory Information

mem:103034k Total

Total amount of physical memory, in kilobytes

128148k used

The amount of physical memory that has been used

902196k Free

Amount of free physical memory

13680k buffers

Amount of memory as buffered

Line 5th

Exchange partition (Swap) information

swap:1023996k Total

Total size of swap partition (virtual memory)

0k used

Size of the swap partition that has been used

1023996k Free

Size of the idle swap partition

37772k Cached

The size of the swap partition as a cache

(5) View process tree :#pstree [ options] //WHERE option:-P Displays the pid,-u of the process to show the user to which the process belongs.

1.2 terminating a process

(1) Kill command

① View Available process information: #kill –l

Signal Code

Signal Name

Description

1

Sigup

This signal enables the process to shut down immediately and then restarts after the configuration file is read again.

2

SIGINT

The program terminates the signal for terminating the foreground process. Equivalent to output CTRL + C shortcut key

8

SIGFPE

Emitted when a fatal arithmetic operation error occurs. Includes not only floating-point arithmetic errors, but also overflow and all other arithmetic errors except 0.

9

SIGKILL

Used to immediately end a program run. This signal cannot be blocked, processed, or ignored. Typically used to force a process to terminate .

14

Sigalarm

A clock timing signal that calculates the actual time or clock time. The alarm function uses this signal

15

SIGTERM

The signal of the normal end process , the default signal of the KILL command. Sometimes if the process has been a problem, the signal is unable to properly terminate the process, then you can try to sigkill signal, that is, signal 9.

18

Sigcont

This signal allows the paused process to resume execution and the signal cannot be blocked

19

SIGSTOP

This signal can pause the foreground process, equivalent to the input CTRL + Z shortcut key. This signal cannot be blocked.

  ② terminate the process: #kill-Signal code process number

(2) killall command:#killall [options] [signal] process name//kill process by process name

WHERE option:-I is interactive and asks if you want to kill a process. -I: Ignores the case of the process name. For example, #killall -9i httpd, which indicates that the httpd process is forced to kill.

(3) pkill command : #pkill [options] [signal] Process name//terminate process by process name. Where the option "-T terminal number": The user is kicked out according to the terminal number.

① #w//Use the W command to query the user who is logged on by this machine

② #pkill-T-9 PTS/1//force kills the process of logging in from a PTS/1 virtual terminal.

2. Work Management

(1) put the process into the background : ( background process is equivalent to Windows minimized window )

① Method 1: #tar –zcf etc.tar.gz/etc & //& in which the process is placed in the background, which is equivalent to a window in Windows minimized. Note that this method is in the background and the process is still executing

② Method 2: For example, #top//During the execution of the top command, Press CTRL + Z shortcut key . Note that this method is placed in the background, and the process is paused for execution .

(2) View the work in the background:#jobs [-l] //Where the-L shows the working PID.

① output results such as: [1]+ 1742 Stop (signal) top

② note, where [1] is the work number, indicating the order placed in the background, the "+" number represents the last work to put into the background, but also work to restore the default work. The "-" symbol represents the bottom 2nd work in the background.

(3) resume the work of the background pause

① restore to foreground execution   :

#fg%     Work number //The% number can be omitted, but pay attention to the difference between work number and PID.

  ② Restore to background execution

#bg%     work number //note, background recovery execution commands are not interactive with the foreground. Otherwise, it cannot be restored to background execution.

3. System Resource View

View Content

Orders and instructions

Monitoring system resources

#vmstat [Refresh delay refresh]//e.g. #vmstat 1 3

Kernel detection information at boot time

#dmesg or #dmesg | grep CPU

View Memory usage Status

#free [-b|-k|-m|-g]//In bytes, KB, MB, GB. The default is in kilobytes.

View CPU Information

#cat/proc/cpuinfo

Viewing the system's start time and average load

The #uptime, which is the 1th line of the top command. The W command can also see this data

View system and kernel-related information

#uname [Options]//WHERE option-A is used to view all the West-related information of the system;-r view kernel version;-S view kernel name

Determine the number of bits in the current system

#file/bin/ls

Querying the current distribution of Linux systems

#lsb_release-A

List the file information that the process opens or uses

#lsof [Options]//WHERE option "-C string": Only files opened with a process beginning with a string are listed; "-u username": Only files opened by a user's process are listed; "-P pid" lists files opened by a PID process.

4. System Timing Tasks

(1) Crond service Management and access control

① #service crond Restart//start

② #chkconfig Crond on//self-starting

(2) User's crontab settings:

① Command:#crontab [Options] //Where "-E": Edit crontab timed task ;"-L" Query crontab task . "-R" removes all crontab tasks for the current user .

#crontab-E into edit, add shape such as: "* * * * * command" task

Project

scope

1th" * "

1 hours of the first few minutes

0-59

2nd "*"

1 days of the first hours

0-23

3rd" * "

1 months of the week

1-31

4th "*"

months of the year

1-12

5th "* "

Days of the week

0-7 (0 and 7 all represent Sunday)

② Task Settings

Time

Meaning

Special symbols and meanings

45 22 * * * command

Execute command at 22:45

① "*": Represents any time. For example, the 1th "*" means that every minute of 1 hours will be executed once.

② "," stands for discontinuous time. For example, "0 8,12,16 * * * * * * * * * * * * * * * * * * * * * * * * * * * * command"

③ "-" represents a continuous time range. For example, "0 5 * * 1-6 command" represents the execution of orders from Monday to Saturday 5 o'clock in the morning

④ "*/n" represents how often it executes. For example, "*/10 * * * * * * * * * * * * * * command" represents every 10 minutes.

0 17 * * 1 command

Execute the command at 17:0, 1 on a weekly basis

0 5 1,15 * * command

5:0 every month, 1th and 15th, execute orders.

40 4 * * 1-5 command

Every Monday to Friday 4:40 execute the Order

*/10 4 * * * command

Commands are executed every 10 minutes 4 o'clock in the morning every day

0 0 1,15 * 1 command

Commands are executed every month, 1th and 15th, or 0:0 every 1. Note: The day of the week and the date should not appear at the same time. Because they define the days, it is very easy to confuse.

(3) Application examples

# CRONTAB-E

*/5 * * * */bin/echo"aa" >>/tmp/test   // every 5 minutes execution  552 /sbin/shutdown-r now           // weekly 2 5:5 A.M. execute 0 5 1,ten, * */root/sh/autobak. SH       // 5 points per month for 1, 10, 15th

The 12th Chapter Linux System 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.