Use Bash scripts to monitor process performance and bash script Process Performance
Monitors a Linux Process and uses Bash scripts.
Use the ps command to monitor the process, and use the cycle plus sleep time for continuous monitoring.
Usage:
Psmonitor. sh-p [pid]-d [interval]-n [statistics count]
Parameters:
-P monitoring process ID
-D read performance data interval
-N: The number of statistics. When this number is reached, the system automatically exits.
#!/bin/bashinterval=0count=0pid=""while getopts "p:d:n:" argdo case $arg in p) pid=$OPTARG echo "pid: $pid" ;; d) interval=$OPTARG echo "interval:$interval" ;; n) count=$OPTARG echo "count:$count" ;; \?) echo "unkonw argument" exit 1 ;; esacdonei=0;while [ true ]; do if [ $i -gt $count ] then exit 0; else let "i+=1" fi ps h -p $pid -o rss,vsz,%mem,%cpu sleep $intervaldone
Monitoring results:
-bash-3.2$ ./psmonitor.sh -p 4181 -d 1 -n 10pid: 4181interval:1count:101511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.4