View CPU Footprint
Enter top on the command line
You can start top
Top Full Screen Dialog mode can be divided into 3 parts: System Information Bar, command input bar, process list bar.
Use top to view system load
The top command can dynamically monitor the system load, including CPU, memory usage, and resource-intensive process details.
Dynamically View system load (occupy one terminal)
Top
Exit after display
Top-n 1
Output in text format for use by other programs
Top-b
All right, let's see. Limit CPU and memory usage methods
Script content:
| The code is as follows |
|
#!/bin/sh Upid= ' Top-bn 1 | grep "^ *[1-9]" | awk ' {if ($ > | | $ > && id-u $ >) print ' For PID in $UPID Todo Renice +10 $PID echo "Renice +10 $PID" Done |
I modified the script above to limit the process to the entire server.
Modified script:
| The code is as follows |
|
#!/bin/sh Upid= ' Top-bn 1 | grep "^ *[1-9]" | awk ' {if ($ > | | $ >) PRINT $} ' For PID in $UPID Todo Renice +10 $PID echo "Renice +10 $PID" Done |
You can run this script in cron and have it checked every minute:
| The code is as follows |
|
chmod +x limit.sh Vi/etc/crontab */1 * * * */bin/sh/root/soft_shell/limit.sh |
Ps:
N: Number of updates, and will exit top after completion
B: Batch file mode, with "n" Parameters used together, can be used to output the top results to the file
So top-bn 1 is the result of getting the top output once.
grep "^*[1-9]": To get the PID number directly, excluding the table first information.
awk ' {if ($ > | | $ > && id-u $ >) print ':
Process PID with CPU usage greater than 20% or memory usage greater than 25%, and user uid greater than 500.