2

We have a number of ksh scripts that run forever (inside a while loop), or at least until a shutdown event is delivered to them. We had a project where these scripts where converted to ksh93 (and functionality was added) and the O/S was upgraded from AIX 5.3 to 6.1. The ksh scripts ran without issue on AIX 5.1. Now that we've converted to ksh93, AIX 6.1, and added functionality, we're finding the memory of the processes continues to grow until it has exceeded its limit. We've had to add logic to kill and restart the processes when they reach a memory threshold.

We're assuming, maybe incorrectly, that there's a memory leak in some ksh93 function.

I'm trying to determine if there's a particular function that's not releasing memory. To get process memory I've been using svmon -P $$ | grep $$ | awk '{ print $3 }'. Maybe there's a better way to do that.

Here's the output of the svmon command at various points in the script. I've added an "End-Of-Loop" to show the bottom of the outer 'while' loop. You'll notice that memory use keeps climbing, except for the occasional reading where is back down to near the starting value. I'm guessing these low values are erroneous because the very next reading after the low value seems to follow the reading just before the low value. If you remove the low values, the memory usage continues to climb. This script is a watchdog script which checks on the existence of our other processes. The scripts for our other processes exhibit the same type of behaviour.

Is there a better way to determine memory use? Is anyone aware of common ksh93 functions that don't release memory properly? IBM suggested we upgrade to AIX 7.x but that's not a possibility at this time.

I should warn you now. I'm a DBA, not a ksh script developer.

