Dachang interviews Linux, just these 5 questions!

1. What is the difference between CPU load and CPU utilization?

First of all, we can uptime, wor topcommand to see the average CPU load.

Load Average  : The 3 numbers of the load, such as 4.86, 5.28, and 5.00 in the figure above, respectively represent the average load of the system in the past 1 minute, 5 minutes, and 15 minutes. It represents the sum of the number of processes currently running and waiting to be run in the system . It also refers to the average number of processes in a runnable state and an uninterruptible state .

If a single-core CPU is used, the load reaching 1 means that the CPU has reached full load. If it exceeds 1, the subsequent processing needs to be queued for processing.

If it is multi-core and multi-CPU, assuming that the server now has 2 CPUs and each CPU has 2 cores, there is no problem if the total load does not exceed 4.

How to check how many cores the CPU has?

cat /proc/cpuinfo | grep "model name"View the CPU status through commands .

By cat /proc/cpuinfo | grep "cpu cores"checking the number of CPU cores

CPU Utilization : Unlike load, CPU utilization refers to the percentage of CPU occupied by the currently running process in real time. It is a statistic of CPU usage over a period of time.

I give a chestnut????:

Assuming that your company toilet has a pit, and one person occupies the pit, the load is 1, if there is another person in the line, then the load is 2.

If in 1 hour, A spent 10 minutes on the toilet, B spent 20 minutes on the toilet, and no one used the toilet for the remaining 30 minutes, then the utilization rate within this hour would be 50%.

2. What if the CPU load is high but the utilization rate is low?

The CPU load is very high, but the utilization rate is very low, indicating that there are many tasks in the waiting state. The higher the load, it means that there may be many dead processes. Usually this situation is an IO-intensive task, and a large number of requests are requesting the same IO, causing the task queue to accumulate.

Similarly, you can first topobserve through commands (the screenshots are just for illustration, not the real situation), and suppose that it is indeed high load and low utilization.

Then, use the command to ps -axjfcheck whether there is a D+state process, this state refers to the uninterruptible sleep state process. The process in this state cannot be terminated, nor can it exit by itself. It can only be solved by restoring the resources it depends on or restarting the system. (Sorry, I can't intercept the status of D+)

3. What if the load is low, but the utilization rate is high?

If your company has only one toilet, no one is in line outside, but one person has been inside for half an hour, what does this mean?

Two possibilities: he didn't bring paper, or something strange happened?

This means that the CPU does not have many tasks, but the task execution time is very long. The high probability is that the code you write has a problem. It is usually a computationally intensive task and generates a large number of time-consuming computational tasks.

How to troubleshoot? Directly topcommand to find the task with the highest usage rate, just locate it and take a look. If there is no problem with the code, then the CPU usage will drop after some time.

4. What if the CPU usage reaches 100%? How to troubleshoot?

  1. By topfinding processes with high occupancy rates.

  1. By top -Hp pidfinding the thread ID with high CPU usage. Find the thread ID of 958 here

  1. Then convert the thread ID to hexadecimal, printf "0x%x\n" 958and get the thread ID0x3be

  1. Through the command jstack 163 | grep '0x3be' -C5 --color or  jstack 163|vim +/0x3be - find the problematic code

5. Tell me about common Linux commands?

Commonly used file and directory commands

ls: The user can view the files in the directory, which ls -acan be used to view hidden files, and ls -lcan be used to view the detailed information of the file, including information such as permissions, size, and owner.

touch: Used to create files. If the file does not exist, a new file is created, if the file already exists, the time stamp of the file is modified.

cat: Cat is concatenatethe abbreviation of English , used to view the content of the file. If you use the catview file, no matter how much the content of the file is, it will be displayed all at once, so it is not suitable for viewing files that are too large.

more: More and cat are a bit different, more is used to display file content on a split screen. You can use the key to page 空格键down and page bup

less: Similar to more, less is used for branch display

tail: It may be the most commonly used command, it is basically up to him to check the log files. General users tail -fn 100 xx.logview the last 100 lines of content

Commonly used authority commands

chmod: Modify authority command. Generally use +number to add permission, -number to delete permission, xstands for execution permission, rstands for read permission, wstands for write permission, common writing methods such as chmod +x 文件名 adding execution permission.

There is another way of writing, using numbers to authorize, because r=4, w=2, x=1, chmod 777 文件名it is the highest authority to execute commands normally .

The first number 7=4+2+1 represents the authority of the owner, the second number 7 represents the authority of the group, and the third number represents the authority of others.

A common permission number is 644. The owner has read and write permissions, while others have read-only permissions. 755 represents other people have read-only and execute permissions.

chown: Used to modify the owner and group of files and directories. General usage is chown user 文件used to modify the file owner, chown user:user 文件modify the file owner and group, before the colon is the owner, and after it is the group.

Commonly used compression commands

zip: Compress zip file command, for example, zip test.zip 文件you can compress the file into a zip file, if you want to compress the directory, you need to add an -roption.

unzip: Corresponding to zip, decompress zip file command. unzip xxx.zipDecompression directly, you can also -dspecify the decompression directory through options.

gzip: Used to compress .gz suffix files. The gzip command cannot pack directories. Note gzip 文件名that if you use the source file directly , it will disappear. If you want to keep the source file, you can use it gzip -c 文件名 > xx.gz, unzip it and use it directlygzip -d xx.gz

tar: Tar commonly used several options, -xunpacking, -cpackaging, -fspecifying the name of the compressed package file, -vdisplaying the process of packaging the file, generally used tar -cvf xx.tar 文件for packaging, decompression is used tar -xvf xx.tar.

Linux packaging and compression are separate operations. If you want to package and compress, you must first package with tar according to the previous method, and then compress with gzip. Of course, there is a better way to -zorder, pack and compress.

Use command tar -zcvf xx.tar.gz 文件to pack and compress, use command tar -zxvf xx.tar.gzto decompress

—————END—————

Friends who like this article, welcome to follow the official account  programmer Xiaohui , and watch more exciting content

点个[在看],是对小灰最大的支持!

Guess you like

Origin blog.csdn.net/bjweimengshu/article/details/111243673