Beyond the limits - environment

1. Prerequisites
My environmnet is based on Solaris 10  10 9/10  with 640 MB of memory and CentOS 5.5 2.6.18-194.26.1.el5 with 512 MB, standard installation both of them run in VMWare environmnet. For shell I use bash (as common)

bash-3.00# bash --version
GNU bash, version 3.00.16(1)-release (i386-pc-solaris2.10)
Copyright (C) 2004 Free Software Foundation, Inc.


[root@centos ~]# bash --version
GNU bash, version 3.2.25(1)-release (i686-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.


All the tests will be done with default settings of the OS and environment

2. Test the maximum length variable
the script i will use is sample:

TEMPVAR=A
for i in {1..10000};
        do
        TEMPVAR=${TEMPVAR}$TEMPVAR;
        a=$(echo 2^$i+1|bc)
        b=$(echo $TEMPVAR|wc -c)
        if [ $a -ne $b ]
        then echo KO - $a, $b
        else echo $a
        fi
done

 2.1. And the execution in Linux


[root@centos ~]# ./z1.sh
3
5
<snip>
67108865
134217729
./z1.sh: xmalloc: cannot allocate 268435457 bytes (0 bytes allocated)
KO - 268435457, 0
[1]+  Stopped                 ./z1.sh
[root@centos ~]# vmstat 1 2
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0  10716 229500  25160 228524   66  139   138   178 1011  151 18 18 61  3  0
 0  0  10716 229500  25160 228524    0    0     0     0 1013   15  0  0 100  0  0

 As you can see above I get error allocating memory beyond the size of free memory
2.2. Execution in Solaris

bash-3.00# ./z1.sh
3
5
<snip>
8388609
16777217
./z1.sh: fork: Not enough space
./z1.sh: line 7: [: 33554433: unary operator expected
33554433
./z1.sh: fork: Not enough space
bash-3.00# vmstat 1 2
 kthr      memory            page            disk          faults      cpu
 r b w   swap  free  re  mf pi po fr de sr cd f0 s0 --   in   sy   cs us sy id
 0 0 0 856808 174100 50 1101 0  1  5  0 66  2 -0  3  0  336  801  308  9  7 84
 0 0 0 749832 70472   3  43  0  0  0  0  0 27  0  0  0  326  300  185  1  9 90
 

 The similar is situation in Solaris where i can allocate even less that half of free memory
Of course it is not very wise to use such variables, but who knows?
3. Number of commandline arguments
3.1. Sample C program
Next I will try to check what is the maximum of commandline arguments of one sample C program

#include <stdio.h>
int main(int argc, char *argv[])
{
        printf("%d\n", argc);
}

and the shell script I will use is

TEMPVAR=A
for i in {1..1000}
do
TEMPVAR="$TEMPVAR $TEMPVAR"
a=$(./a.out $TEMPVAR)
echo $a
done
 


3.1.1 On Linux

[root@centos ~]# cc z2.c
[root@centos ~]# ./a.out 1
2
[root@centos ~]# ./a.out 1 2
3
[root@centos ~]# ./z2.sh
3
5
<snip>
524289
1048577
./z2.sh: line 5: ./a.out: Argument list too long


 1m of arguments, that pretty much :)
3.1.2 Solaris

bash-3.00# /usr/sfw/bin/gcc z2.c
bash-3.00# ./a.out 1
2
bash-3.00# ./a.out 1 2
3
bash-3.00# ./z2.sh
3
5
<snip>
65537
131073
./z2.sh: line 5: ./a.out: Arg list too long

"Just" 128k, not so much as Linux, but anyway do someone will use so many for practical puspose?


3.2. Sample shell program
Next I will try to check what is the maximum of commandline arguments of one very sample shell program

echo $#

 using this shell script

TEMPVAR=A
for i in {1..1000}
do
TEMPVAR="$TEMPVAR $TEMPVAR"
a=$(./z2test.sh $TEMPVAR)
echo $a
done
 

 This time the results appear mich slower because of the invocation of subshell.
3.2.1 Linux
After 1 hour of waiting I stop the script, but before this I see in top

29827 root      25   0 47028  41m  476 R 99.9  8.3   2:38.86 bash

3.2.2. Solaris
The same (long waiting) happen in Solaris and after 128k i see in prstat

 15100 root       72M   69M run     20    0   0:09:01  96% bash/1

As conclusion 128K is the maximum practicle limit of number command line arguments

No comments:

Post a Comment

Compressed tar archive

There are some cases when you want to create compressed tar archive but you do not have enough disk space to keep original files and tar arc...