Question & Answer
Question
Cause
Answer
The below script will try store the output of the cat command script variable To achieve that it has to allocate memory equal to size of the file. But ksh will not be able to allocate MB of data to a script variable as mentioned in the below example. The script will fail with
error “0403-029 There is not enough memory available now.”
Creating test.out file :
#perl -e 'print("x") for (1..8388607);print "\n"' > test.out
Script :
# cat ksh_enomem.sh
#!/usr/bin/ksh
test=`cat ./test.out`
exit 0
# ls -l test.out
-rw-r--r-- 1 root system 8388608 Jul 19 09:22 test.out
# ./ksh_enomem.sh
./ksh_enomem.sh[2]: 0403-029 There is not enough memory available now.
Workaround :
Use ksh93 instead of ksh
# ./ksh_enomem.sh
./ksh_enomem.sh[2]: 0403-029 There is not enough memory available now.
(1) root @ telesto2: 7.2.0.0: /
# /usr/bin/ksh93 ./ksh_enomem.sh
(0)
Solution :
AIX offers KSH_STAK_SIZE environment variable to prevents this error and we have to export the environment variable with space to satisfy the needs of the script variable.
In this case file size is 8MB
ls -l test.out
-rw-r--r-- 1 root system 8388608 Jul 19 09:22 test.out
(0)> dcal 8388608/(1024*1024)
Value decimal: 8 Value hexa: 00000008
But we dont have easy method to find how much ksh can allocate to the variable in question and Ksh has not provided any information on how much memory required to successfully run the script . It only fails with "not enough memory available"
So user has use trail and error method to choose proper size to KSH_STAK_SIZE
0) root @ telesto2: 7.2.0.0: /
# export KSH_STAK_SIZE=1MB
(0) root @ telesto2: 7.2.0.0: /
# ./ksh_enomem.sh
./ksh_enomem.sh[2]: 0403-029 There is not enough memory available now.
(1)
# export KSH_STAK_SIZE=2MB
(0)
# ./ksh_enomem.sh
(0)
It better to set KSH_STAK_SIZE in script.
Note : KSH_STAK_SIZE should be between 32k to 128MB
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Author: Chetan Gaonkar
Operating System: AIX and VIOS
Hardware: Power
Feedback: aix_feedback@wwpdl.vnet.ibm.com, cgaonkar@in.ibm.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Was this topic helpful?
Document Information
Modified date:
21 July 2020
UID
ibm16250831