Operating System - HP-UX
1834366 Members
2433 Online
110066 Solutions
New Discussion

select and maxfiles e maxfiles_lim

 
Benedetto Mangiapane
Frequent Advisor

select and maxfiles e maxfiles_lim

Hi,
in the HP-UX 11i OS, I've a process that perform a select routine that make an error.
The errno is EBADF.

This error happens with the change of kernel parameter maxfiles e maxfiles_lim from 2048 to 5500.

The select is:

select(max_fd, &fdProcSet, NULL, NULL, &poll_time)

where max_fd is value from getlimit:

struct rlimit rl;
rl.rlim_max = 0;

getrlimit(RLIMIT_NOFILE, &rl);
max_fd = rl.rlim_max;

and fdProcSet is:

fd_set fdProcSet

Can You help me?
Thanks.
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: select and maxfiles e maxfiles_lim

Shalom,

Several parameters may require adjustment.

maxfiles 256 - 256
maxfiles_lim 2048 Y 2048
nfile 4096 - 4096
maxuprc

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Benedetto Mangiapane
Frequent Advisor

Re: select and maxfiles e maxfiles_lim

Hi,
the kernel parameter is:

maxfiles 5500 - 5500
maxfiles_lim 5500 Y 5500
nfile 63488 - (15*NPROC+2048)
maxuprc 3686 Y ((NPROC*9)/10)

Thanks.
rick jones
Honored Contributor

Re: select and maxfiles e maxfiles_lim

There are three current-ish versions of "11i" - which one are you using?

Manpages can be your friend - from the 11.11 (11iv1) manpage:

[EBADF] One or more of the file descriptor sets specified a file descriptor that is not a valid open file descriptor. This could happen either if the file descriptor sets are not initialized or nfds argument is greater than FD_SETSIZE.

So, either the FD you passed isn't open, or you went beyond FD_SETSIZE. I would suggest printing FD_SETSIZE from your program and also running it under a verbose tusc trace to see exactly what FDs are being set in the fd_sets for the call. That may require havint tusc show both syscall entry and exit.
there is no rest for the wicked yet the virtuous have no pillows
Benedetto Mangiapane
Frequent Advisor

Re: select and maxfiles e maxfiles_lim

In the man pages of select(2) routine, I read that FD_SETSIZE is 2048. It can be set to 5500. This is not possible via kernel parameter maxfiles or maxfiles_lim.

This is the problem!

Therefore, increasing the parameter of the kernel, is necessary to remember itself of set the FD_SETSIZE value.

It's right?
Ralph Grothe
Honored Contributor

Re: select and maxfiles e maxfiles_lim

Sorry, if I dare participate though I am not a systems programmer.
But doesn't the manpage demonstrate how the user is supposed to raise the upper bound for file descriptor sets in the given sample snippet and its comments?



The FD_SETSIZE is used in the definition of fd_set structure. It is
set to a value of 2048 to accommodate 2048 file descriptors. Any user
code that uses FD_SETSIZE or the structure fd_set should redefine
FD_SETSIZE to a smaller value (greater than or equal to the number of
open files the process will have) in order to save space. Similarly,
any user code that wants to test more than 2048 file descriptors
should redefine FD_SETSIZE to the required higher value.

The user can also allocate the space for fd_set structure dynamically,
depending upon the number of file descriptors to be tested. The
following code segment illustrates the basic concepts.

int num_of_fds,s;
struct fd_set *f;

/*
* Set num_of_fds to the required value.
* User can set it to the maximum possible value the kernel is
* configured for, by using sysconf(_SC_OPEN_MAX).
* Note that, if you are not using these many files, you are
* wasting too much space.
*/
num_of_fds = sysconf(_SC_OPEN_MAX);
s = sizeof(long);
/*
* howmany is a macro defined in sys/types.h
*/
f = (struct fd_set *)malloc(s*howmany(num_of_fds, s*8);
/*
* Use f wherever struct fd_set * is used.
* It can be used to test num_of_fds file descriptors.
*/




Maybe this comment in /usr/include/sys/_fd_macros.h
also may help?


/*
* FD_SETSIZE may be defined by the user, but must be >= u.u_highestfd + 1.
* Since we know the absolute limit for the number of per process open files is
* MAXFUPLIM, we need to define FD_SETSIZE to be large enough to accomodate
* this many file descriptors. Unless the user has this many files opened, he
* should redefine FD_SETSIZE to a smaller number.
*/

Madness, thy name is system administration
Sandman!
Honored Contributor

Re: select and maxfiles e maxfiles_lim

Could you attach the source code of the routine (if it's not too big) that's causing the error. From your post it is hard to glean the context of the issue and trouble shoot it.

~thanks