UNIX标准及实现
UNIX标准及实现
引言
UNIX标准化
ISO C
A summary of the current level of conformanceof gcc to the 1999 version of the ISO C standard is available at http://gcc.gnu.org/c99status.html. Although the C standard was updated in 2011, we deal only with the 1999 version in this text, because the other standards haven’t yet caught up with the relevantchanges.
IEEE POSIX
- ISO/IEC 9945-1 (IEEE Standard 1003.1-1996), which includes
- IEEE Standard 1003.1-1990
- IEEE Standard 1003.1b-1993 (real-time extensions)
- IEEE Standard 1003.1c-1995 (pthreads)
- IEEE Standard 1003.1i-1995 (real-time technical corrigenda)
- IEEE P1003.1a draft standard (system interface amendment)
- IEEE Standard 1003.1d-1999 (advanced real-time extensions)
- IEEE Standard 1003.1j-2000 (more advanced real-time extensions)
- IEEE Standard 1003.1q-2000 (tracing)
- Parts of IEEE Standard 1003.1g-2000 (protocol-independent interfaces)
- ISO/IEC 9945-2 (IEEE Standard 1003.2-1993)
- IEEE P1003.2b draft standard (shell and utilities amendment)
- IEEE Standard 1003.2d-1994 (batch extensions)
- The Base Specifications of the Single UNIX Specification, version 2, which include
- System Interface Definitions, Issue 5
- Commands and Utilities, Issue 5
- System Interfaces and Headers, Issue5
- Open Group Technical Standard, Networking Services, Issue 5.2
- ISO/IEC 9899:1999, Programming Languages–C
- IEEE Standard 1003.1, 2004 Edition
- Open Group Technical Standard, 2006, Extended API Set, Parts 1–4
- ISO/IEC 9899:1999, including corrigenda
Header | FreeBSD 8.0 | Linux 3.2.0 | Mac OS X 10.6.8 | Solaris 10 | Description |
<aio.h> | • | • | • | • | asynchronous I/O |
<cpio.h> | • | • | • | • | cpio archive values |
<dirent.h> | • | • | • | • | directory entries |
<dlfcn.h> | • | • | • | • | dynamic linking |
<fcntl.h> | • | • | • | • | file control |
<fnmatch.h> | • | • | • | • | filename-matching types |
<glob.h> | • | • | • | • | pathname pattern-matching and generation |
<grp.h> | • | • | • | • | group file |
<iconv.h> | • | • | • | • | codeset conversion utility |
<langinfo.h> | • | • | • | • | language information constants |
<monetary.h> | • | • | • | • | monetarytypes and functions |
<netdb.h> | • | • | • | • | network database operations |
<nl_types.h> | • | • | • | • | message catalogs |
<poll.h> | • | • | • | • | poll function |
<pthread.h> | • | • | • | • | threads |
<pwd.h> | • | • | • | • | password file |
<regex.h> | • | • | • | • | regular expressions |
<sched.h> | • | • | • | • | execution scheduling |
<semaphore.h> | • | • | • | • | semaphores |
<strings.h> | • | • | • | • | string operations |
<tar.h> | • | • | • | • | tar archive values |
<termios.h> | • | • | • | • | terminal I/O |
<unistd.h> | • | • | • | • | symbolic constants |
<wordexp.h> | • | • | • | • | word-expansion definitions |
<arpa/inet.h> | • | • | • | • | Internet definitions |
<net/if.h> | • | • | • | • | socket local interfaces |
<netinet/in.h> | • | • | • | • | Internet address family |
<netinet/tcp.h> | • | • | • | • | Transmission Control Protocol definitions |
<sys/mman.h> | • | • | • | • | memory management declarations |
<sys/select.h> | • | • | • | • | select function |
<sys/socket.h> | • | • | • | • | sockets interface |
<sys/stat.h> | • | • | • | • | file status |
<sys/statvfs.h> | • | • | • | • | file system information |
<sys/times.h> | • | • | • | • | process times |
<sys/types.h> | • | • | • | • | primitive system data types |
<sys/un.h> | • | • | • | • | UNIX domain socket definitions |
<sys/utsname.h> | • | • | • | • | system name |
<sys/wait.h> | • | • | • | • | process control |
Header | FreeBSD 8.0 | Linux 3.2.0 | Mac OS X 10.6.8 | Solaris 10 | Description |
<fmtmsg.h> | • | • | • | • | message display structures |
<ftw.h> | • | • | • | • | file tree walking |
<libgen.h> | • | • | • | • | pathname management functions |
<ndbm.h> | • | • | • | database operations | |
<search.h> | • | • | • | • | search tables |
<syslog.h> | • | • | • | • | system error logging |
<utmpx.h> | • | • | • | • | user accounting database |
<sys/ipc.h> | • | • | • | • | IPC |
<sys/msg.h> | • | • | • | • | XSI message queues |
<sys/resource.h> | • | • | • | • | resource operations |
<sys/sem.h> | • | • | • | • | XSI semaphores |
<sys/shm.h> | • | • | • | • | XSI shared memory |
<sys/time.h> | • | • | • | • | time types |
<sys/uio.h> | • | • | • | • | vector I/O operations |
Header | FreeBSD 8.0 | Linux 3.2.0 | Mac OS X 10.6.8 | Solaris 10 | Description |
<mqueue.h> | • | • | • | • | message queues |
<spawn.h> | • | • | • | • | real-time spawn interface |
Code | SUS mandatory |
Symbolic constant | Description |
ADV | _POSIX_ADVISORY_INFO | advisory information (real-time) | |
CPT | _POSIX_CPUTIME | process CPU time clocks (real-time) | |
FSC | _POSIX_FSYNC | file synchronization | |
IP6 | _POSIX_IPV6 | IPv6 interfaces | |
ML | _POSIX_MEMLOCK | process memory locking (real-time) | |
MLR | _POSIX_MEMLOCK_RANGE | memory range locking (real-time) | |
MON | _POSIX_MONOTONIC_CLOCK | monotonicclock (real-time) | |
MSG | _POSIX_MESSAGE_PASSING | message passing (real-time) | |
MX | _ _STDC_IEC_559_ _ | IEC 60559 floating-point option | |
PIO | _POSIX_PRIORITIZED_IO | prioritized input and output | |
PS | _POSIX_PRIORITY_SCHEDULING | process scheduling(real-time) | |
RPI | _POSIX_THREAD_ROBUST_PRIO_INHERIT | robust mutex priority inheritance(real-time) | |
RPP | _POSIX_THREAD_ROBUST_PRIO_PROTECT | robust mutexpriority protection (real-time) | |
RS | _POSIX_RAW_SOCKETS | raw sockets | |
SHM | _POSIX_SHARED_MEMORY_OBJECTS | shared memory objects (real-time) | |
SIO | _POSIX_SYNCHRONIZED_IO | synchronizedinput and output (real-time) | |
SPN | _POSIX_SPAWN | spawn(real-time) | |
SS | POSIX_SPORADIC_SERVER | process sporadicserver (real-time) | |
TCT | _POSIX_THREAD_CPUTIME | thread CPU time clocks (real-time) | |
TPI | _POSIX_THREAD_PRIO_INHERIT | nonrobust mutex priority inheritance (real-time) | |
TPP | _POSIX_THREAD_PRIO_PROTECT | nonrobust mutex priority protection (real-time) | |
TPS | _POSIX_THREAD_PRIORITY_SCHEDULING | thread execution scheduling(real-time) | |
TSA | _POSIX_THREAD_ATTR_STACKADDR | thread stack address attribute | |
TSH | _POSIX_THREAD_PROCESS_SHARED | thread process-shared synchronization | |
TSP | _POSIX_THREAD_SPORADIC_SERVER | thread sporadicserver (real-time) | |
TSS | _POSIX_THREAD_ATTR_STACKSIZE | thread stack size address | |
TYM | _POSIX_TYPED_MEMORY_OBJECTS | typed memory objects (real-time) | |
XSI | _XOPEN_UNIX | X/Open interfaces |
Single UNIX Specification
The Open Group owns the UNIX trademark and uses the Single UNIX Specification to define the interfaces an implementation must support to call itself a UNIX system. Vendorsmust file conformance statements, pass test suitesto verify conformance, and licensethe right to use the UNIX trademark
UNIX系统实现
First Edition (V1)
|
Second Edition (V2)
|
Third Edition (V3)
|
Fourth Edition (V4)
|
Fifth Edition (V5)
|
Sixth Edition (V6) -----*
\ |
\ |
\ |
Seventh Edition (V7) |
\ |
\ 1BSD
32V |
\ 2BSD---------------*
\ / |
\ / |
\/ |
3BSD |
| |
4.0BSD 2.7.9BSD
| |
4.1BSD --------------> 2.8BSD
| |
4.1aBSD -----------\ |
| \ |
4.1bBSD \ |
| \ |
*------ 4.1cBSD --------------> 2.9BSD
/ | |
Eighth Edition | 2.9BSD-Seismo
| | |
+----<--- 4.2BSD 2.9.1BSD
| | |
+----<--- 4.3BSD -------------> 2.10BSD
| | / |
Ninth Edition | / 2.10.1BSD
| 4.3BSD Tahoe-----+ |
| | \ |
| | \ |
v | 2.11BSD
Tenth Edition | |
| 2.11BSD rev #430
4.3BSD NET/1 |
| v
4.3BSD Reno
|
*---------- 4.3BSD NET/2 -------------------+-------------*
| | | |
386BSD 0.0 | | BSD/386 ALPHA
| | | |
386BSD 0.1 ------------>+ | BSD/386 0.3.[13]
| \ | 4.4BSD Alpha |
| 386BSD 1.0 | | BSD/386 0.9.[34]
| | 4.4BSD |
| | / | |
| | 4.4BSD-Encumbered | |
| NetBSD 0.8 | BSD/386 1.0
| | | |
FreeBSD 1.0 NetBSD 0.9 | BSD/386 1.1
| | .----- 4.4BSD Lite |
FreeBSD 1.1 | / / | \ |
| | / / | \ |
FreeBSD 1.1.5 .---|--------' / | \ |
| / | / | \ |
FreeBSD 1.1.5.1 / | / | \ |
| / NetBSD 1.0 <-' | \ |
| / | | \ |
FreeBSD 2.0 <--' | | BSD/OS 2.0
| \ | |
FreeBSD 2.0.5 \ | BSD/OS 2.0.1
| .-----\------------- 4.4BSD Lite2 |
| | \ | | | | |
| | .-----|------Rhapsody | | | |
| | | | NetBSD 1.3 | | |
| | | | OpenBSD 2.3 | |
| | | | BSD/OS 3.0 |
FreeBSD 2.1 | | | |
| | | | NetBSD 1.1 ------. BSD/OS 2.1
| FreeBSD 2.1.5 | | | \ |
| | | | NetBSD 1.2 \ BSD/OS 3.0
| FreeBSD 2.1.6 | | | \ OpenBSD 2.0 |
| | | | | \ | |
| FreeBSD 2.1.6.1 | | | \ | |
| | | | | \ | |
| FreeBSD 2.1.7 | | | | | |
| | | | | NetBSD 1.2.1 | |
| FreeBSD 2.1.7.1 | | | | |
| | | | | |
| | | | | |
*-FreeBSD 2.2 | | | | |
| \ | | | | |
| FreeBSD 2.2.1 | | | | |
| | | | | | |
| FreeBSD 2.2.2 | | | OpenBSD 2.1 |
| | | | | | |
| FreeBSD 2.2.5 | | | | |
| | | | | OpenBSD 2.2 |
| | | | NetBSD 1.3 | |
| FreeBSD 2.2.6 | | | | | |
| | | | | NetBSD 1.3.1 | BSD/OS 3.1
| | | | | | OpenBSD 2.3 |
| | | | | NetBSD 1.3.2 | |
| FreeBSD 2.2.7 | | | | | |
| | | | | | | BSD/OS 4.0
| v | | | | | |
| FreeBSD 2.2.8 | | | | | |
| | | | | OpenBSD 2.4 |
FreeBSD 3.0 <--------* | | v | |
| | | NetBSD 1.3.3 | |
*---FreeBSD 3.1 | | | |
| | | | | BSD/OS 4.0.1
| FreeBSD 3.2----* | NetBSD 1.4 OpenBSD 2.5 |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| FreeBSD 3.3 | | | | NetBSD 1.4.1 | |
| | | | | | | OpenBSD 2.6 |
| FreeBSD 3.4 | | | | | | |
| | | | | | | | BSD/OS 4.1
FreeBSD 4.0 | | | | | NetBSD 1.4.2 | |
| | | | | | | | |
| | | | | | | | |
| FreeBSD 3.5 | | | | | OpenBSD 2.7 |
| | | | | | | | |
| FreeBSD 3.5.1 | | | | | | |
| | | | | | | |
*---FreeBSD 4.1 | | | | | | |
| | | | (?) | | | |
| FreeBSD 4.1.1 | | / | | | |
| | | | / | | | |
| FreeBSD 4.2 Darwin/ | NetBSD 1.4.3 | |
| | Mac OS X | OpenBSD 2.8 BSD/OS 4.2
| | | | | |
| | | | | |
| | 10.0 NetBSD 1.5 | |
| FreeBSD 4.3 | | | | |
| | | | | OpenBSD 2.9 |
| | | | NetBSD 1.5.1 | |
| | | | | | |
| FreeBSD 4.4-. | | NetBSD 1.5.2 | |
| | | Mac OS X | | | |
| | | 10.1 | | OpenBSD 3.0 |
| FreeBSD 4.5 | | | | | |
| | \ | | | | BSD/OS 4.3
| FreeBSD 4.6 \ | | | OpenBSD 3.1 |
| | \ | | NetBSD 1.5.3 | |
| FreeBSD 4.6.2 Mac OS X | | |
| | 10.2 | | |
| FreeBSD 4.7 | | | |
| | | NetBSD 1.6 OpenBSD 3.2 |
| FreeBSD 4.8 | | | | |
| | | | NetBSD 1.6.1 | |
| |--------. | | | OpenBSD 3.3 BSD/OS 5.0
| | \ | | | | |
| FreeBSD 4.9 | | | | OpenBSD 3.4 BSD/OS 5.1 ISE
| | | | | | |
| | | | | NetBSD 1.6.2 |
| | | | | | |
| | | | | | OpenBSD 3.5
| | | | | v |
| FreeBSD 4.10 | | | |
| | | | | |
| FreeBSD 4.11 | | | |
| | | | | |
| v `-|------|-----------------|---------------------.
| | | | \
FreeBSD 5.0 | | | |
| | | | |
FreeBSD 5.1 | | | DragonFly 1.0
| \ | | | |
| ----- Mac OS X | | |
| 10.3 | | |
FreeBSD 5.2 | | | |
| | | | | |
| FreeBSD 5.2.1 | | | |
| | | | |
*---FreeBSD 5.3 | | | |
| | | | OpenBSD 3.6 |
| | | NetBSD 2.0 | |
| | | | | | | DragonFly 1.2.0
| | Mac OS X | | NetBSD 2.0.2 | |
| FreeBSD 5.4 10.4 | | | | |
| | | | | | OpenBSD 3.7 |
| V | | | NetBSD 2.0.3 | |
| | | | | | |
*---FreeBSD 6.0 | | | v OpenBSD 3.8 |
| | | | | | |
| V | | \ | |
| | | NetBSD 2.1 | |
| | | | |
| | NetBSD 3.0 | |
| | | | DragonFly 1.4.0
| | | | |
FreeBSD 7 -current | NetBSD -current OpenBSD -current |
| | | | |
v v v v v
SVR4
4.4BSD
FreeBSD
Several other BSD-based free operating systems are available. The NetBSD project (http://www.netbsd.org) is similar to the FreeBSD project, but emphasizesportability between hardware platforms. The OpenBSD project (http://www.openbsd.org) is similar to FreeBSD but places a greater emphasis on security.
Linux
Mac OS X
Solaris
Other UNIX System
标准和实现的关系
限制
Name | Description | Minimum acceptable value |
Typical value |
CHAR_BIT | bits in a char | 8 | 8 |
CHAR_MAX | max value of char | (see later) | 127 |
CHAR_MIN | min value of char | (see later) | -128 |
SCHAR_MAX | max value of signed char | 127 | 127 |
SCHAR_MIN | min value of signed char | −127 | −128 |
UCHAR_MAX | max value of unsigned char | 255 | 255 |
INT_MAX | max value of int | 32,767 | 2,147,483,647 |
INT_MIN | min value of int | −32,767 | −2,147,483,648 |
UINT_MAX | max value of unsigned int | 65,535 | 4,294,967,295 |
SHRT_MAX | max value of short | 32,767 | 32,767 |
SHRT_MIN | min value of short | −32,767 | −32,768 |
USHRT_MAX | max value of unsigned short | 65,535 | 65,535 |
LONG_MAX | max value of long | 2,147,483,647 | 2,147,483,647 |
LONG_MIN | min value of long | −2,147,483,647 | −2,147,483,648 |
ULONG_MAX | max value of unsigned long | 4,294,967,295 | 4,294,967,295 |
LLONG_MAX | max value of long long | 9,223,372,036,854,775,807 | 9,223,372,036,854,775,807 |
LLONG_MIN | min value of long long | −9,223,372,036,854,775,807 | −9,223,372,036,854,775,808 |
ULLONG_MAX | max value of unsigned long long |
18,446,744,073,709,551,615 | 18,446,744,073,709,551,615 |
MB_LEN_MAX | max number of bytes multibyte character constant |
1 | 6 |
ISO C限制
Limit | FreeBSD 8.0 |
Linux 3.2.0 |
Mac OS X 10.6.8 |
Solaris 10 |
FOPEN_MAX | 20 | 16 | 20 | 20 |
TMP_MAX | 308,915,776 | 238,328 | 308,915,776 | 17,576 |
FILENAME_MAX | 1024 | 4096 | 1024 | 1024 |
POSIX限制
Name | Description: minimum acceptable value for maximum ... | Value |
_POSIX_ARG_MAX | length of arguments to exec functions | 4,096 |
_POSIX_CHILD_MAX | number of child processes at a time per real user ID | 25 |
_POSIX_DELAYTIMER_MAX | number of timer expiration overruns | 32 |
_POSIX_HOST_NAME_MAX | length of a host name as returned by gethostname | 255 |
_POSIX_LINK_MAX | number of links to a file | 8 |
_POSIX_LOGIN_NAME_MAX | length of a login name | 9 |
_POSIX_MAX_CANON | number of bytes on a terminal’s canonicalinput queue | 255 |
_POSIX_MAX_INPUT | space available on a terminal’s input queue | 255 |
_POSIX_NAME_MAX | number of bytes in a filename, not including the terminating null | 14 |
_POSIX_NGROUPS_MAX | number of simultaneous supplementarygroup IDs per process | 8 |
_POSIX_OPEN_MAX | maximum number of open files per process | 20 |
_POSIX_PATH_MAX | number of bytes in a pathname, including the terminating null | 256 |
_POSIX_PIPE_BUF | number of bytes that can be written atomicallyto a pipe | 512 |
_POSIX_RE_DUP_MAX | number of repeated occurrencesof a basic regular expression permittedby the regexec and regcomp functions when using the interval notation\{m,n\} | 255 |
_POSIX_RTSIG_MAX | number of real-time signal numbers reservedfor applications | 8 |
_POSIX_SEM_NSEMS_MAX | number of semaphores a process can have in use at one time | 256 |
_POSIX_SEM_VALUE_MAX | value a semaphore can hold | 32,767 |
_POSIX_SIGQUEUE_MAX | number of queued signals a process can send and have pending | 32 |
_POSIX_SSIZE_MAX | value that can be stored in ssize_t object | 32,767 |
_POSIX_STREAM_MAX | number of standard I/O streams a process can have open at once | 8 |
_POSIX_SYMLINK_MAX | number of bytes in a symbolic link | 255 |
_POSIX_SYMLOOP_MAX | number of symbolic links that can be traversedduring pathname resolution |
8 |
_POSIX_TIMER_MAX | number of timers per process | 32 |
_POSIX_TTY_NAME_MAX | length of a terminal device name, including the terminating null | 9 |
_POSIX_TZNAME_MAX | number of bytes for the name of a time zone | 6 |
A strictlyconforming POSIX application is different from an application that is merelyPOSIX conforming. A POSIX-conforming application uses only interfaces defined in IEEE Standard 1003.1-2008. A strictly conforming POSIX application must meet further restrictions, such as not relying on any undefined behavior, not using any obsolescentinterfaces, and not requiringvalues of constants larger than the minimums shown in Figure 2.8.
Name | Description | Minimum acceptable value |
ARG_MAX | maximum length of arguments to exec functions |
_POSIX_ARG_MAX |
ATEXIT_MAX | maximum number of functions that can be registered with the atexit function | 32 |
CHILD_MAX | maximum number of child processes per real user ID |
_POSIX_CHILD_MAX |
DELAYTIMER_MAX | maximum number of timer expiration overruns | _POSIX_DELAYTIMER_MAX |
HOST_NAME_MAX | maximum length of a host name as returned by gethostname | _POSIX_HOST_NAME_MAX |
LOGIN_NAME_MAX | maximum length of a login name | _POSIX_LOGIN_NAME_MAX |
OPEN_MAX | one more than the maximum value assigned to a newly created file descriptor 赋予新建文件描述符的最大值+1 |
_POSIX_OPEN_MAX |
PAGESIZE | system memory page size, in bytes | 1 |
RTSIG_MAX | maximum number of real-time signals reserved for application use | _POSIX_RTSIG_MAX |
SEM_NSEMS_MAX | maximum number of semaphoresa process can use |
_POSIX_SEM_NSEMS_MAX |
SEM_VALUE_MAX | maximum value of a semaphore | _POSIX_SEM_VALUE_MAX |
SIGQUEUE_MAX | maximum number of signals that can be queued for a process |
_POSIX_SIGQUEUE_MAX |
STREAM_MAX | maximum number of standard I/O streams a process can have open at once |
_POSIX_STREAM_MAX |
SYMLOOP_MAX | number of symboliclinks that can be traversedduring pathname resolution | _POSIX_SYMLOOP_MAX |
TIMER_MAX | maximum number of timers per process | _POSIX_TIMER_MAX |
TTY_NAME_MAX | length of a terminal device name, including the terminating null |
_POSIX_TTY_NAME_MAX |
TZNAME_MAX | number of bytes for the name of a time zon | _POSIX_TZNAME_MAX |
XSI限制
Name | Description | Minimum acceptable value |
Typical value |
NL_LANGMAX | maximum number of bytes in LANG environment variable |
14 | 14 |
NZERO | default process priority | 20 | 20 |
_XOPEN_IOV_MAX | maximum number of iovec structures that can be used with readv or writev |
16 | 16 |
_XOPEN_NAME_MAX | number of bytes in a filename | 255 | 255 |
_XOPEN_PATH_MAX | number of bytes in a pathname | 1024 | 1024 |
函数sysconfi、pathconf、fpathconf
#include<unistd.h>
long sysconf(int name);
long pathconf(constchar*pathname,int name);
long fpathconf(int fd,int name);
All three return: corresponding value if OK,−1 on error (see later)
Name of limit | Description | name argument |
ARG_MAX | maximum length, in bytes, of arguments to the exec functions | _SC_ARG_MAX |
ATEXIT_MAX | maximum number of functions that can be registered with the atexit function | _SC_ATEXIT_MAX |
CHILD_MAX | maximum number of processes per real user ID | _SC_CHILD_MAX |
clock ticks/second | number of clock ticksper second | _SC_CLK_TCK |
COLL_WEIGHTS_MAX | maximum number of weightsthat can be assignedto an entry of the LC_COLLATE order keyword in the locale definition file | _SC_COLL_WEIGHTS_MAX |
DELAYTIMER_MAX | maximum number of timer expiration overruns | _SC_DELAYTIMER_MAX |
HOST_NAME_MAX | maximum length of a host name as returned by gethostname | _SC_HOST_NAME_MAX |
IOV_MAX | maximum number of iovec structures that can be used with readv or writev | _SC_IOV_MAX |
LINE_MAX | maximum length of a utility’s input line | _SC_LINE_MAX |
LOGIN_NAME_MAX | maximum length of a login name | _SC_LOGIN_NAME_MAX |
NGROUPS_MAX | maximum number of simultaneous supplementaryprocess group IDs per process | _SC_NGROUPS_MAX |
OPEN_MAX | one more than the maximum value assigned to a newly created file descriptor | _SC_OPEN_MAX |
PAGESIZE | system memory page size, in bytes | _SC_PAGESIZE |
PAGE_SIZE | system memory page size, in bytes | _SC_PAGE_SIZE |
RE_DUP_MAX | number of repeated occurrencesof a basic regular expression permittedby the regexec and regcomp functions when using the interval notation\{m,n\} | _SC_RE_DUP_MAX |
RTSIG_MAX | maximum number of real-time signals reservedfor application use | _SC_RTSIG_MAX |
SEM_NSEMS_MAX | maximum number of semaphoresa process can use at one time | _SC_SEM_NSEMS_MAX |
SEM_VALUE_MAX | maximum value of a semaphore | _SC_SEM_VALUE_MAX |
SIGQUEUE_MAX | maximum number of signals that can be queued for a process | _SC_SIGQUEUE_MAX |
STREAM_MAX | maximum number of standard I/O streams per process at any given time; if defined, it must have the same value as FOPEN_MAX | _SC_STREAM_MAX |
SYMLOOP_MAX | number of symboliclinks that can be traversedduring pathname resolution | _SC_SYMLOOP_MAX |
TIMER_MAX | maximum number of timers per process | _SC_TIMER_MAX |
TTY_NAME_MAX | length of a terminal device name, including the terminating null | _SC_TTY_NAME_MAX |
TZNAME_MAX | maximum number of bytes for a time zone name | _SC_TZNAME_MAX |
Name of limit | Description | name argument |
FILESIZEBITS | minimum number of bits needed to represent, as a signed integer value, the maximum size of a regularfile allowed in the specified directory | _PC_FILESIZEBITS |
LINK_MAX | maximum value of a file’s link count | _PC_LINK_MAX |
MAX_CANON | maximum number of bytes on a terminal’s canonicalinput queue |
_PC_MAX_CANON |
MAX_INPUT | number of bytes for which space is available on terminal’s input queue |
_PC_MAX_INPUT |
NAME_MAX | maximum number of bytes in a filename (does not include a null at end) |
_PC_NAME_MAX |
PATH_MAX | maximum number of bytes in a relative pathname, including the terminating null |
_PC_PATH_MAX |
PIPE_BUF | maximum number of bytes that can be written atomicallyto a pipe |
_PC_PIPE_BUF |
_POSIX_TIMESTAMP_RESOLUTION | resolutionin nanoseconds for file timestamps | _PC_TIMESTAMP_RESOLUTION |
SYMLINK_MAX | number of bytes in a symboliclink | _PC_SYMLINK_MAX |
# firewaywei 2016年 08月 18日 星期四 21:22:13 CST
#!/usr/bin/awk -f
BEGIN {
printf("#include \"apue.h\"\n")
printf("#include <errno.h>\n")
printf("#include <limits.h>\n")
printf("\n")
printf("static void pr_sysconf(char *, int);\n")
printf("static void pr_pathconf(char *, char *, int);\n")
printf("\n")
printf("int\n")
printf("main(int argc, char *argv[])\n")
printf("{\n")
printf("\tif (argc != 2)\n")
printf("\t\terr_quit(\"usage: a.out <dirname>\");\n\n")
FS="\t+"
while(getline <"sysconf.sym">0){
printf("#ifdef %s\n", $1)
printf("\tprintf(\"%s defined to be %%ld\\n\", (long)%s + 0);\n",
$1, $1)
printf("#else\n")
printf("\tprintf(\"no symbol for %s\\n\");\n", $1)
printf("#endif\n")
printf("#ifdef %s\n", $2)
printf("\tpr_sysconf(\"%s =\", %s);\n", $1, $2)
printf("#else\n")
printf("\tprintf(\"no symbol for %s\\n\");\n", $2)
printf("#endif\n")
printf("\n")
}
close("sysconf.sym")
printf("\n\n")
while(getline <"pathconf.sym">0){
printf("#ifdef %s\n", $1)
printf("\tprintf(\"%s defined to be %%ld\\n\", (long)%s+0);\n",
$1, $1)
printf("#else\n")
printf("\tprintf(\"no symbol for %s\\n\");\n", $1)
printf("#endif\n")
printf("#ifdef %s\n", $2)
printf("\tpr_pathconf(\"%s =\", argv[1], %s);\n", $1, $2)
printf("#else\n")
printf("\tprintf(\"no symbol for %s\\n\");\n", $2)
printf("#endif\n")
printf("\n")
}
close("pathconf.sym")
exit
}
END {
printf("\texit(0);\n")
printf("}\n\n")
printf("static void\n")
printf("pr_sysconf(char *mesg, int name)\n")
printf("{\n")
printf("\tlong val;\n\n")
printf("\tfputs(mesg, stdout);\n")
printf("\terrno = 0;\n")
printf("\tif ((val = sysconf(name)) < 0) {\n")
printf("\t\tif (errno != 0) {\n")
printf("\t\t\tif (errno == EINVAL)\n")
printf("\t\t\t\tfputs(\" (not supported)\\n\", stdout);\n")
printf("\t\t\telse\n")
printf("\t\t\t\terr_sys(\"sysconf error\");\n")
printf("\t\t} else {\n")
printf("\t\t\tfputs(\" (no limit)\\n\", stdout);\n")
printf("\t\t}\n")
printf("\t} else {\n")
printf("\t\tprintf(\" %%ld\\n\", val);\n")
printf("\t}\n")
printf("}\n\n")
printf("static void\n")
printf("pr_pathconf(char *mesg, char *path, int name)\n")
printf("{\n")
printf("\tlong val;\n")
printf("\n")
printf("\tfputs(mesg, stdout);\n")
printf("\terrno = 0;\n")
printf("\tif ((val = pathconf(path, name)) < 0) {\n")
printf("\t\tif (errno != 0) {\n")
printf("\t\t\tif (errno == EINVAL)\n")
printf("\t\t\t\tfputs(\" (not supported)\\n\", stdout);\n")
printf("\t\t\telse\n")
printf("\t\t\t\terr_sys(\"pathconf error, path = %%s\", path);\n")
printf("\t\t} else {\n")
printf("\t\t\tfputs(\" (no limit)\\n\", stdout);\n")
printf("\t\t}\n")
printf("\t} else {\n")
printf("\t\tprintf(\" %%ld\\n\", val);\n")
printf("\t}\n")
printf("}\n")
}
#ifdef NAME_MAX
printf("NAME_MAX defined to be %ld\n",(long)NAME_MAX+0);
#else
printf("no symbol for NAME_MAX\n");
#endif
#ifdef _PC_NAME_MAX
pr_pathconf("NAME_MAX =", argv[1], _PC_NAME_MAX);
#else
printf("no symbol for _PC_NAME_MAX\n");
#endif
/**
* 文件名: standards/conf.c
* 内容: 由makeconf.awk脚本自动生成
* 时间:2016年 08月 19日 星期五 21:10:48 CST
* 作者:firewaywei
*/
#include"apue.h"
#include<errno.h>
#include<limits.h>
staticvoid pr_sysconf(char*,int);
staticvoid pr_pathconf(char*,char*,int);
int
main(int argc,char*argv[])
{
if(argc !=2)
err_quit("usage: a.out <dirname>");
#ifdef ARG_MAX
printf("ARG_MAX defined to be %ld\n",(long)ARG_MAX +0);
#else
printf("no symbol for ARG_MAX\n");
#endif
#ifdef _SC_ARG_MAX
pr_sysconf("ARG_MAX =", _SC_ARG_MAX);
#else
printf("no symbol for _SC_ARG_MAX\n");
#endif
#ifdef ATEXIT_MAX
printf("ATEXIT_MAX defined to be %ld\n",(long)ATEXIT_MAX +0);
#else
printf("no symbol for ATEXIT_MAX\n");
#endif
#ifdef _SC_ATEXIT_MAX
pr_sysconf("ATEXIT_MAX =", _SC_ATEXIT_MAX);
#else
printf("no symbol for _SC_ATEXIT_MAX\n");
#endif
#ifdef CHARCLASS_NAME_MAX
printf("CHARCLASS_NAME_MAX defined to be %ld\n",(long)CHARCLASS_NAME_MAX +0);
#else
printf("no symbol for CHARCLASS_NAME_MAX\n");
#endif
#ifdef _SC_CHARCLASS_NAME_MAX
pr_sysconf("CHARCLASS_NAME_MAX =", _SC_CHARCLASS_NAME_MAX);
#else
printf("no symbol for _SC_CHARCLASS_NAME_MAX\n");
#endif
#ifdef CHILD_MAX
printf("CHILD_MAX defined to be %ld\n",(long)CHILD_MAX +0);
#else
printf("no symbol for CHILD_MAX\n");
#endif
#ifdef _SC_CHILD_MAX
pr_sysconf("CHILD_MAX =", _SC_CHILD_MAX);
#else
printf("no symbol for _SC_CHILD_MAX\n");
#endif
#ifdef CLOCKTICKSPERSECOND /*clock ticks/second*/
printf("CLOCKTICKSPERSECOND /*clock ticks/second*/ defined to be %ld\n",(long)CLOCKTICKSPERSECOND /*clock ticks/second*/+0);
#else
printf("no symbol for CLOCKTICKSPERSECOND /*clock ticks/second*/\n");
#endif
#ifdef _SC_CLK_TCK
pr_sysconf("CLOCKTICKSPERSECOND /*clock ticks/second*/ =", _SC_CLK_TCK);
#else
printf("no symbol for _SC_CLK_TCK\n");
#endif
#ifdef COLL_WEIGHTS_MAX
printf("COLL_WEIGHTS_MAX defined to be %ld\n",(long)COLL_WEIGHTS_MAX +0);
#else
printf("no symbol for COLL_WEIGHTS_MAX\n");
#endif
#ifdef _SC_COLL_WEIGHTS_MAX
pr_sysconf("COLL_WEIGHTS_MAX =", _SC_COLL_WEIGHTS_MAX);
#else
printf("no symbol for _SC_COLL_WEIGHTS_MAX\n");
#endif
#ifdef DELAYTIMER_MAX
printf("DELAYTIMER_MAX defined to be %ld\n",(long)DELAYTIMER_MAX +0);
#else
printf("no symbol for DELAYTIMER_MAX\n");
#endif
#ifdef _SC_DELAYTIMER_MAX
pr_sysconf("DELAYTIMER_MAX =", _SC_DELAYTIMER_MAX);
#else
printf("no symbol for _SC_DELAYTIMER_MAX\n");
#endif
#ifdef HOST_NAME_MAX
printf("HOST_NAME_MAX defined to be %ld\n",(long)HOST_NAME_MAX +0);
#else
printf("no symbol for HOST_NAME_MAX\n");
#endif
#ifdef _SC_HOST_NAME_MAX
pr_sysconf("HOST_NAME_MAX =", _SC_HOST_NAME_MAX);
#else
printf("no symbol for _SC_HOST_NAME_MAX\n");
#endif
#ifdef IOV_MAX
printf("IOV_MAX defined to be %ld\n",(long)IOV_MAX +0);
#else
printf("no symbol for IOV_MAX\n");
#endif
#ifdef _SC_IOV_MAX
pr_sysconf("IOV_MAX =", _SC_IOV_MAX);
#else
printf("no symbol for _SC_IOV_MAX\n");
#endif
#ifdef LINE_MAX
printf("LINE_MAX defined to be %ld\n",(long)LINE_MAX +0);
#else
printf("no symbol for LINE_MAX\n");
#endif
#ifdef _SC_LINE_MAX
pr_sysconf("LINE_MAX =", _SC_LINE_MAX);
#else
printf("no symbol for _SC_LINE_MAX\n");
#endif
#ifdef LOGIN_NAME_MAX
printf("LOGIN_NAME_MAX defined to be %ld\n",(long)LOGIN_NAME_MAX +0);
#else
printf("no symbol for LOGIN_NAME_MAX\n");
#endif
#ifdef _SC_LOGIN_NAME_MAX
pr_sysconf("LOGIN_NAME_MAX =", _SC_LOGIN_NAME_MAX);
#else
printf("no symbol for _SC_LOGIN_NAME_MAX\n");
#endif
#ifdef NGROUPS_MAX
printf("NGROUPS_MAX defined to be %ld\n",(long)NGROUPS_MAX +0);
#else
printf("no symbol for NGROUPS_MAX\n");
#endif
#ifdef _SC_NGROUPS_MAX
pr_sysconf("NGROUPS_MAX =", _SC_NGROUPS_MAX);
#else
printf("no symbol for _SC_NGROUPS_MAX\n");
#endif
#ifdef OPEN_MAX
printf("OPEN_MAX defined to be %ld\n",(long)OPEN_MAX +0);
#else
printf("no symbol for OPEN_MAX\n");
#endif
#ifdef _SC_OPEN_MAX
pr_sysconf("OPEN_MAX =", _SC_OPEN_MAX);
#else
printf("no symbol for _SC_OPEN_MAX\n");
#endif
#ifdef PAGESIZE
printf("PAGESIZE defined to be %ld\n",(long)PAGESIZE +0);
#else
printf("no symbol for PAGESIZE\n");
#endif
#ifdef _SC_PAGESIZE
pr_sysconf("PAGESIZE =", _SC_PAGESIZE);
#else
printf("no symbol for _SC_PAGESIZE\n");
#endif
#ifdef PAGE_SIZE
printf("PAGE_SIZE defined to be %ld\n",(long)PAGE_SIZE +0);
#else
printf("no symbol for PAGE_SIZE\n");
#endif
#ifdef _SC_PAGE_SIZE
pr_sysconf("PAGE_SIZE =", _SC_PAGE_SIZE);
#else
printf("no symbol for _SC_PAGE_SIZE\n");
#endif
#ifdef RE_DUP_MAX
printf("RE_DUP_MAX defined to be %ld\n",(long)RE_DUP_MAX +0);
#else
printf("no symbol for RE_DUP_MAX\n");
#endif
#ifdef _SC_RE_DUP_MAX
pr_sysconf("RE_DUP_MAX =", _SC_RE_DUP_MAX);
#else
printf("no symbol for _SC_RE_DUP_MAX\n");
#endif
#ifdef RTSIG_MAX
printf("RTSIG_MAX defined to be %ld\n",(long)RTSIG_MAX +0);
#else
printf("no symbol for RTSIG_MAX\n");
#endif
#ifdef _SC_RTSIG_MAX
pr_sysconf("RTSIG_MAX =", _SC_RTSIG_MAX);
#else
printf("no symbol for _SC_RTSIG_MAX\n");
#endif
#ifdef SEM_NSEMS_MAX
printf("SEM_NSEMS_MAX defined to be %ld\n",(long)SEM_NSEMS_MAX +0);
#else
printf("no symbol for SEM_NSEMS_MAX\n");
#endif
#ifdef _SC_SEM_NSEMS_MAX
pr_sysconf("SEM_NSEMS_MAX =", _SC_SEM_NSEMS_MAX);
#else
printf("no symbol for _SC_SEM_NSEMS_MAX\n");
#endif
#ifdef SEM_VALUE_MAX
printf("SEM_VALUE_MAX defined to be %ld\n",(long)SEM_VALUE_MAX +0);
#else
printf("no symbol for SEM_VALUE_MAX\n");
#endif
#ifdef _SC_SEM_VALUE_MAX
pr_sysconf("SEM_VALUE_MAX =", _SC_SEM_VALUE_MAX);
#else
printf("no symbol for _SC_SEM_VALUE_MAX\n");
#endif
#ifdef SIGQUEUE_MAX
printf("SIGQUEUE_MAX defined to be %ld\n",(long)SIGQUEUE_MAX +0);
#else
printf("no symbol for SIGQUEUE_MAX\n");
#endif
#ifdef _SC_SIGQUEUE_MAX
pr_sysconf("SIGQUEUE_MAX =", _SC_SIGQUEUE_MAX);
#else
printf("no symbol for _SC_SIGQUEUE_MAX\n");
#endif
#ifdef STREAM_MAX
printf("STREAM_MAX defined to be %ld\n",(long)STREAM_MAX +0);
#else
printf("no symbol for STREAM_MAX\n");
#endif
#ifdef _SC_STREAM_MAX
pr_sysconf("STREAM_MAX =", _SC_STREAM_MAX);
#else
printf("no symbol for _SC_STREAM_MAX\n");
#endif
#ifdef SYMLOOP_MAX
printf("SYMLOOP_MAX defined to be %ld\n",(long)SYMLOOP_MAX +0);
#else
printf("no symbol for SYMLOOP_MAX\n");
#endif
#ifdef _SC_SYMLOOP_MAX
pr_sysconf("SYMLOOP_MAX =", _SC_SYMLOOP_MAX);
#else
printf("no symbol for _SC_SYMLOOP_MAX\n");
#endif
#ifdef TIMER_MAX
printf("TIMER_MAX defined to be %ld\n",(long)TIMER_MAX +0);
#else
printf("no symbol for TIMER_MAX\n");
#endif
#ifdef _SC_TIMER_MAX
pr_sysconf("TIMER_MAX =", _SC_TIMER_MAX);
#else
printf("no symbol for _SC_TIMER_MAX\n");
#endif
#ifdef TTY_NAME_MAX
printf("TTY_NAME_MAX defined to be %ld\n",(long)TTY_NAME_MAX +0);
#else
printf("no symbol for TTY_NAME_MAX\n");
#endif
#ifdef _SC_TTY_NAME_MAX
pr_sysconf("TTY_NAME_MAX =", _SC_TTY_NAME_MAX);
#else
printf("no symbol for _SC_TTY_NAME_MAX\n");
#endif
#ifdef TZNAME_MAX
printf("TZNAME_MAX defined to be %ld\n",(long)TZNAME_MAX +0);
#else
printf("no symbol for TZNAME_MAX\n");
#endif
#ifdef _SC_TZNAME_MAX
pr_sysconf("TZNAME_MAX =", _SC_TZNAME_MAX);
#else
printf("no symbol for _SC_TZNAME_MAX\n");
#endif
#ifdef FILESIZEBITS
printf("FILESIZEBITS defined to be %ld\n",(long)FILESIZEBITS+0);
#else
printf("no symbol for FILESIZEBITS\n");
#endif
#ifdef _PC_FILESIZEBITS
pr_pathconf("FILESIZEBITS =", argv[1], _PC_FILESIZEBITS);
#else
printf("no symbol for _PC_FILESIZEBITS\n");
#endif
#ifdef LINK_MAX
printf("LINK_MAX defined to be %ld\n",(long)LINK_MAX+0);
#else
printf("no symbol for LINK_MAX\n");
#endif
#ifdef _PC_LINK_MAX
pr_pathconf("LINK_MAX =", argv[1], _PC_LINK_MAX);
#else
printf("no symbol for _PC_LINK_MAX\n");
#endif
#ifdef MAX_CANON
printf("MAX_CANON defined to be %ld\n",(long)MAX_CANON+0);
#else
printf("no symbol for MAX_CANON\n");
#endif
#ifdef _PC_MAX_CANON
pr_pathconf("MAX_CANON =", argv[1], _PC_MAX_CANON);
#else
printf("no symbol for _PC_MAX_CANON\n");
#endif
#ifdef MAX_INPUT
printf("MAX_INPUT defined to be %ld\n",(long)MAX_INPUT+0);
#else
printf("no symbol for MAX_INPUT\n");
#endif
#ifdef _PC_MAX_INPUT
pr_pathconf("MAX_INPUT =", argv[1], _PC_MAX_INPUT);
#else
printf("no symbol for _PC_MAX_INPUT\n");
#endif
#ifdef NAME_MAX
printf("NAME_MAX defined to be %ld\n",(long)NAME_MAX+0);
#else
printf("no symbol for NAME_MAX\n");
#endif
#ifdef _PC_NAME_MAX
pr_pathconf("NAME_MAX =", argv[1], _PC_NAME_MAX);
#else
printf("no symbol for _PC_NAME_MAX\n");
#endif
#ifdef PATH_MAX
printf("PATH_MAX defined to be %ld\n",(long)PATH_MAX+0);
#else
printf("no symbol for PATH_MAX\n");
#endif
#ifdef _PC_PATH_MAX
pr_pathconf("PATH_MAX =", argv[1], _PC_PATH_MAX);
#else
printf("no symbol for _PC_PATH_MAX\n");
#endif
#ifdef PIPE_BUF
printf("PIPE_BUF defined to be %ld\n",(long)PIPE_BUF+0);
#else
printf("no symbol for PIPE_BUF\n");
#endif
#ifdef _PC_PIPE_BUF
pr_pathconf("PIPE_BUF =", argv[1], _PC_PIPE_BUF);
#else
printf("no symbol for _PC_PIPE_BUF\n");
#endif
#ifdef SYMLINK_MAX
printf("SYMLINK_MAX defined to be %ld\n",(long)SYMLINK_MAX+0);
#else
printf("no symbol for SYMLINK_MAX\n");
#endif
#ifdef _PC_SYMLINK_MAX
pr_pathconf("SYMLINK_MAX =", argv[1], _PC_SYMLINK_MAX);
#else
printf("no symbol for _PC_SYMLINK_MAX\n");
#endif
#ifdef _POSIX_TIMESTAMP_RESOLUTION
printf("_POSIX_TIMESTAMP_RESOLUTION defined to be %ld\n",(long)_POSIX_TIMESTAMP_RESOLUTION+0);
#else
printf("no symbol for _POSIX_TIMESTAMP_RESOLUTION\n");
#endif
#ifdef _PC_TIMESTAMP_RESOLUTION
pr_pathconf("_POSIX_TIMESTAMP_RESOLUTION =", argv[1], _PC_TIMESTAMP_RESOLUTION);
#else
printf("no symbol for _PC_TIMESTAMP_RESOLUTION\n");
#endif
exit(0);
}
staticvoid
pr_sysconf(char*mesg,int name)
{
long val;
fputs(mesg, stdout);
errno =0;
if((val = sysconf(name))<0){
if(errno !=0){
if(errno == EINVAL)
fputs(" (not supported)\n", stdout);
else
err_sys("sysconf error");
}else{
fputs(" (no limit)\n", stdout);
}
}else{
printf(" %ld\n", val);
}
}
staticvoid
pr_pathconf(char*mesg,char*path,int name)
{
long val;
fputs(mesg, stdout);
errno =0;
if((val = pathconf(path, name))<0){
if(errno !=0){
if(errno == EINVAL)
fputs(" (not supported)\n", stdout);
else
err_sys("pathconf error, path = %s", path);
}else{
fputs(" (no limit)\n", stdout);
}
}else{
printf(" %ld\n", val);
}
}
Solaris 10 | |||||
Limit | FreeBSD 8.0 | Linux 3.2.0 | Mac OS X 10.6.8 |
UFS file system | PCFS file system |
ARG_MAX | 262,144 | 2,097,152 | 262,144 | 2,096,640 | 2,096,640 |
ATEXIT_MAX | 32 | 2,147,483,647 | 2,147,483,647 | no limit | no limit |
CHARCLASS_NAME_MAX | no symbol | 2,048 | 14 | 14 | 14 |
CHILD_MAX | 1,760 | 47,211 | 266 | 8,021 | 8,021 |
clock ticks/second | 128 | 100 | 100 | 100 | 100 |
COLL_WEIGHTS_MAX | 0 | 255 | 2 | 10 | 10 |
FILESIZEBITS | 64 | 64 | 64 | 41 | unsupported |
HOST_NAME_MAX | 255 | 64 | 255 | 255 | 255 |
IOV_MAX | 1,024 | 1,024 | 1024 | 16 | 16 |
LINE_MAX | 2,048 | 2,048 | 2,048 | 2,048 | 2,048 |
LINK_MAX | 32,767 | 65,000 | 32,767 | 32,767 | 1 |
LOGIN_NAME_MAX | 17 | 256 | 255 | 9 | 9 |
MAX_CANON | 255 | 255 | 1,024 | 256 | 256 |
MAX_INPUT | 255 | 255 | 1,024 | 512 | 512 |
NAME_MAX | 255 | 255 | 255 | 255 | 8 |
NGROUPS_MAX | 1,023 | 65,536 | 16 | 16 | 16 |
OPEN_MAX | 3,520 | 1,024 | 256 | 256 | 256 |
PAGESIZE | 4,096 | 4,096 | 4,096 | 8,192 | 8,192 |
PAGE_SIZE | 4,096 | 4,096 | 4,096 | 8,192 | 8,192 |
PATH_MAX | 1,024 | 4,096 | 1,024 | 1,024 | 1,024 |
PIPE_BUF | 512 | 4,096 | 512 | 5,120 | 5,120 |
RE_DUP_MAX | 255 | 32,767 | 255 | 255 | 255 |
STREAM_MAX | 3,520 | 16 | 20 | 256 | 256 |
SYMLINK_MAX | 1,024 | no limit | 255 | 1,024 | 1,024 |
SYMLOOP_MAX | 32 | no limit | 32 | 20 | 20 |
TTY_NAME_MAX | 255 | 32 | 255 | 128 | 128 |
TZNAME_MAX | 255 | 6 | 255 | no limit | no limit |
Beware that some limits are reported incorrectly. For example, on Linux, SYMLOOP_MAX is reportedly unlimited, but an examination of the source code revealsthat there is actually a hard-coded limit of 40 for the number of consecutivesymbolic links traversedin the absence ofa loop (see the follow_link function in fs/namei.c).
Another potential source of inaccuracyin Linux is that the pathconf and fpathconf functions are implemented in the C library. The configuration limits returned by these functions depend on the underlyingfile system type, so if your file system is unknown to the C library, the functions return an educatedguess.
- # ......
staticvoid pr_sysconf(char*,int);
staticvoid pr_pathconf(char*,char*,int);
int
main(int argc,char*argv[])
{
if(argc !=2)
err_quit("usage: a.out <dirname>");
printf("no symbol for ARG_MAX\n");
pr_sysconf("ARG_MAX =", _SC_ARG_MAX);
printf("no symbol for ATEXIT_MAX\n");
pr_sysconf("ATEXIT_MAX =", _SC_ATEXIT_MAX);
printf("CHARCLASS_NAME_MAX defined to be %ld\n",(long)2048+0);
pr_sysconf("CHARCLASS_NAME_MAX =", _SC_CHARCLASS_NAME_MAX);
printf("no symbol for CHILD_MAX\n");
pr_sysconf("CHILD_MAX =", _SC_CHILD_MAX);
printf("no symbol for CLOCKTICKSPERSECOND /*clock ticks/second*/\n");
pr_sysconf("CLOCKTICKSPERSECOND /*clock ticks/second*/ =", _SC_CLK_TCK);
printf("COLL_WEIGHTS_MAX defined to be %ld\n",(long)255+0);
pr_sysconf("COLL_WEIGHTS_MAX =", _SC_COLL_WEIGHTS_MAX);
printf("DELAYTIMER_MAX defined to be %ld\n",(long)2147483647+0);
pr_sysconf("DELAYTIMER_MAX =", _SC_DELAYTIMER_MAX);
printf("HOST_NAME_MAX defined to be %ld\n",(long)64+0);
pr_sysconf("HOST_NAME_MAX =", _SC_HOST_NAME_MAX);
printf("IOV_MAX defined to be %ld\n",(long)1024+0);
pr_sysconf("IOV_MAX =", _SC_IOV_MAX);
printf("LINE_MAX defined to be %ld\n",(long)2048+0);
pr_sysconf("LINE_MAX =", _SC_LINE_MAX);
printf("LOGIN_NAME_MAX defined to be %ld\n",(long)256+0);
pr_sysconf("LOGIN_NAME_MAX =", _SC_LOGIN_NAME_MAX);
printf("NGROUPS_MAX defined to be %ld\n",(long)65536+0);
pr_sysconf("NGROUPS_MAX =", _SC_NGROUPS_MAX);
printf("no symbol for OPEN_MAX\n");
pr_sysconf("OPEN_MAX =", _SC_OPEN_MAX);
printf("no symbol for PAGESIZE\n");
pr_sysconf("PAGESIZE =", _SC_PAGESIZE);
printf("no symbol for PAGE_SIZE\n");
pr_sysconf("PAGE_SIZE =", _SC_PAGESIZE);
printf("RE_DUP_MAX defined to be %ld\n",(long)(0x7fff)+0);
pr_sysconf("RE_DUP_MAX =", _SC_RE_DUP_MAX);
printf("RTSIG_MAX defined to be %ld\n",(long)32+0);
pr_sysconf("RTSIG_MAX =", _SC_RTSIG_MAX);
printf("no symbol for SEM_NSEMS_MAX\n");
pr_sysconf("SEM_NSEMS_MAX =", _SC_SEM_NSEMS_MAX);
printf("SEM_VALUE_MAX defined to be %ld\n",(long)(2147483647)+0);
pr_sysconf("SEM_VALUE_MAX =", _SC_SEM_VALUE_MAX);
printf("no symbol for SIGQUEUE_MAX\n");
pr_sysconf("SIGQUEUE_MAX =", _SC_SIGQUEUE_MAX);
printf("no symbol for STREAM_MAX\n");
pr_sysconf("STREAM_MAX =", _SC_STREAM_MAX);
printf("no symbol for SYMLOOP_MAX\n");
pr_sysconf("SYMLOOP_MAX =", _SC_SYMLOOP_MAX);
printf("no symbol for TIMER_MAX\n");
pr_sysconf("TIMER_MAX =", _SC_TIMER_MAX);
printf("TTY_NAME_MAX defined to be %ld\n",(long)32+0);
pr_sysconf("TTY_NAME_MAX =", _SC_TTY_NAME_MAX);
printf("no symbol for TZNAME_MAX\n");
pr_sysconf("TZNAME_MAX =", _SC_TZNAME_MAX);
# 294 "conf.c"
printf("no symbol for FILESIZEBITS\n");
pr_pathconf("FILESIZEBITS =", argv[1], _PC_FILESIZEBITS);
printf("no symbol for LINK_MAX\n");
pr_pathconf("LINK_MAX =", argv[1], _PC_LINK_MAX);
printf("MAX_CANON defined to be %ld\n",(long)255+0);
pr_pathconf("MAX_CANON =", argv[1], _PC_MAX_CANON);
printf("MAX_INPUT defined to be %ld\n",(long)255+0);
pr_pathconf("MAX_INPUT =", argv[1], _PC_MAX_INPUT);
printf("NAME_MAX defined to be %ld\n",(long)255+0);
pr_pathconf("NAME_MAX =", argv[1], _PC_NAME_MAX);
printf("PATH_MAX defined to be %ld\n",(long)4096+0);
pr_pathconf("PATH_MAX =", argv[1], _PC_PATH_MAX);
printf("PIPE_BUF defined to be %ld\n",(long)4096+0);
pr_pathconf("PIPE_BUF =", argv[1], _PC_PIPE_BUF);
printf("no symbol for SYMLINK_MAX\n");
pr_pathconf("SYMLINK_MAX =", argv[1], _PC_SYMLINK_MAX);
printf("no symbol for _POSIX_TIMESTAMP_RESOLUTION\n");
printf("no symbol for _PC_TIMESTAMP_RESOLUTION\n");
exit(0);
}
staticvoid
pr_sysconf(char*mesg,int name)
{
long val;
fputs(mesg, stdout);
(*__errno_location ())=0;
if((val = sysconf(name))<0){
if((*__errno_location ())!=0){
if((*__errno_location ())==22)
fputs(" (not supported)\n", stdout);
else
err_sys("sysconf error");
}else{
fputs(" (no limit)\n", stdout);
}
}else{
printf(" %ld\n", val);
}
}
staticvoid
pr_pathconf(char*mesg,char*path,int name)
{
long val;
fputs(mesg, stdout);
(*__errno_location ())=0;
if((val = pathconf(path, name))<0){
if((*__errno_location ())!=0){
if((*__errno_location ())==22)
fputs(" (not supported)\n", stdout);
else
err_sys("pathconf error, path = %s", path);
}else{
fputs(" (no limit)\n", stdout);
}
}else{
printf(" %ld\n", val);
}
}
no symbol for ARG_MAX
ARG_MAX = 2097152
no symbol for ATEXIT_MAX
ATEXIT_MAX = 2147483647
CHARCLASS_NAME_MAX defined to be 2048
CHARCLASS_NAME_MAX = 2048
no symbol for CHILD_MAX
CHILD_MAX = 7884
no symbol for CLOCKTICKSPERSECOND /*clock ticks/second*/
CLOCKTICKSPERSECOND /*clock ticks/second*/ = 100
COLL_WEIGHTS_MAX defined to be 255
COLL_WEIGHTS_MAX = 255
DELAYTIMER_MAX defined to be 2147483647
DELAYTIMER_MAX = 2147483647
HOST_NAME_MAX defined to be 64
HOST_NAME_MAX = 64
IOV_MAX defined to be 1024
IOV_MAX = 1024
LINE_MAX defined to be 2048
LINE_MAX = 2048
LOGIN_NAME_MAX defined to be 256
LOGIN_NAME_MAX = 256
NGROUPS_MAX defined to be 65536
NGROUPS_MAX = 65536
no symbol for OPEN_MAX
OPEN_MAX = 1024
no symbol for PAGESIZE
PAGESIZE = 4096
no symbol for PAGE_SIZE
PAGE_SIZE = 4096
RE_DUP_MAX defined to be 32767
RE_DUP_MAX = 32767
RTSIG_MAX defined to be 32
RTSIG_MAX = 32
no symbol for SEM_NSEMS_MAX
SEM_NSEMS_MAX = (no limit)
SEM_VALUE_MAX defined to be 2147483647
SEM_VALUE_MAX = 2147483647
no symbol for SIGQUEUE_MAX
SIGQUEUE_MAX = 7884
no symbol for STREAM_MAX
STREAM_MAX = 16
no symbol for SYMLOOP_MAX
SYMLOOP_MAX = (no limit)
no symbol for TIMER_MAX
TIMER_MAX = (no limit)
TTY_NAME_MAX defined to be 32
TTY_NAME_MAX = 32
no symbol for TZNAME_MAX
TZNAME_MAX = 6
no symbol for FILESIZEBITS
FILESIZEBITS = 64
no symbol for LINK_MAX
LINK_MAX = 65000
MAX_CANON defined to be 255
MAX_CANON = 255
MAX_INPUT defined to be 255
MAX_INPUT = 255
NAME_MAX defined to be 255
NAME_MAX = 255
PATH_MAX defined to be 4096
PATH_MAX = 4096
PIPE_BUF defined to be 4096
PIPE_BUF = 4096
no symbol for SYMLINK_MAX
SYMLINK_MAX = (no limit)
no symbol for _POSIX_TIMESTAMP_RESOLUTION
no symbol for _PC_TIMESTAMP_RESOLUTION
不确定的运行时限制
Pathnames
/**
* 文件名: lib/openmax.c
* 内容:
* 时间: 2016年 08月 19日 星期五 15:23:51 CST
* 作者:firewaywei
*
*/
#include"apue.h"
#include<errno.h>
#include<limits.h>
#ifdef OPEN_MAX
staticlong openmax = OPEN_MAX;
#else
staticlong openmax =0;
#endif
/*
* If OPEN_MAX is indeterminate, this might be inadequate.
*/
#define OPEN_MAX_GUESS 256
long
open_max(void)
{
if(openmax ==0)
{/* first time through */
errno =0;
if((openmax = sysconf(_SC_OPEN_MAX))<0)
{
if(errno ==0)
{
openmax = OPEN_MAX_GUESS;/* it's indeterminate */
}
else
{
err_sys("sysconf error for _SC_OPEN_MAX");
}
}
}
return(openmax);
}
Maximum Number of Open Files
#include<sys/param.h>
for(i =0; i < NOFILE; i++)
{
close(i);
}
#include<unistd.h>
for(i =0; i < sysconf(_SC_OPEN_MAX); i++)
{
close(i);
}
/**
* 文件名: lib/openmax.c
* 内容:
* 时间: 2016年 08月 19日 星期五 15:23:51 CST
* 作者:firewaywei
*
*/
#include"apue.h"
#include<errno.h>
#include<limits.h>
#ifdef OPEN_MAX
staticlong openmax = OPEN_MAX;
#else
staticlong openmax =0;
#endif
/*
* If OPEN_MAX is indeterminate, this might be inadequate.
*/
#define OPEN_MAX_GUESS 256
long
open_max(void)
{
if(openmax ==0)
{/* first time through */
errno =0;
if((openmax = sysconf(_SC_OPEN_MAX))<0)
{
if(errno ==0)
{
openmax = OPEN_MAX_GUESS;/* it's indeterminate */
}
else
{
err_sys("sysconf error for _SC_OPEN_MAX");
}
}
}
return(openmax);
}
The OPEN_MAX value is called runtime invariant by POSIX, meaning that its value should not change during the lifetime of a process. But on systems that support the XSI option, we can call the setrlimit(2) function (Section 7.11) to change this value for a running process. (This value can also be changed from the C shell with the limit command, and from the Bourne, Bourne-again, Debian Almquist, and Korn shells with the ulimit command.) If our system supports this functionality, we could change the function in Figure 2.17 to call sysconf every time it is called, not just the first time.
选项
Name of option | Indicates ... | name argument |
_POSIX_CHOWN_RESTRICTED | whether use of chown is restricted | _PC_CHOWN_RESTRICTED |
_POSIX_NO_TRUNC | whether filenames longer than NAME_MAX | _PC_NO_TRUNC |
_POSIX_VDISABLE | if defined, terminal special characters can be disabled with this value | _PC_VDISABLE |
_POSIX_ASYNC_IO | whether asynchronous I/O can be used with the associated file | _PC_ASYNC_IO |
_POSIX_PRIO_IO | whether prioritized I/O can be used with the associated file | _PC_PRIO_IO |
_POSIX_SYNC_IO | whether synchronized I/O can be used with the associated file | _PC_SYNC_IO |
_POSIX2_SYMLINKS | whether symbolic links are supported in the directory | _PC_2_SYMLINKS |
Name of option | Indicates ... | name argument |
_POSIX_ASYNCHRONOUS_IO | whether the implementation supports POSIX asynchronous I/O | _SC_ASYNCHRONOUS_IO |
_POSIX_BARRIERS | whether the implementation supports barriers | _SC_BARRIERS |
_POSIX_CLOCK_SELECTION | whether the implementation supports clock selection | _SC_CLOCK_SELECTION |
_POSIX_JOB_CONTROL | whether the implementation supports job control | _SC_JOB_CONTROL |
_POSIX_MAPPED_FILES | whether the implementation supports memory-mapped files | _SC_MAPPED_FILES |
_POSIX_MEMORY_PROTECTION | whether the implementation supports memory protection | _SC_MEMORY_PROTECTION |
_POSIX_READER_WRITER_LOCKS | whether the implementation supports reader–writer locks | _SC_READER_WRITER_LOCKS |
_POSIX_REALTIME_SIGNALS | whether the implementation supports real-time signals | _SC_REALTIME_SIGNALS |
_POSIX_SAVED_IDS | whether the implementation supports the saved set-user-ID and the saved set-group-ID | _SC_SAVED_IDS |
_POSIX_SEMAPHORES | whether the implementation supports POSIX semaphores | _SC_SEMAPHORES |
_POSIX_SHELL | whether the implementation supports the POSIX shell | _SC_SHELL |
_POSIX_SPIN_LOCKS | whether the implementation supports spin locks | _SC_SPIN_LOCKS |
_POSIX_THREAD_SAFE_FUNCTIONS | whether the implementation supports thread-safe functions | _SC_THREAD_SAFE_FUNCTIONS |
_POSIX_THREADS | whether the implementation supports threads | _SC_THREADS |
_POSIX_TIMEOUTS | whether the implementation supports timeout-based variants of selected functions | _SC_TIMEOUTS |
_POSIX_TIMERS | whether the implementation supports timers | _SC_TIMERS |
_POSIX_VERSION | the POSIX.1 version | _SC_VERSION |
_XOPEN_CRYPT | whether the implementation supports the XSI encryption option group | _SC_XOPEN_CRYPT |
_XOPEN_REALTIME | whether the implementation supports the XSI real-time option group | _SC_XOPEN_REALTIME |
_XOPEN_REALTIME_THREADS | whether the implementation supports the XSI real-time threads option group | _SC_XOPEN_REALTIME_THREADS |
_XOPEN_SHM | whether the implementation supports the XSI shared memory option group | _SC_XOPEN_SHM |
_XOPEN_VERSION | the XSI version | _SC_XOPEN_VERSION |
- _POSIX_ASYNCHRONOUS_IO
- _POSIX_BARRIERS
- _POSIX_CLOCK_SELECTION
- _POSIX_MAPPED_FILES
- _POSIX_MEMORY_PROTECTION
- _POSIX_READER_WRITER_LOCKS
- _POSIX_REALTIME_SIGNALS
- _POSIX_SEMAPHORES
- _POSIX_SPIN_LOCKS
- _POSIX_THREAD_SAFE_FUNCTIONS
- _POSIX_THREADS
- _POSIX_TIMEOUTS
- _POSIX_TIMERS
Solaris 10 | |||||
Limit | FreeBSD 8.0 |
Linux 3.2.0 |
Mac OS X 10.6.8 |
UFS file system | PCFS file system |
_POSIX_CHOWN_RESTRICTED | 1 | 1 | 200112 | 1 | 1 |
_POSIX_JOB_CONTROL | 1 | 1 | 200112 | 1 | 1 |
_POSIX_NO_TRUNC | 1 | 1 | 200112 | 1 | unsupported |
_POSIX_SAVED_IDS | unsupported | 1 | 200112 | 1 | 1 |
_POSIX_THREADS | 200112 | 200809 | 200112 | 200112 | 200112 |
_POSIX_VDISABLE | 255 | 0 | 255 | 0 | 0 |
_POSIX_VERSION | 200112 | 200809 | 200112 | 200112 | 200112 |
_XOPEN_UNIX | unsupported | 1 | 1 | 1 | 1 |
_XOPEN_VERSION | unsupported | 700 | 600 | 600 | 600 |
功能测试宏
Older versions of the POSIX.1 standard defined the _POSIX_SOURCE constant. This was supersededby the _POSIX_C_SOURCE constant in the 2001 version of POSIX.1.
cc -D_POSIX_C_SOURCE=200809L file.c
#define _POSIX_C_SOURCE 200809L
c99 -D_XOPEN_SOURCE=700 file.c -o file
gcc -D_XOPEN_SOURCE=700 -std=c99 file.c -o file
基本系统数据类型
Type | Description |
clock_t | counter of clock ticks(process time) |
comp_t | compressed clock ticks(not defined by POSIX.1) |
dev_t | device numbers (major and minor) |
fd_set | file descriptor sets |
fpos_t | file position |
gid_t | numeric group IDs |
ino_t | i-node numbers |
mode_t | file type, file creation mode |
nlink_t | link counts for directory entries |
off_t | file sizes and offsets (signed) (lseek) |
pid_t | process IDs and process group IDs (signed) |
pthread_t | thread IDs |
ptrdiff_t | result of subtractingtwo pointers (signed) |
rlim_t | resource limits |
sig_atomic_t | data type that can be accessed atomically |
sigset_t | signal set |
size_t | sizes of objects (such as strings) (unsigned) |
ssize_t | functions that return a count of bytes (signed) (read, write) |
time_t | counter of seconds of calendar time |
uid_t | numericuser IDs |
wchar_t | can represent all distinctcharacter codes |
标准之间的冲突
小结
UNIX标准及实现的更多相关文章
- linux文件锁的应用,POSIX,unix标准,linux标准
1. perl,flock加锁.java也能加锁. 2. 先创建文件并打开,才能加锁(写打开?). 3. 可以用于判断进程是否一直在运行(用另一进程判断),如果锁一直在,则进程在:锁不在,则原进程或意 ...
- UNIX标准
背景 人们在UNIX编程环境和C 程序设计语言的标准化方面已经做了很多工作.虽然UNIX应用 程序在不同的UNIX操作系统版本之间进行移植相当容易,但是2 0 世 纪 80年代UNIX版本种类的剧增以 ...
- UNIX环境高级编程 第2章 UNIX标准及实现
在过去的将近25年时间,人们为了UNIX的标准化做出了种种努力,这使得程序在不同版本的UNIX系统之间的移植相当容易. ISO C 1989年,C语言首个标准得到批准,其为C89.次年,一个带有小改动 ...
- UNIX标准C - socket套接字
一.计算机网络 1.计算机网络的功能 a.数据通信 b.资源共享 c.提高系统的可靠性 d.分布式网络处理和负载均匀. 2.计算机网络的组成 1.通信子网:由网卡.线缆.集线器.中继器.交换器.路由器 ...
- UNIX标准C - 进程之间的通信
一.基本概念 进程间通信IPC:进程之间交换数据的过程叫进程间通信 进程间同性的方式: 简单的进程间的通信: 命令行:父进程通过exec函数创建子进程是可以附加一些数据 环境变量表:父进程通过exec ...
- 《UNIX环境高级编程》笔记——2.标准和实现
随着UNIX各种衍生版本不断发展壮大,标准化工作就十分必要.其实干啥事都是这样,玩的人多了,必须进行标准化. 一.UNIX标准 1.1 ISO C(ANSI C) ANSI:Amerocan Nato ...
- 【笔记】Unix 平台标准
POSIX 表示可移植操作系统接口(Portable Operating System Interface ,缩写为 POSIX ),POSIX标准定义了操作系统应该为应用程序提供的接口标准,是IEE ...
- UNIX环境高级编程——标准I/O库函数和Unbuffered I/O函数
以写文件为例,C标准I/O库函数(printf(3) .putchar(3) .fputs(3) )与系统调用write(2) 的关 系如下图所示. 库函数与系统调用的层次关系 open .read ...
- C标准I/O库函数与Unbuffered I/O函数
一.C标准I/O库函数.Unbuffered I/O函数 1. C标准I/O库函数是如何用系统调用的 fopen(3) 调用open(2)打开制定的文件,返回一个文件描述符(一个int类型的编号),分 ...
随机推荐
- 阿里云AliYun表格存储(Table Store)相关案例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 使用jquery.form.js文件进行文件上传
本想着文件上传是一件挺简单的事,不过是获取文件地址保存到服务器而已,然而事实并非如此. 我信心满满的写下input type="file",alert input 的value,打 ...
- 数据库表反向生成(一) MyBatis-generator与IDEA的集成
在Dao层,通过数据库表反向生成,可以节省我们很多的精力,把更多的精力投入复杂的业务中. 数据库表反向生成,指的是通过数据库如mysql中的库表schema生成dao层读写表的基础代码,包括model ...
- GooglePlay - 排行榜及支付接入
前言 Google Play应用商店在国外Android市场中地位基本与AppStore在IOS中的地位一致,为此考虑国外的应用时,Android首要考虑的是接入GooglePlay的排行榜等支持. ...
- JAVA常用API(Date、DateFormat、Calendar、System、Math、基本数据类型包装类)
注:本文所有内容均属个人见解,如有错误望各位大佬好心指点批评,不胜感激 本章重点单词: parse:解析 format:格式化 pattern:模式 amount:数量 filed :领域 1.Dat ...
- 窗口迅速关闭的解决办法/scanf/if/for/break
break if的格式 if(a>b) { printf("max=%d\n",a); } else printf("max=%d\n",b); scan ...
- python安装(python2.7)
1.下载python 进入官网下载安装 点击打开链接(官网地址:https://www.python.org/downloads/),进入官网后根据自己需求选择python2 或者 python3 2 ...
- win10 uwp MVVM 轻量框架
如果在开发过程,遇到多个页面之间,需要传输信息,那么可能遇到设计的问题.如果因为一个页面内包含多个子页面和多个子页面之间的通信问题找不到一个好的解决方法,那么请看本文.如果因为ViewModel代码越 ...
- Latex 去掉行号
本文主要讲如何去掉Latex的行号 删除\modulolinenumbers删除所有\linenumbers 删除\usepackage{lineno,hyperref} modulolinenumb ...
- LINUX 笔记-netstat命令
netstat命令用于显示与IP.TCP.UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况.netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP ...