AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
Expand all | Collapse all

Memory leak when redirecting stderr on AIX?

  • 1.  Memory leak when redirecting stderr on AIX?

    Posted Mon December 09, 2013 11:38 AM

    Originally posted by: sarujanai


    When redirecting stderr to a log file we see a memory leak on AIX.

    Further investigation showed that the following simple test program reproduces the problem when compiled and run on AIX redirecting the output to a file, eg:

    ./test &> log.txt

    -------------------------------------------------------
    #include <unistd.h>
    #include <stdio.h>

    int main()
    {
        while (1)
        { 
            write(2, "Testing!\n", 9);
        }
    }

    -------------------------------------------------------

    You can watch the memory leaking with "svmon -P <pid>" and see the Inuse count go up and up.

    Is this a known issue?



  • 2.  Re: Memory leak when redirecting stderr on AIX?

    Posted Tue December 10, 2013 04:43 AM

    Originally posted by: Wouter Liefting


    Are you sure it's not simply a cache or buffer being filled before the data is written out to disk?

    Your program doesn't have any form of pacing in it - it will write the output text at CPU speed and your disk drivers will probably not be able to handle this firehose of data. So it's got to go somewhere in the meantime. That's not necessarily a memory leak but a welcome feature.

    What happens if you put a sleep() or maybe a flush() in there to slow things down or let the system catch up after a few megabytes? And does the same thing happen when you don't redirect stderr to a file, but let the program open the file directly?