Monitor a Linux process with a bash script implementation.
Monitor the process using the PS command, and use the Loop plus sleep time for continuous monitoring.
Usage:
PSMONITOR.SH-P [PID]-D [Interval]-n [Statistics count]
Parameters:
-p Monitored process ID
-D read performance data interval
-N statistics, up to the number of times, automatic exit
#!/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 effect:
-bash-3.2$./psmonitor.sh-p 4181-d 1-n 10pid:4181interval:1count:101511232 2537664 37.3 2.41511232 2537664 37.3 2.4151 1232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.415112 32 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.4
Using bash scripts for process performance monitoring