Improve company productivity with a Business Account.Sign Up

x
?
Solved

set "environment size" ksh aix

Posted on 2004-04-12
15
Medium Priority
?
5,362 Views
Last Modified: 2013-11-17
Hello out there,

How do I display set (increase) the environment SIZE for ksh under AIX?

Kind regards,

Ebe
0
Comment
Question by:ekariel
  • 6
  • 4
  • 3
13 Comments
 
LVL 20

Expert Comment

by:Gns
ID: 10814242
Eh, Is there such a limit? Surely not imposed be ksh at least.
The "passing of environment" from parent to child is handled by the exec family of syscalls (man exec), and one can see there that the environment is defined as a "pointer to pointer to char" thingy (a vector of strings), where the end of environment is "signaled" by a NULL string. Could be pretty hefty on a 64 bit machine:-).

From the man-page of the IEEE POSIX 1003 limits.h file one can further glean
------- Start snip
Run-Time Invariant Values (Possibly Indeterminate)

The second set of run-time invariant values required by POSIX specify values
that might vary, especially due to system load, but that can be attained on a
lightly loaded system.

Symbol Value Explanation

ARG_MAX 24,576> Maximum length (in bytes) of arguments for the exec subroutine,
including the environment
Note: The argument list and environment are allowed to consume all of the user
data segment.
------- End snip
So this leads one to believe that one could "increase" this by use of the ulimit shell builtin (realistic only for root), or by changing the limit in /etc/security/limits (a -1 value == inifinity).

Or are you asking how to set and export the environment variable SIZE? "export SIZE=value" ...:-)... Nah, probably not.

-- Glenn
0
 

Author Comment

by:ekariel
ID: 10814530
Thanks Glenn. The short answer is - upgrade to AIX 5.1!! Then you can do the following:

ncargs
Purpose:  Specifies the maximum allowable size of the ARG/ENV list (in 4KB blocks) when running exec() subroutines.  
Values:  Default: 6; Range: 6 to 128  
Display:  lsattr -E -l sys0 -a ncargs  
Change:  chdev -l sys0 -a ncargs=NewValue
Change takes effect immediately and is preserved over boot.  
Diagnosis:  Users cannot execute any additional processes because the argument list passed to the exec() system call is too long.  
Tuning:  This is a mechanism to prevent the exec() subroutines from failing if the argument list is too long. Please note that tuning to a higher ncargs value puts additional constraints on system memory resources.  

This is from:

http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/share/man/info/en_US/a_doc_lib/aixbman/prftungd/2365a82.htm#HDRI48026

Another question then - how do you DELETE an environment variable under Unix? Putenv under Windows allows a null value to be treated as "delete the variable".

Kind regards,

Ebe
0
 
LVL 20

Expert Comment

by:Gns
ID: 10821119
Ah, and the default value for ncargs is 6... which is to say the POSIX limit. Good info. Thanks.

Deleting...
As you've seen, if you have
export aa=somestring
env | grep aa
... will give
aa=somestring
... and a subsequent
aa=
... will still keep aa around with a null value. You need do
unset aa
for it to go away:-).

Happy trails!

-- Glenn
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LVL 62

Expert Comment

by:gheist
ID: 10846084
Thanks ekariel, ksh is broken (linked against old libraries i guess)
you have option to configure in AIX 5.1 , but ksh does not catch up still...
This is not about env list, but about args, so use xargs to split the list, or bash2 for finer limit

for ksh
export VAR=value # makes VAR containing value
unset VAR=value # removes variable
readonly VAR # locks out both previous

/etc/security/profile
default .profile for new user
/etc/environment
file run first to set env variables by tsm (Terminal Security Manager, known as login or pam on other systems)
/etc/profile
shell script run before user's .profile, export, readonly and unset goes here
0
 

Author Comment

by:ekariel
ID: 10871644
Ok - sorry about the delay - had a system to fix! Maybe I didn't state the problem clearly enough. unset works in the shell. I need the name of the API to call to achieve the same effect in a C program. As mentioned before, putenv under Windows allows a null VALUE to be treated as "delete the environment variable". This doesn't appear to be the case under Unix/Linux/AIX. Any ideas?