28721   
Start-Of-Loop   
28435   <--- low value  
28733   
28737   
28740   
28745   
28747   
28435   <--- low value   
28755   
28759   
28762   
28767   
28770   
28774   
28777   
28780   
28783   
28787   
28791   
28806   
28809   
28813   
28817   
28822   
28825   
28828   
28831   
28833   
28835   
28835   
28838   
28839   
28843   
28843   
28843   
28435   <--- low value   
28843   
28843   
28846   
28846   
28847   
28408   <--- low value   
28853   
28853   
28853   
28408   <--- low value  
28854   
28854   
28857   
28857   
28859   
28860   
28863   
28863   
28864   
28865   
28867   
28869   
28871   
28874   
28878   
28878   
28879   
28879   
28882   
28882   
28883   
28884   
28887   
28888   
28891   
28891   
28435   <--- low value  
28894   
28897   
28898   
28901   
28436   <--- low value  
28904   
28904   
28906   
28906   
28910   
28910   
28914   
28407   <--- low value  
28917   
28435   <--- low value  
28921   
28923   
28927   
28927   
28930   
28436   <--- low value  
28935   
28935   
28935   
28938   
28942   
28942   
28435   <--- low value  
28946   
28948   
28950   
28953   
28953   
28953   
28953   
28953   
28953   
28957   
28957   
28958   
28958   
28959   
28959   
28961   
28962   
28965   
28408   <--- low value  
28966   
28966   
28967   
28968   
28970   
28971   
28974   
28974   
28975   
28975   
28976   
28976   
28408   <--- low value  
28978   
28978   
End-Of-Loop  
28436   <--- low value  
28982   
28982   
28983   
28408   <--- low value  
28984   
28984   
28985   
28440   <--- low value  
28989   
28990   
28436   <--- low value  
28991   
28991   
28991   
28991   
28991   
28994   
28995   
28995   
28995   
28995   
28997   
29001   
29004   
29008   
28435   <--- low value  
29008   
29008   
28408   <--- low value  
29011   
29011   
29011   
29015   
29015   
29019   
29019   
29019   
29019   
29020   
28435   <--- low value  
29025   
29026   
29028   
29030   
29033   
29033   
28435   <--- low value  
29035   
29039   
28436   <--- low value  
29039   
29039   
29041   
29043   
28408   <--- low value  
29047   
29050   
29050   
29052   
29052   
29055   
29055   
29057   
29057   
29058   
28408   <--- low value  
29061   
29062   
29067   
29067   
29068   
28408   <--- low value  
29069   
29070   
29075   
28408   <--- low value  
29076   
29076   
29076   
28408   <--- low value  
28408   <--- low value  
28435   <--- low value  
29080   
29083   
28408   <--- low value  
29087   
29089   
29089   
29092   
29094   
28430   <--- low value  
29097   
29100   
29101   
29103   
28408   <--- low value  
29103   
29103   
29104   
29104   
28435   <--- low value  
29107   
28408   <--- low value  
29111   
29113   
29114   
29117   
29117   
29120   
29120   
29122   
29122   
29124   
29124   
29127   
29127   
29129   
29129   
28408   <--- low value  
29134   
29135   
29135   
29135   
29135   
29139   
29139   
29139   
29139   
28440   <--- low value  
29139   
28435   <--- low value  
28408   <--- low value  
29139   
End-Of-Loop  
29141   
29145   
29145   
29147   
28435   <--- low value  
29150   
29150   
29153   
29153   
29155   
29157   
29157   
29157   
29157   
29157   
29159   
29159   
29159   
29159   
29163   
29163   
29167   
29169   
29172   
29172   
29175   
29175   
29177   
29177   
29177   
29179   
28435   <--- low value  
29181   
29186   
29186   
29189   
29189   
29191   
29193   
29196   
29196   
29198   
29198   
29199   
29200   
29202   
29202   
29205   
29205   
28435   <--- low value  
29209   
29211   
28435   <--- low value  
29216   
29217   
29220   
28435   <--- low value  
29225   
29225   
28433   <--- low value  
29227   
28433   <--- low value  
29229   
29230   
29231   
29233   
29233   
29235   
29237   
29238   
29239   
29244   
29247   
29250   
29252   
29258   
29260   
29263   
29264   
29268   
29269   
29271   
29271   
29274   
29274   
28435   <--- low value  
28408   <--- low value  
29283   
29286   
29287   
29291   
29291   
29295   
29295   
29295   
29299   
29303   
29303   
29306   
29306   
29308   
29310   
29312   
28440   <--- low value  
29312   
29312   
29317   
29318   
29322   
29322   
29323   
29323   
28408   <--- low value  
28407   <--- low value  
29327   
29327   
29329   
29329   
28435   <--- low value  
29329   
29330   
29331   
28437   <--- low value  
29333   
29336   
29336   
29336   
29336   
29336   
29336   
29336   
29336   
29336   
End-Of-Loop  
29338   
29342   
29343   
29343   
29345   
29347   
28435   <--- low value  
28435   <--- low value  
29349   
29349   
29351   
29353   
29353   
29354   
29354   
29354   
29354   
29354   
28436   <--- low value  
28408   <--- low value  
29356   
29357   
29357   
29361   
29361   
28435   <--- low value  
29361   
29363   
29363   
29366   
29367   
29373   
28408   <--- low value  
29376   
29376   
29380   
28407   <--- low value  
28435   <--- low value  
29381   
28440   <--- low value  
29387   
29387   
29390   
29394   
29394   
28436   <--- low value  
29396   
29398   
29399   
29401   
29401   
29402   
29402   
29403   
29404   
29406   
28436   <--- low value  
29411   
28408   <--- low value  
29417   
29417   
29418   
29419   
29421   
29421   
29423   
29424   
29426   
29426   
28408   <--- low value  
29431   
29435   
29435   
28435   <--- low value  
29439   
29442   
29444   
28435   <--- low value  
29447   
29449   
29449   
29451   
29451   
29455   
29455   
28435   <--- low value  
29458   
29461   
29462   
29465   
29467   
28408   <--- low value  
29470   
29473   
29475   
29478   
29479   
29483   
29483   
29485   
29485   
29488   
29488   
29489   
29489   
29489   
29489   
29491   
29492   
29493   
29493   
29495   
29497   
29501   
29503   
29504   
29504   
29506   
29508   
29509   
29511   
29515   
29515   
29519   
29519   
28436   <--- low value  
29521   
28408   <--- low value  
29522   
29523   
28435   <--- low value  
29523   
29523   
29523   
End-Of-Loop  
0

Sorry I cannot answer your questions but I suggest you change the script to do the loop a predefined no of times, then run itself and end. This way the operating system will release the excessive memory allocated by the leak before it gets huge.

This should be more efficient than checking for how much memory is being used all the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.