[asterisk-users] asterisk's zombie processes

Steve Edwards asterisk.org at sedwards.com
Wed May 18 20:38:57 CDT 2011


On Wed, 18 May 2011, Skyler wrote:

(Please see script from previous post.)

Band-aids are a bad idea. Fixing (or properly reporting) a bug serves the 
whole community better.

Getting off my soap-box, I recognize that using a band-aid and keeping 
your job beats being right :)

I haven't tried your script in production. I don't use safe_asterisk and I 
don't have a problem with zombies. (I'm not suggesting there is a 
connection between those conditions.)

I would like to offer a few suggestions that will make your script more 
efficient and who doesn't like learning a few new programming tricks :)

t1=`cat /proc/stat | grep btime | awk '{print $2}'`

can be written as

BOOT_TIME=$(awk '/^btime/ {print $2}' /proc/stat)

) Descriptive variable names make program maintenance easier.

) Use Bash's $() instead of backticks. They're easier to read and nest.

) Awk (an awful name for a great program) can do this task in a single 
invocation saving 2 process creations.

date=`date +%d-%m-%Y_%Hh%Mm` 
echo "$date - Asterisk Zombies Clean up started....." ####  >> $LOG

can be written as

date +'%F %T Asterisk Zombies Clean up started.....%n' >>${LOG}

) Using the formatting abilities of date saves 1 process creation. (I know 
echo is usually a 'built-in,' but the concept is valid.)

) I prefer '%F %T' as a timestamp because it sorts properly.

for parent in `ps -ef | grep safe_asterisk | awk '$3 == '1'{print $2}'`

can be written as

for parent in $(pgrep safe_asterisk)

) The pgrep utility saves you 2 process creations.

) Pgrep can also be used on the other 2 for statements with similar 
savings.

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000



More information about the asterisk-users mailing list