Maximalanzahl Sockets / Filedeskriptoren?

Post Reply
Message
Author
Socke

Maximalanzahl Sockets / Filedeskriptoren?

#1 Post by Socke »

Hi,

Wie bekomme ich (gerne auch manuell) heraus, wie viele Sockets und Filedeskriptoren auf einem Systerm maximal erlaubt sind?

Jochen

Re: Maximalanzahl Sockets / Filedeskriptoren?

#2 Post by Jochen »

Das ist in den Kernelsourcen schön in der Datei Documentation/filesystems/proc.txt in Abschnitt 2.1, /proc/sys/fs, dokumentiert:<blockquote><hr>file-nr and file-max
--------------------

The kernel allocates file handles dynamically, but doesn't free them again at
this time.

The value in file-max denotes the maximum number of file handles that the
Linux kernel will allocate. When you get a lot of error messages about running
out of file handles, you might want to raise this limit. The default value is
4096. To change it, just write the new number into the file:

# cat /proc/sys/fs/file-max
4096
# echo 8192 > /proc/sys/fs/file-max
# cat /proc/sys/fs/file-max
8192

<hr></blockquote>
Da kannst Du auch noch andere interessante Sachen finden.

Jochen

Wolfgang

Re: Maximalanzahl Sockets / Filedeskriptoren?

#3 Post by Wolfgang »

Hi!

Am portabelsten (weil von POSIX vorgeschrieben) ist sysconf(_SC_OPEN_MAX) aus unistd.h, wobei man beachten sollte, dass die Funktion auch -1 zurückgeben kann, wenn es *keine* Einschränkung gibt, was in der Praxis auf, äh, mindestens einem freien Betriebsystem der Fall ist. Der Wert -1 wird auch im Falle eines Fehlers zurückgegeben, wobei dabei errno gesetzt wird. Ergo ist folgender Code korrekt:

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
long open_max;
errno = 0;
open_max = sysconf (_SC_OPEN_MAX);
if (open_max != -1)
the_limit_is (open_max);
else
if (errno)
something_went_wrong ();
else
we_do_not_have_a_limit ();
</font><hr></pre></blockquote>

Die Single Unix Specification (eine Übermenge von POSIX, erhältlich kostenlos unter www.unix-systems.org) sagt entsprechend: "As -1 is a permissible return value in a successful situation, an application wishing to check for error situations should set errno to 0, then call sysconf(), and, if it returns -1, check to see if errno is non-zero."

Cheers,
GNU/Wolfgang

Post Reply