BASH Script Performace

2012-01-06 2 min read bash Learning
Today we will look at some bash code snippests and the performance issues. Lets first look at the problem and the implemented solution: Problem: We needed to log the output of the ps command for all the process’s. This was required to be done on per minute basis and the output was required in comma separated files. So, here is what was implemented: pslog=`ps -e -opid,ppid,user,nlwp,pmem,vsz,rss,s,time,stime,pri,nice,pcp:u,args|grep -v PID|sort -r -k 13,13` OLD_IFS=$IFS IFS=$'\n' logarr=( $pslog ) for LOGLINE in ${logarr[@]} do LOGLINE=`echo $LOGLINE|awk '{OFS=" Continue reading