SUMMARY:What do you do when file descriptors run out?

From: Chin Fang (fangchin@jessica.stanford.edu)
Date: Wed Sep 20 1995 - 10:44:48 CDT


Sorry about the late summary. We have been tied up by some urgent tasks.

My original inquiry:

>We are experiencing an odd problem laterly on one of our heavily used
>SS2. It seems to me some processes can't get enough file descriptors
>and thus they crash.
>The machine runs SunOS 4.1.3U1B with recommended patches. It has 32
>MEGs RAM, 230 MB swap, and 4G HD. I have adjusted the "maxusers" parm
>in the kernel configuration file from 32 to 45 without any significant
>impact.
>
>Would appreciate it very much for a suggestion for either resolving
>this or getting around the problem mentioned above.
>
>I will summarize.

Thanks to the following who responded:

From: kwthomas@wizard.nssl.uoknor.edu (Kevin W. Thomas)
From: Kevin.Sheehan@uniq.com.au (Kevin Sheehan {Consulting Poster Child})
From: Alan Chan <A.Chan@CdnAir.CA>
From: Alan Chan <alanc>
From: poffen@San-Jose.ate.slb.com (Russ Poffenberger)
From: Martin Redmond <mpr@lij.aecom.yu.edu>
From: Henry Katz <hkatz@panix.com>
From: patp@juliet.ll.mit.edu ( Patrick Pawlak )
From: reynolds@mfg.mke.ab.com (Michael D. Reynolds)
From: Glenn.Satchell@uniq.com.au (Glenn Satchell - Uniq Professional Services)
From: Rahul Dhesi <dhesi@rahul.net>

The solution ranges from using a csh wrapper (somewhat effective) to
incoporating the two system calls getrlimit() and set_limit() into the
code that caused our troubles. to ensure a process would get the max
available file descriptors.

A wrapper example:

     #! /bin/csh -f
     limit descriptors 127
     exec <your application>

A system call example:

/*
 * raise_nofile_limit...
 *
 * Raise the number of file descriptors allowed in the process.
 */

#ifndef LINT
static char limit[] = "@(#)limit.c 1.2 3/22/95";
#endif /* LINT */

#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>

struct rlimit rlimit;

raise_nofile_limit()
{
        get_limit();
        set_limit();
#ifdef DEBUG
        get_limit();
#endif
        return;
}

get_limit()
{
        int i;

        i = getrlimit( RLIMIT_NOFILE, &rlimit );

        if ( i < 0 )
        {
                perror("get_limit: RLIMIT_NOFILE\n");
                return;
        }

#ifdef DEBUG
        printf("%d/%d\n",rlimit.rlim_cur,rlimit.rlim_max);
#endif

        return;
}

set_limit()
{
        int i;

        rlimit.rlim_cur = rlimit.rlim_max;

        i = setrlimit( RLIMIT_NOFILE, &rlimit );

        if ( i < 0 )
        {
                perror("set_limit: RLIMIT_NOFILE\n");
                return;
        }

        return;
}

main()
{
    raise_nofile_limit();
}

However, after some thinking, I have come to the conclusion that
both are fixes for the time being. The cure would be switching
to NetBSD, which doesn't have such hard coded limit on # of file
descriptors and we still can run lots SunOS existing binaries
in such an environment.

Thanks to all who responded.

Chin Fang
fangchin@jessica.stanford.edu



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:10:34 CDT