*BSD News Article 5759


Return to BSD News archive

Path: sserve!manuel!munnari.oz.au!spool.mu.edu!agate!doc.ic.ac.uk!uknet!mcsun!news.funet.fi!funic!nntp.hut.fi!kampi.hut.fi!alo
From: alo@kampi.hut.fi (Antti Louko)
Newsgroups: comp.unix.bsd
Subject: Re: getdtablesize
Message-ID: <1992Sep29.142535.21001@nntp.hut.fi>
Date: 29 Sep 92 14:25:35 GMT
References: <tlukka.717504312@vipunen.hut.fi> <Bv7Dz7.C2o@BitBlocks.com>
Sender: usenet@nntp.hut.fi (Usenet pseudouser id)
Organization: Helsinki University of Technology
Lines: 25
Nntp-Posting-Host: kampi.hut.fi

In article <Bv7Dz7.C2o@BitBlocks.com> bvs@BitBlocks.com (Bakul Shah) writes:
>tlukka@vipunen.hut.fi (Tuomas Lukka) writes:
>>for(i=getdtablesize(); --i>2; close(i));
>>and getdtablesize returned something like 2000000000 and this
>>naturally would take a while to run... 

>Another culprit is popen(). It attempts to allocate an array to hold
>getdtablesize() number of descriptors and fails under zsh.

>Now I don't think what zsh is doing is wrong.  The problem is in
>the use of getdtablesize() in popen() and the code above.  What is
>needed is a system call that returns the highest *open* file
>descriptor number.

Actually, an even better solution is to have a system call

getdescriptors(firstfd,dtable,dtablesize)

int	firstfd;
int	dtable[];
int	*dtablesize;

On entry *dtablesize tells how big dtable is. On return, kernel fills
dtable with at most *dtablesize open file descriptors which are >=
firstfd.