Huge difference between _POSIX_OPEN_MAX and sysconf(_SC_OPEN_MAX).


 
Thread Tools Search this Thread
Top Forums Programming Huge difference between _POSIX_OPEN_MAX and sysconf(_SC_OPEN_MAX).
# 1  
Old 03-02-2010
Huge difference between _POSIX_OPEN_MAX and sysconf(_SC_OPEN_MAX).

On my Linux system there seems to be a massive difference between the value of _POSIX_OPEN_MAX and what sysconf(_SC_OPEN_MAX) returns and also what I'd expect from the table of examples of configuration limits from Advanced Programming In The UNIX Environment, 2nd Ed.

_POSIX_OPEN_MAX: 16
sysconf(_SC_OPEN_MAX): 65535

Advanced Programming In The UNIX Environment, 2nd Ed, 2005
Figure 2.14. Examples of configuration limits

OPEN_MAX:
FreeBSD 5.2.1: 1735
Linux 2.4.22: 1024
Mac OS X 10.3: 256
Solaris 9: 256

Doesn't the value of 65,535 returned by sysconf(_SC_OPEN_MAX) seem way too high?

Code:
#ifdef _POSIX_OPEN_MAX
        printf("_POSIX_OPEN_MAX: %d\n", _POSIX_OPEN_MAX);
#endif
#ifdef OPEN_MAX
    printf("OPEN_MAX: %d\n", OPEN_MAX);
#endif
#ifdef FOPEN_MAX
    printf("FOPEN_MAX: %d\n", FOPEN_MAX);
#endif

errno = 0;

long om = sysconf(_SC_OPEN_MAX);
printf("errno: %d\n", errno);
printf("_SC_OPEN_MAX: %ld\n", om);

long pcnm = pathconf("/home/gencon/up.zip", _PC_NAME_MAX);
printf("errno: %d\n", errno);
printf("_PC_NAME_MAX: %ld\n", pcnm);

long pcpm = pathconf("/home/gencon/", _PC_PATH_MAX);
printf("errno: %d\n", errno);
printf("_PC_PATH_MAX: %ld\n", pcpm);

Outputs:
_POSIX_OPEN_MAX: 16
FOPEN_MAX: 16
errno: 0
_SC_OPEN_MAX: 65535
errno: 0
_PC_NAME_MAX: 255
errno: 0
_PC_PATH_MAX: 4096

# 2  
Old 03-02-2010
No. It is controlled by the kernel and the values in limits.h provided by the people who built the kernel. On some systems it may be dynamic, others it is fixed.
You may also have _POSIX2_ values for things. See /usr/include/limits.h

FWIW -
I have an old version of solaris with _POSIX_OPEN_MAX = 16

PS: you don't have to write C code to get those values - try the getconf command.
# 3  
Old 03-02-2010
Thanks Jim and nice hint to use getconf.

The first thing I tried was: getconf _POSIX_OPEN_MAX

and got: 65535

How come in C code when I print the value of _POSIX_OPEN_MAX I get 16 but from bash with getconf I get 65535?

Confused. Smilie
# 4  
Old 03-02-2010
You have to set your #define statements to invoke what you want.
Possible examples:
Code:
#define _POSIX_C_SOURCE
#define _POSIX_SOURCE
#define _XOPEN_SOURCE 600
.........

You cannot invoke all these all at once. You really need to read up on your compiler, then REALLY read /usr/limits.h very carefully. Take notes.

On the forums, follow the standards link here, download the big ol' pdf.
UNIX IEEE Std 1003.1-2001 (POSIX.1) - The UNIX and Linux Forums

There are updates to this - I think they still show up in that link.
# 5  
Old 03-02-2010
Quote:
On the forums, follow the standards link here, download the big ol' pdf.
UNIX IEEE Std 1003.1-2001 (POSIX.1) - The UNIX and Linux Forums
IEEE Std 1003.1-2001 is no longer current. It was replaced by IEEE Std 1003.1-2008. Here is a link to this standard.

If you want to access this standard via your Firefox searchbar you can download an addon from https://addons.mozilla.org/en-US/firefox/addon/75095
# 6  
Old 03-06-2010
Quote:
Originally Posted by gencon
Thanks Jim and nice hint to use getconf.

