Re: Too-many-files errors on OS X - Mailing list pgsql-hackers
From | Larry Rosenman |
---|---|
Subject | Re: Too-many-files errors on OS X |
Date | |
Msg-id | 29880000.1077533342@lerlaptop.lerctr.org Whole thread Raw |
In response to | Re: Too-many-files errors on OS X (Tom Lane <tgl@sss.pgh.pa.us>) |
Responses |
Re: Too-many-files errors on OS X
|
List | pgsql-hackers |
--On Sunday, February 22, 2004 23:00:31 -0500 Tom Lane <tgl@sss.pgh.pa.us> wrote: > Kevin Brown <kevin@sysexperts.com> writes: >> I wasn't able to test on HP-UX > > I get the same result on HPUX, after whacking the test program around > a bit: no change in the number of files we can open. Confirmations on > other platforms please, anyone? > > For anyone else who has problems getting it to compile, try copying > the relevant version of pg_dlopen from src/backend/port/dynloader/. > I attach the code I actually ran on HPUX. > > regards, tom lane > On FreeBSD 5: $ ./eatfds3 /usr/local/lib/libpq.so /usr/lib/libm.so dup() failed: Too many open files Was able to use 7146 file descriptors dup() failed: Too many open files Was able to use 7146 file descriptors after opening 2 shared libs $ On UnixWare 7.1.4: $ ./eatfds3 /usr/lib/libpq.so.3 /usr/lib/libm.so.1 dup() failed: Too many open files Was able to use 2045 file descriptors dup() failed: Too many open files Was able to use 2045 file descriptors after opening 2 shared libs $ I had to hack on the code some more for FreeBSD: (the realloc call needed the multiplication). I ran this same code on UnixWare. $ cat eatfds3.c #include <stdio.h> #include <string.h> #include <errno.h> #include <stdlib.h> #include <unistd.h> #include <dlfcn.h> // these seem to be needed on HPUX: //#include <a.out.h> //#include <dl.h> int *fd; int size = 3072; void * pg_dlopen(char *filename) { /* * Use BIND_IMMEDIATE so that undefined symbols cause a failure return * from shl_load(), rather than an abort() later on when we attempt to * call the library! */ caddr_t handle = dlopen(filename, RTLD_LAZY); return (void *) handle; } int eatallfds(void) { int i = 0; int j, myfd; while (1) { myfd = dup(0); if (myfd < 0) { fprintf (stderr, "dup()failed: %s\n", strerror(errno)); break; } if (i >= size) { size*= 2; fd = realloc(fd, size * sizeof(*fd)); if (fd == NULL) { fprintf (stderr, "Can't allocate: %s\n", strerror(errno)); fprintf (stderr, "Had used %d descriptors\n", i); exit(1); } } fd[i++] = myfd; } for (j = 0 ; j < i ; ++j) { close(fd[j]); } return i; } int main (int argc, char *argv[]) { int n, na; int i; void *addr; size = 3072; fd = malloc((size + 1) * sizeof(*fd)); if (fd == NULL) { fprintf (stderr, "Can'tallocate: %s\n", strerror(errno)); return 1; } n = eatallfds(); printf ("Was able touse %d file descriptors\n", n); na = 0; for (i = 1 ; i < argc ; ++i) { addr = pg_dlopen(argv[i]); if (addr != NULL)na++; } n = eatallfds(); printf ("Was able to use %d file descriptors after opening %d shared libs\n", n, na); return 0; } $ -- Larry Rosenman http://www.lerctr.org/~ler Phone: +1 972-414-9812 E-Mail: ler@lerctr.org US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
pgsql-hackers by date: