how many file descriptors?
Richard Walker
walker at island.uu.net
Thu Sep 15 04:21:45 AEST 1988
In article <24889 at teknowledge-vaxc.ARPA> mkhaw at teknowledge-vaxc.UUCP (Mike Khaw) writes:
>How can a SunView program tell how many file descriptors it has in use,
>especially if it opens&closes /dev/fb several times and creates&destroys
>frames several times while it's running?
>Thanks,
>Mike Khaw
This is one of the things I hate about the Unix/Sunview combination.
Sunview uses file descriptors for its user interface objects yet
provides no control over allocation and release.
(They do get released *eventually* after the destruction).
Here are functions to determine the number of free file descriptors.
free_file_descriptors()
{
int i, n;
struct stat statb;
extern int errno;
/* There is a slop factor of 2 in the fd calculations
becuse the window system uses fd's transiently */
n = getdtablesize();
for (i = n-1; i >= 0; i--)
if (!(fstat(i, &statb) < 0 && errno == EBADF))
n--;
/* RJW reserve SunView slop of 2 and 2 for prompt dialog */
return(n-4);
}
/*
* Return a flag indicating that there are 'n' free descriptors.
*/
enough_fds(n)
int n;
{
if(n > free_file_descriptors()) {
err_prompt("There are too many panels open.\n\
Please close some panels and try again.");
return(0);
}
return(1);
}
More information about the Comp.unix.questions
mailing list