Linux system management knowledge point Sharing, linux knowledge point

Source: Internet
Author: User

Linux system management knowledge point Sharing, linux knowledge point

I. Process Management

1. What is a process?

Is the running program

2. Role of process management

Determine System Health Status

View All PROCESSES IN THE SYSTEM

Kill Process

3. View Processes

Ps command ps aux # list all processes of the system.-cannot be added before aux; otherwise, a warning will appear. ps-le # lists all processes of the system. linux Standard Format options:-: display all processes of a terminal-u: display the owner user and memory usage of the process-x: display processes without terminal control-e: display all processes-l: long format display, show more detailed information

USER: Process user pid: process ID % CPU: cpu usage % MEM: memory usage VSZ: virtual memory usage RSS: real memory usage TTY: terminal type, tty1 ~ Tty7, local terminal, pts0 ~ Pts255 Remote Terminal STAT: Process status, R run, S sleep, T stop, s contains sub-process, + background run START: process start time: cpu time consumed by the process COMMAND: command

Pstree command pstree-pu # display the process in a tree option:-p: display the pid-u of A process: display the user of a process

The top command displays the running status of the system and processes that are running. The top command refresh the system once every 3 seconds by default. The top five lines are system statuses and the following processes are running. Top is also an interactive program, which can be processed differently based on different commands entered by users. Top option # display system status options:-I <time>: Set the interval;-u <User Name>: Specifies the user name;-p <process number>: Specifies the process; -n <times>: the number of cycles displayed. Interaction: M: sort by resident memory size; P: sort by CPU usage percentage; T: sort by time/accumulative time; q: exit the program; h: the help screen is displayed, and some brief command summary is provided. Descriptions of the first five fields: top-09:44:56 [current system time], 16 days [the system has been running for 16 days]. 1 user [currently logged on to users], load average: 9.59, 4.75, 1.92 [system load, that is, the average length of the task queue] Tasks: 145 total [total process count], 2 running [number of running processes], 143 sleeping [number of sleeping processes], 0 stopped [number of stopped processes], 0 zombie [number of frozen processes], Cpu (s): 99.8% us [CPU usage percentage of user space], 0.1% sy [CPU usage percentage of kernel space], 0.0% ni [CPU usage percentage of processes that have changed their priorities in user process space], 0.2% id [percentage of idle CPU], 0.0% wa [percentage of CPU time waiting for input and output], 0.0% hi [], 0.0% st [], Mem: 4147888 k total [total physical memory], 2493092 k used [total physical memory used], 1654796 k free [total idle memory], 158188 k buffers [Memory used for Kernel cache] Swap: 5144568 k total [total Swap areas], 56 k used [total Swap areas used], 5144512 k free [total idle Swap areas], 2013180 k cached [total number of buffer swap zones]

4. Killing Processes

The kill command is used to delete programs or jobs in execution. Kill can send the specified information to the program. The preset information is SIGTERM (15). You can terminate the specified program. If you still cannot terminate the program, you can use SIGKILL (9) Information to try to forcibly Delete the program. The program or job number can be viewed using the ps or job command. HUP 1 terminal disconnection INT 2 interrupt (same as Ctrl + C) QUIT 3 QUIT (same as Ctrl + \) TERM 15 terminate KILL 9 Force terminate CONT 18 continue (opposite to STOP, fg/bg command) STOP 19 pause (same as Ctrl + Z)

Killkill [Option] [PID] Option:-a: when processing the current process, the correspondence between command names and process numbers is not restricted;-l <Information No.>: if the <information number> option is not added, the-l parameter lists all information names.-p: specifies that the kill command prints only the process number of the relevant process without sending any signal; -s <information name or number>: specifies the information to be sent;-u: Specifies the user.

Killall sometimes has multiple processes in a software or service. killall can only kill one process, and killall can kill all the processes of a software or service. Killall [Option] [Signal] process name option:-I: interactive mode;-I: Ignore the case sensitivity of process names

Pkillpkill [Option] [Signal] process name option:-t: terminal number; kill the user according to the terminal number:

