[comp.sys.hp] The "getdtablesize" command

preetham@ra.src.umd.edu (Preetham Gopalaswamy) (12/18/90)

I am trying to compile a software package that was unfortunately not written
for SysV although they claim that it is.   The computer being used is an HP800
running HPUX 3.1.   One of the problems that I am facing is finding a SysV
equivalent for the command "getdtablesize" which is used (so the SUN man
pages say) to "get the descriptor table size".   What can I use instead of
this command since it does not exist on the HPs.
Any help would be appreciated.   Thanks in advance.

							Preetham Gopalaswamy

ps: You may either post the answer or send e-mail to preetham@ra.src.umd.edu

cedman@golem.ps.uci.edu (Carl Edman) (12/18/90)

In article <28687@mimsy.umd.edu> preetham@ra.src.umd.edu (Preetham Gopalaswamy) writes:
   I am trying to compile a software package that was unfortunately not written
   for SysV although they claim that it is.   The computer being used is an HP800
   running HPUX 3.1.   One of the problems that I am facing is finding a SysV
   equivalent for the command "getdtablesize" which is used (so the SUN man
   pages say) to "get the descriptor table size".   What can I use instead of
   this command since it does not exist on the HPs.
   Any help would be appreciated.   Thanks in advance.

getdtablesize() is a BSD command to find (basically) the maximum
number of files open at the same time. The corresponding HPUX command
is sysconf(_SC_OPEN_MAX). The correct include file for this is <unistd.h>.
Simply replace getdtablesize by sysconf everywhere, or better, define
getdtablesize, compile it, and add this function to your BSD library.
Then you will never again have to worry about it.

        Carl Edman



Theorectical Physicist,N.:A physicist whose  | Send mail
existence is postulated, to make the numbers |  to
balance but who is never actually observed   | cedman@golem.ps.uci.edu
in the laboratory.                           | edmanc@uciph0.ps.uci.edu

ash@hpindda.cup.hp.com (Art Harkin) (12/19/90)

/ hpindda:comp.sys.hp / preetham@ra.src.umd.edu (Preetham Gopalaswamy) /  3:00 pm  Dec 17, 1990 /

I am trying to compile a software package that was unfortunately not written
for SysV although they claim that it is.   The computer being used is an HP800
running HPUX 3.1.   One of the problems that I am facing is finding a SysV
equivalent for the command "getdtablesize" which is used (so the SUN man
pages say) to "get the descriptor table size".   What can I use instead of
this command since it does not exist on the HPs.
Any help would be appreciated.   Thanks in advance.

							Preetham Gopalaswamy

ps: You may either post the answer or send e-mail to preetham@ra.src.umd.edu
----------

rvdp@cs.vu.nl (Ronald van der Pol) (12/19/90)

preetham@ra.src.umd.edu (Preetham Gopalaswamy) writes:


=I am trying to compile a software package that was unfortunately not written
=for SysV although they claim that it is.   The computer being used is an HP800
=running HPUX 3.1.   One of the problems that I am facing is finding a SysV
=equivalent for the command "getdtablesize" which is used (so the SUN man
=pages say) to "get the descriptor table size".   What can I use instead of
=this command since it does not exist on the HPs.
=Any help would be appreciated.   Thanks in advance.
	Select and its functions are BSD features. Not all SVR3 machines
	include all the select additional functions. Maybe it is in HP's
	libbsd.a?


--
		Ronald van der Pol  <rvdp@cs.vu.nl>

ash@hpindda.cup.hp.com (Art Harkin) (12/19/90)

Reposted since previous posting cut off the answer...

In reply to:

> comp.sys.hp / preetham@ra.src.umd.edu  /  3:00 pm  Dec 17, 1990 /
>
>I am trying to compile a software package that was unfortunately not written
>for SysV although they claim that it is.   The computer being used is an HP800
>running HPUX 3.1.   One of the problems that I am facing is finding a SysV
>equivalent for the command "getdtablesize" which is used (so the SUN man
>pages say) to "get the descriptor table size".   What can I use instead of
>this command since it does not exist on the HPs.
>Any help would be appreciated.   Thanks in advance.
>
>							Preetham Gopalaswamy
>
>ps: You may either post the answer or send e-mail to preetham@ra.src.umd.edu
>
---------------------------------------------------------------------------
Try:

#include <sys/types.h>

#ifdef hpux
    t = FD_SETSIZE;
#else /* hpux */
    t = getdtablesize();
#endif /* hpux */


Art Harkin
Hewlett Packard

cedman@golem.ps.uci.edu (Carl Edman) (12/20/90)

In article <4310152@hpindda.cup.hp.com> ash@hpindda.cup.hp.com (Art Harkin) writes:
   Try:

   #include <sys/types.h>

   #ifdef hpux
       t = FD_SETSIZE;
   #else /* hpux */
       t = getdtablesize();
   #endif /* hpux */


   Art Harkin
   Hewlett Packard

How come that _no_one_ in the world, not even HP, uses its own system
call to do this ? (sysconf, a solution with which I posted a few days ago).

Also this solution is, if I understand correctly, incorrect or at
least wastefull. While FD_SETSIZE is guaranteed to be greater than
FILENO, thus it probably wouldn't cause any harm for the most common
applications, it is at least wasteful.

Also imagine, e.g., an application which has a variable number of
sockets open. This application has usually many low-priority
connections, which can be closed at a moments notice, without any harm
but must be able to accept some uncommon high-priority messages
quickly. So the application closes one low-priority connection when it
notices that its number of open connections approaches FILENO. Using
FD_SETSIZE instead of this breaks this application.

        Carl Edman



Theorectical Physicist,N.:A physicist whose  | Send mail
existence is postulated, to make the numbers |  to
balance but who is never actually observed   | cedman@golem.ps.uci.edu
in the laboratory.                           | edmanc@uciph0.ps.uci.edu

rsh@hpfcdc.HP.COM (Scott Holbrook) (12/22/90)

>>   Try:
>>
>>   #include <sys/types.h>
>>
>>   #ifdef hpux
>>       t = FD_SETSIZE;
>>   #else /* hpux */
>>       t = getdtablesize();
>>   #endif /* hpux */

> Art Harkin
> Hewlett Packard

> How come that _no_one_ in the world, not even HP, uses its own system
> call to do this ? (sysconf, a solution with which I posted a few days
> ago).

The sysconf() solution is the preferred method.  However, the submitter
stated that he was running on a HP-UX 3.1 system, which did not support
the sysconf(_SC_OPEN_MAX) call.  So, your proposed solution wouldn't
have worked for the author of the basenote.

Here is another possible solution that should work properly on all
HP-UX releases (and probably on other systems as well):

#include <stdio.h>
#include <unistd.h>

int
getdtablesize()
{
#ifdef _SC_OPEN_MAX
    return sysconf(_SC_OPEN_MAX);
#else
    return _NFILE;
#endif
}

A better solution is to modify your source code to call sysconf()
directly.  sysconf() is part of the POSIX 1003.1 standard, so should
be the most portable solution.  getdtablesize() is a BSDism, so will
probably only be available on BSD or BSD derived systems.

Scott Holbrook / rsh@hpfcla.fc.hp.com
HP-UX kernel/commands