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

From: Chin Fang (
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
>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: (Kevin W. Thomas)
From: (Kevin Sheehan {Consulting Poster Child})
From: Alan Chan <A.Chan@CdnAir.CA>
From: Alan Chan <alanc>
From: (Russ Poffenberger)
From: Martin Redmond <>
From: Henry Katz <>
From: ( Patrick Pawlak )
From: (Michael D. Reynolds)
From: (Glenn Satchell - Uniq Professional Services)
From: Rahul Dhesi <>

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;

#ifdef DEBUG

        int i;

        i = getrlimit( RLIMIT_NOFILE, &rlimit );

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

#ifdef DEBUG


        int i;

        rlimit.rlim_cur = rlimit.rlim_max;

        i = setrlimit( RLIMIT_NOFILE, &rlimit );

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



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

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