2. Work Management (Background Program Management) Work Management is background program management. Sometimes complicated tasks are performed, such as copying large files and backing up large files, such a task usually takes a long time to run. During the running period, this task will occupy the terminal. At this time, we can only wait for this task to complete, and we can't do anything before it is completed. In fact, this problem can be solved by putting this task in the background line.

1. How to put the program to the background for running

Add & after the command, for example, tar-zcf etc.tar.gz/etc &

Press Ctrl + Z when executing the command at the front-end and put it in the background for suspension.

2. View background programs

Jobs [Option] Option:-l: Display Background Program PID

Note: The number of the background program is enclosed in brackets, which can be used during frontend and backend switch. + indicates that the number is placed in the backend.-indicates that the last and second digits are placed in the backend.

3. frontend and backend program Switching

Fg % program number. Place the background program to the foreground

Bg % program number. Place the foreground program in the background. Description: The program number is the number in brackets.

4. run without the terminal

The concept of leaving the terminal is that the program we run in the terminal is bound to the terminal. When we exit the terminal, the program will automatically end. Sometimes we want to start a service and then exit the terminal to run it. In this case, we need to leave the terminal to run.

The system service cannot be started in the terminal. It can be written to/etc/rc. d/rc. local.

In scheduled task

Nohup command: nohup command & 3. View System Resources

1. vmstat: reports the overall running status of processes, memory, I/O, and other systems.

Procs (process)

R: Number of processes in the running queue. This value can also determine whether to increase the CPU. (Longer than 1)

B: Number of processes waiting for IO. Memory (Memory)

Swpd: the virtual memory size. If the value of swpd is not 0, but the value of SI and SO is 0 for a long time, this will not affect the system performance.

Free: The size of idle physical memory.

Buff: the buffer size.

Cache: the memory size used as the cache. If the cache value is large, it indicates that the number of files in the cache is large. If files frequently accessed can be cached, then the disk read IO bi will be very small. Swap

Si: The size of memory written from the swap area per second, which is transferred from the disk to the memory.

So: the memory size written to the swap zone per second, which is transferred from the memory to the disk. Note: When the memory is sufficient, these two values are all 0. If these two values are greater than 0 for a long time, the system performance will be affected and the disk I/O and CPU resources will be consumed. When some friends see little or near zero free memory, they think the memory is not enough. They should not just look at this point, but also combine si and so. If there is little free, however, si and so are also few (mostly 0), so don't worry, the system performance will not be affected at this time. IO (the size of the current Linux version block is 1 KB)

Bi: Number of read blocks per second

Bo: number of blocks written per second. Note: when reading and writing random disks, the larger the two values (for example, exceeding 1024 k), the larger the value of CPU waiting for I/O. System)

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

Cs: Number of context switches per second. Note: The larger the values above, the larger the CPU time consumed by the kernel. CPU (expressed in percentage)

Us: when the user process execution time percentage (usertime) us value is relatively high, it indicates that the user process consumes a lot of CPU time, but if it is used for a long time more than 50%, so we should consider optimizing the program algorithm or accelerating it.

Sy: When the kernel system process execution time percentage (system time) sy is high, it indicates that the system kernel consumes a lot of CPU resources, which is not a benign manifestation. We should check the cause.

Wa: when the percentage of I/O wait time is high, the I/O wait is serious, which may be caused by a large number of random access to the disk or disk bottlenecks (block operations ).

Id: Percentage of idle time 2. free [-B |-k |-m |-g]: displays the memory usage. The unit in which the options are displayed is 3. dmesg: Information of self-check on startup, 4. view cpu: cat/proc/cpuinfo5.uptime: the first line of top Command 6. view kernel information: uname-a7.linux release: lsb_release-a 4. scheduled task

1.

The at command is used to execute commands at a specified time. At [Option] [time] Option:-m: send an email to the user after the task is executed. -C: show all set specific command time: HH: MM for example: 02: 33HH: MM YYYY-MM-DD For example: 15: 28 five o'clock P.M. tomorrow 17: 20atq query set those tasks atrm Delete the set task at-c task number, view the specific content of the task