The first thing I tried was: getconf _POSIX_OPEN_MAX

and got: 65535

How come in C code when I print the value of _POSIX_OPEN_MAX I get 16 but from bash with getconf I get 65535?

Confused. Smilie
Yeah, this is indeed somewhat confusing.

The _POSIX_OPEN_MAX that you print from you program is the limits as defined by the POSIX standard (as of IEEE 1003.1-2008, it's 20). This limit states the minimal number of files that a process can have opened at any time. That is, on a POSIX platform, it is guarantee that any process can have at least up to _POSIX_OPEN_MAX files opened.

Typically, systems like Linux support much more opened file per process that _POSIX_OPEN_MAX.

Now, the value you get with getconf _POSIX_OPEN_MAX is in fact the value obtained with sysconf(_SC_OPEN_MAX). That is, the max. number of files a process can have for the user executing the program (also, in your case what ulimit -n would return).

HTH,
Loïc.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to calculate difference of split and sum the difference

In the awk I am trying to subtract the difference $3-$2 of each matching $4 before the first _ (underscore) and print that value in $13. I think the awk will do that, but added comments. What I am not sure off is how to add a line or lines that will add sum each matching $13 value and put it in... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. UNIX for Dummies Questions & Answers

Shc script size limitation and "_SC_ARG_MAX (see sysconf(2))" parameter

I wish to change the parameter (which I do not understand exactly what it is and I wish to) and be able to use shc with very long bash scripts (2 Replies)
Discussion started by: frad
2 Replies

3. Shell Programming and Scripting

Difference between two huge .csv files

Hi all, I need help on getting difference between 2 .csv files. I have 2 large . csv files which has equal number of columns. I nned to compare them and get output in new file which will have difference olny. E.g. File1.csv Name, Date, age,number Sakshi, 16-12-2011, 22, 56 Akash,... (10 Replies)
Discussion started by: Dimple
10 Replies

4. Programming

what is the main difference between difference between using nonatomic lseek and O_APPEND

I think both write at the end of the file ...... but is there a sharp difference between those 2 instruction ..... thank you this is my 3rd question today forgive me :D (1 Reply)
Discussion started by: fwrlfo
1 Replies

5. Shell Programming and Scripting

Three Difference File Huge Data Comparison Problem.

I got three different file: Part of File 1 ARTPHDFGAA . . Part of File 2 ARTGHHYESA . . Part of File 3 ARTPOLYWEA . . (4 Replies)
Discussion started by: patrick87
4 Replies

6. AIX

Huge difference in reported Disk usage between ls,df and du

IBM RS6000 F50 AIX 4.3.2 i am having trouble in calculating the actual size of a set of directories and reconciling the results with the actual Hard Disk space used I have 33GB disk which is showing 7.8GB used, a byte count of the files in the directory/sub-dirs i`m interested in is 48GB,... (4 Replies)
Discussion started by: cooperuf
4 Replies

7. Ubuntu

kernel-huge

Hi All, I have a uname -a Linux caws101arop 2.6.9-67.0.20.ELsmp #1 SMP Wed Jun 18 12:35:02 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux And I'm having lots of problem especially when the web server got new two additional website. Before the memory was just 12G but we upgraded it to 65G. Do... (1 Reply)
Discussion started by: itik
1 Replies

8. UNIX for Dummies Questions & Answers

Difference between two huge files

Hi, As per my requirement, I need to take difference between two big files(around 6.5 GB) and get the difference to a output file without any line numbers or '<' or '>' in front of each new line. As DIFF command wont work for big files, i tried to use BDIFF instead. I am getting incorrect... (13 Replies)
Discussion started by: pyaranoid
13 Replies

9. Solaris

Huge PI in vmstat

This is something nowbody around me can explain: vmstat (-S 5) shows a huge number of PI but when I try to monitor it in parallel with iostat - there is no IO activity to be seen that would correspond to this. I have 16G RAM and 32G swap file. I'll really appreciate if somebody can explain it.... (9 Replies)
Discussion started by: dkvent
9 Replies
Login or Register to Ask a Question