Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Today I was trying to debug an issue where a process was not picking up the correct environmental variable. It took us hours before we realized that it wasn't picking up the correct variable.

I tried to list them using the solution here: http://serverfault.com/a/104175/90224 (ps eww [pid]), but it seems to have a character limit of something like 3155 characters, which is not even close to enough for the particular application. (It's not even done printing the command line options at that point)

Is there another method I can use on AIX to find it? I am a software developer, so I wouldn't mind a solution requiring a bit of code either.

share|improve this question

1 Answer 1

Well, with one more w you should get it all according to the man page:

ewww

Wraps display from the e flag and displays the ENV list until it reaches the INT_MAX value.

That's a pretty big limit.

If you're looking at creating yourself tools for this, you should look into the getevars and geteargs functions which ps uses for the ewww display.

Here's a naïve usage of getevars, prints its own environment (limit ~1Mb):

#include <sys/types.h>
#include <procinfo.h>
#include <unistd.h>
#include <stdio.h>

#define ENV_MAX (1024*1024)

int main(void)
{
    struct procentry64 pe;
    char buffer[ENV_MAX];
    pe.pi_pid = getpid();
    int rc = getevars(&pe, sizeof(pe), buffer, sizeof(buffer));
    if (rc != 0) {
        perror("getevars");
        return 1;
    }
    buffer[ENV_MAX-2] = buffer[ENV_MAX-1] = 0;
    char *cur = buffer;
    char *end = buffer+sizeof(buffer);
    while ((*cur) && (cur < end)) {
        int len = puts(cur);
        cur += len;
    }
    return 0;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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