Monday, October 25, 2010

Identify the most cost UNIX process CPU



Multi-user UNIX computer systems running the process, sometimes feel a sudden slow down processing speed, and sometimes even characters from the keyboard is also too long a response will be. Experienced people will know, then the computer must run a CPU-consuming process. This process is sometimes an individual account in the implementation of a CPU process, sometimes there may be unforeseen circumstances out of the system, the system itself during processing. In either case, the system administrator to find out that the process should be timely and make the appropriate treatment.

Although UNIX provides the "acct" and a series of accounting procedures, but these procedures can only be displayed after the process run time and CPU-time information, not real-time unit of time, a process which occupied the most CPU time.

To do this I use the shell language for a program to provide some of the use of UNIX utilities to achieve the above functionality.

This section contains procedures ps, cut, diff and other UNIX utilities, the following briefly explain the functions of these utilities.

ps: to display the current system processes information. With the-e parameter is displayed in the system processes information. Use the-f parameter is showing the process of complete information;

cut: used to trim the file as a unit. Parameter "-c -15,33 -" that the input file before each line 15 characters and 33 characters after the end of the line until all the characters into the output file;

echo: used to screen prompts;

sleep: shell program can wait for several seconds, and then run behind the statement;

diff: used to compare two files, differences are displayed;

sort: the file can sort the various lines, sort the results can be displayed;

grep: can be used to find the file the line to meet certain conditions. Parameter "^" means to find the first lines as a space;

|: The pipe symbol, can be realized to the back of the previous command's output as the role of the command input, so you can omit the intermediate files generated steps to improve the efficiency;

>: That of the output redirected to should have been something on the screen output to a file.

Procedure as follows:

ps-ef | cut-c -15,33 -> tt1

echo Please wait a while ...

sleep 20

ps-ef | cut-c -15,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

First of all, the system processes all the processes to obtain information and put them into useful fields in the temporary file tt1. Then the program to wait for 20 seconds (adjusted time with specific cases).

Then the process again to obtain all the information and put all the fields in the temporary file tt2.

Compare the two temporary files, find the 20 seconds before and after the information on those different processes (of which there is consumption of CPU time the process has been changed).

Generated when compared remove the ">" and "<", the results placed in the temporary file tt3.

Tt3 content on the sort to spend CPU time to change the process of around the same row with the information. grep "^" is used to remove the implementation of this program produced a number of shell commands the middle of the process information.

Then cut each line is too long deleting process information, make the output clearer. The grep-v 0:00 is used to remove only occurs once in 20 seconds before and after the process. Program execution now, at 20 seconds of CPU time spent before and after the different processes is displayed on the screen, and from which you can easily find out by looking for the process. Finally, to not leave the system useless junk files, but also to all the three temporary files deleted.







Recommended links:



Cool my music box, THE new interface, mainly practical



Articles about Genealogy



YouTube to WMV



Make online video critical information



Joint Commerce and Industry of India: India will rely heavily on computer HARDWARE in China



Articles About Audio Players



QuickTime to MPG



ShotGraph Ordinary principles of drawing



JSP Servlet Automatically jump to the wrong instance of the page



The Three Basic Features Of Object-oriented [1]



TO work without selection, the problem you thought about it?



WMV to Zune



e-cology in the pan of A micro-series



Simple FTP Clients



No comments:

Post a Comment