Note:/etc/. allow and/etc/. deny is the White List and blacklist of at service respectively. It takes effect if you write the user name to your busy schedule. allow priority is greater. deny, other services such as whitelist and blacklist also have the following permissions: crontab note: the permissions for tasks in at are the same as those for task creation users, if the permission is exceeded, the task is not executed.

2. crontab

The crontab command is used to submit and manage users' tasks that require periodic execution. Similar to scheduled tasks in windows, this service tool is installed by default after the operating system is installed, the crond process will be started automatically. The crond Process regularly checks whether there are tasks to be executed every minute. If there are tasks to be executed, the crond process will be automatically executed. Crontab [Option] Option:-e: Edit crontab, using the vim Editor-l: list all scheduled tasks-r: delete writing rules for all scheduled tasks crontab: in the crontab file created by the user, each row represents a task, and each field in each row represents a setting. Its format is divided into six fields. The first five fields are time sets, the sixth part is the command segment to be executed. The format is as follows: minute hour day month week command order: minute hour day month week where:

Minute: minute. It can be any integer from 0 to 59.

Hour: indicates the hour, which can be any integer from 0 to 23.

Day: indicates the date, which can be any integer from 1 to 31.

Month: represents the month, which can be any integer from 1 to 12.

Week: the day of the week. It can be any integer from 0 to 7. Here 0 or 7 represents Sunday.

Command: the command to be executed. It can be a system command or a script file compiled by yourself. You can also use the following special characters in the preceding fields:

Asterisk (*): represents all possible values. For example, if the month field is an asterisk, this command is executed every month after the conditions of other fields are met.

Comma (,): values separated by commas (,) can be used to specify a list range, for example"

Middle bars (-): You can use the middle bars between Integers to represent an integer range. For example, "2-6" indicates "2, 3, 4, 5, 6"

Forward slash (/): You can use a forward slash to specify the interval of time. For example, "0-23/2" indicates that execution is performed every two hours. At the same time, the forward slash can be used with the star number, for example, */10. If it is used in the minute field, it indicates that the execution is performed every ten minutes. Instance: restart smb45, 22 **/etc/init at every month. d/smb restart: Execute the command at 3rd and 15th minutes from eight o'clock A.M. to every two days. Note:/etc/cron. allow and/etc/cron. deny is the whitelist and blacklist of the cron service. It takes effect if you write the user name to your account. allow priority is greater. deny note: the permission for a task in crontab is the same as that for creating a task user. If the permission is exceeded, the task will not be executed.

3. Scheduled system task

The system scheduled task is set through the/etc/crontab configuration file. Its Writing rules are similar to crontab-e, but the user field is added.

There are four special folders under/etc/. These four folders store the scheduled task script, as long as the executable script is placed in cron. in daily, it will be executed once a day, cron. hourly is executed every hour, cron. monthly is executed once a month, cron. weekly is executed once a week.

4. anacron

The preceding example shows that the execution of a folder depends on/etc/crontab and anacron. centos6 and later fully depends on anacron for execution. In versions earlier than centos6,/etc/crontab will be directly set. In centos6 and later versions, this is not the case.

Anacron principle: There are three files under/var/spool/anacron/: cron. daily, cron. weekly, cron. mouthly, these three files respectively record the last execution time of all scripts in the directory with the same name as the three files in/etc. Anacron checks cron every day. daily, checks cron every seven days. weekly, checks cron every month. the time difference between the time recorded by the mouthly file and the check time. If the time difference is greater than one day, one week, or one month, scripts in the corresponding folder will be executed. Anacron configuration file:/etc/anacrontab

RANFD_DELAY: random delay START_HOURS_RANGE: the execution time range. The last three rows have four fields: Number of days, forced Delay Time, and working name. The actual command takes the execution of cron. daily as an example:

First check/var/spool/anacron/cron. daily

Compare record time and current time

If the time exceeds one day, run the script in/etc/cron. daily.

Only 3 ~ Run the command between and (you can modify the configuration file)

The execution will be forcibly delayed for 5 minutes + random delay 0 ~ Run the command 45 minutes later.

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.