connection to proc

when opening a read only connection to /proc/1/as, multiple times, lets say every 5 minutes, it returns with a value of -1, and complains too many files are open.
This happens when the application has been running for several hours. Is there a way to rectify this?

for instance:


  • Open a connection to proc to talk over.
    ProcFd = open( “/proc/1/as”, O_RDONLY );
    if( ProcFd == -1 ) {
    fprintf( stderr, “pload: Unable to access procnto: %s\n”,
    strerror( errno ) );
    fflush( stderr );
    return -1;

You have to close the connection with a close() at some point in time otherwise the program will consume all available file descriptor