Kind regards,

Ebe

0
 
LVL 62

Expert Comment

by:gheist
ID: 10872090
> How do I display set (increase) the environment SIZE for ksh under AIX?
Is ksh yet another C compiler ? A dialect ??
0
 
LVL 20

Expert Comment

by:Gns
ID: 10876944
Ok... Well, the following "silly test.c"
main() {
        char tst[1200];

        strcpy(tst,"NORKSEN=BLARUTIG");
        system("env");
        putenv(tst);
        system("env");
        tst[8]='\0';
        system("env");
       
        tst[0]='\0';
        putenv(tst);
        system("env");
}
gives the following result (I'm using gcc 3.0.1 ... from bullfreeware):
$ gcc aa.c        
$ ./a.out|grep NOR
NORKSEN=BLARUTIG
NORKSEN=
$  

.... so, what was it that didn't work?

-- Glenn
0
 

Author Comment

by:ekariel
ID: 10877024
NORKSEN is still there!

cf with unset which deletes the name (NORKSEN) AND the value

Ebe
0
 
LVL 20

Expert Comment

by:Gns
ID: 10877077
No, NORKSEN goes away... at least in my example.
Count the systems... One afters setting NORKSEN=BLARUTIG, one after setting NORKSEN=\0 and finally one after unsetting it.

Or do you mean that in your compile environment the silly thing doesn't produce this output?

-- Glenn
0
 

Author Comment

by:ekariel
ID: 10877268
This doesn't make sense. As I read it:

        strcpy(tst,"NORKSEN=BLARUTIG");            /* value of tst is: NORKSEN=BLARUTIG
        system("env");
        putenv(tst);
        system("env");
        tst[8]='\0';                                                /* value of tst is: NORKSEN=
        system("env");
       
        tst[0]='\0';                                                /* value of tst is:
        putenv(tst);
        system("env");

So what are you putting/deleting? And why don't you get an error? Or am I just being obtuse here???

Ebe
0
 
LVL 20

Accepted Solution

by:
Gns earned 2000 total points
ID: 10878480
The first putenv makes tst semimagical... It is now more like a reference into the environment vector. The second putenv is not necessary, apologies for that. Keep in mind that environment always propagate downwards... You cannot from a program (like a shell) run a program that will unset environment in the parent... Thus the shell builtin unset...:-).

To manipulate already set values, you can work with a char*, but this will be to the "value" part of the key-value pair... So you cannot use that to unset a value... Example:
#include <stdio.h>
#include <unistd.h>
main() {
        char tst[1200];
        char *tst2;

// This is to "illustrate" that you operate on the _value_ of TESTOLLE
        system("env");
        tst2=(char *)getenv("TESTOLLE");
        printf("TESTOLLE->%s\n",tst2);fflush(stdout);
        strcpy(tst2,NULL);
        printf("TESTOLLE->%s\n",tst2);fflush(stdout);
        system("env");
        putenv(tst2);

// This will remove TESTOLLE ... eventually:-) First get the value
        tst2=(char *)getenv("TESTOLLE");
// "Create" a new string...
        tst[0]='\0';
        sprintf(tst,"TESTOLLE=%s",tst2);
// ... and let it "take over" ...
        putenv(tst);
// ... and "kill TESTOLLE" ...
        tst[0]='\0';
        system("env");
        printf("No more TESTOLLE\n");
}

$ export TESTOLLE=ARGH
$ gcc aa.c
$ ./a.out|egrep "OLLE"
TESTOLLE=ARGH
TESTOLLE->ARGH
TESTOLLE->
TESTOLLE=
No more TESTOLLE
$

Clearer?

-- Glenn
0
 
LVL 62

Expert Comment

by:gheist
ID: 11077826
I am sure proposed answer in no way relates to question given, but I will agree with you, since it did much at educating the asker.
0
 
LVL 20

Expert Comment

by:Gns
ID: 11089038
CC gheist, this question turned out to have little to do with ksh:-).

-- Glenn
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question