Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the most expensive CPU process in UNIX

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

What is the most expensive CPU process in UNIX? in view of this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

When a multi-user UNIX computer system is running, it sometimes feels that the computing speed suddenly slows down, and sometimes it takes a long time to input characters from the keyboard. Anyone with experience will know that a very CPU-consuming process must be running on the computer. Such a process is sometimes someone executing a program that takes up a lot of CPU, and sometimes it may be an unexpected situation in the system that the system itself is dealing with. In either case, the system administrator should find out such a process in time and deal with it accordingly.

Although UNIX provides a series of accounting programs such as "acct", these programs can only display information such as running time and CPU time after the end of the process, and can not calculate in real time which process takes up the most CPU time per unit time.

For this reason, I have written a program in Shell language and realized the above functions by using some utility programs provided by UNIX.

This section of the program contains ps, cut, diff and other UNIX utilities, the following is a brief introduction to the functions of these utilities.

Ps: used to display information about processes in the current system. Use the-e parameter to display information about all processes in the system. Use the-f parameter to display the complete information of each process

Cut: used to clip files in column units. The parameter "- c-15jue 33 -" means to put the first 15 characters of the input file and all characters after the 33rd character until the end of the line into the output file.

Echo: used to display prompts to the screen

Sleep: you can make a shell program wait a few seconds before executing the following statement

Diff: used to compare two files, but the differences are shown

Sort: the lines in the file can be sorted, and the sorting results can be displayed.

Grep: can be used to find lines in a file that meet certain conditions. The parameter "^" indicates that each line listed as a space is found.

| |: it is the symbol of the pipeline, and the output of the previous command can be used as the input of the later command. In this way, the step of generating intermediate files can be omitted and the execution efficiency can be improved. |

>: means to redirect the output and output what should have been displayed on the screen to a file.

The contents of the program are as follows:

Ps-ef | cut-c-15J 33-> tt1

Echo Please wait a while...

Sleep 20

Ps-ef | cut-c-15J 33-> tt2

Echo Attention!

Echo

Diff tt1 tt2 | cut-c 2-> tt3

Sort tt3 | grep ^ | cut-c-83 | grep-v 0:00

Echo

Echo That is ok!

Rm tt1 tt2 tt3

The program first takes the information of all the processes in the system and puts the useful fields into the temporary file tt1. Then let the program wait 20 seconds (the time can be adjusted on a case-by-case basis).

Then get the information about all the processes again and put all the fields in the temporary file tt2.

Compare the two temporary files to find those processes with different information before and after 20 seconds (including those that consume CPU time has changed).

Remove the ">" and "sum" generated during the comparison.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report