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) |\ |\ 1BSD32V |\ 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.11BSDTenth Edition | || 2.11BSD rev #4304.3BSD NET/1 || v4.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.1FreeBSD 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 -fBEGIN {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_MAXprintf("NAME_MAX defined to be %ld\n",(long)NAME_MAX+0);#elseprintf("no symbol for NAME_MAX\n");#endif#ifdef _PC_NAME_MAXpr_pathconf("NAME_MAX =", argv[1], _PC_NAME_MAX);#elseprintf("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);intmain(int argc,char*argv[]){if(argc !=2)err_quit("usage: a.out <dirname>");#ifdef ARG_MAXprintf("ARG_MAX defined to be %ld\n",(long)ARG_MAX +0);#elseprintf("no symbol for ARG_MAX\n");#endif#ifdef _SC_ARG_MAXpr_sysconf("ARG_MAX =", _SC_ARG_MAX);#elseprintf("no symbol for _SC_ARG_MAX\n");#endif#ifdef ATEXIT_MAXprintf("ATEXIT_MAX defined to be %ld\n",(long)ATEXIT_MAX +0);#elseprintf("no symbol for ATEXIT_MAX\n");#endif#ifdef _SC_ATEXIT_MAXpr_sysconf("ATEXIT_MAX =", _SC_ATEXIT_MAX);#elseprintf("no symbol for _SC_ATEXIT_MAX\n");#endif#ifdef CHARCLASS_NAME_MAXprintf("CHARCLASS_NAME_MAX defined to be %ld\n",(long)CHARCLASS_NAME_MAX +0);#elseprintf("no symbol for CHARCLASS_NAME_MAX\n");#endif#ifdef _SC_CHARCLASS_NAME_MAXpr_sysconf("CHARCLASS_NAME_MAX =", _SC_CHARCLASS_NAME_MAX);#elseprintf("no symbol for _SC_CHARCLASS_NAME_MAX\n");#endif#ifdef CHILD_MAXprintf("CHILD_MAX defined to be %ld\n",(long)CHILD_MAX +0);#elseprintf("no symbol for CHILD_MAX\n");#endif#ifdef _SC_CHILD_MAXpr_sysconf("CHILD_MAX =", _SC_CHILD_MAX);#elseprintf("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);#elseprintf("no symbol for CLOCKTICKSPERSECOND /*clock ticks/second*/\n");#endif#ifdef _SC_CLK_TCKpr_sysconf("CLOCKTICKSPERSECOND /*clock ticks/second*/ =", _SC_CLK_TCK);#elseprintf("no symbol for _SC_CLK_TCK\n");#endif#ifdef COLL_WEIGHTS_MAXprintf("COLL_WEIGHTS_MAX defined to be %ld\n",(long)COLL_WEIGHTS_MAX +0);#elseprintf("no symbol for COLL_WEIGHTS_MAX\n");#endif#ifdef _SC_COLL_WEIGHTS_MAXpr_sysconf("COLL_WEIGHTS_MAX =", _SC_COLL_WEIGHTS_MAX);#elseprintf("no symbol for _SC_COLL_WEIGHTS_MAX\n");#endif#ifdef DELAYTIMER_MAXprintf("DELAYTIMER_MAX defined to be %ld\n",(long)DELAYTIMER_MAX +0);#elseprintf("no symbol for DELAYTIMER_MAX\n");#endif#ifdef _SC_DELAYTIMER_MAXpr_sysconf("DELAYTIMER_MAX =", _SC_DELAYTIMER_MAX);#elseprintf("no symbol for _SC_DELAYTIMER_MAX\n");#endif#ifdef HOST_NAME_MAXprintf("HOST_NAME_MAX defined to be %ld\n",(long)HOST_NAME_MAX +0);#elseprintf("no symbol for HOST_NAME_MAX\n");#endif#ifdef _SC_HOST_NAME_MAXpr_sysconf("HOST_NAME_MAX =", _SC_HOST_NAME_MAX);#elseprintf("no symbol for _SC_HOST_NAME_MAX\n");#endif#ifdef IOV_MAXprintf("IOV_MAX defined to be %ld\n",(long)IOV_MAX +0);#elseprintf("no symbol for IOV_MAX\n");#endif#ifdef _SC_IOV_MAXpr_sysconf("IOV_MAX =", _SC_IOV_MAX);#elseprintf("no symbol for _SC_IOV_MAX\n");#endif#ifdef LINE_MAXprintf("LINE_MAX defined to be %ld\n",(long)LINE_MAX +0);#elseprintf("no symbol for LINE_MAX\n");#endif#ifdef _SC_LINE_MAXpr_sysconf("LINE_MAX =", _SC_LINE_MAX);#elseprintf("no symbol for _SC_LINE_MAX\n");#endif#ifdef LOGIN_NAME_MAXprintf("LOGIN_NAME_MAX defined to be %ld\n",(long)LOGIN_NAME_MAX +0);#elseprintf("no symbol for LOGIN_NAME_MAX\n");#endif#ifdef _SC_LOGIN_NAME_MAXpr_sysconf("LOGIN_NAME_MAX =", _SC_LOGIN_NAME_MAX);#elseprintf("no symbol for _SC_LOGIN_NAME_MAX\n");#endif#ifdef NGROUPS_MAXprintf("NGROUPS_MAX defined to be %ld\n",(long)NGROUPS_MAX +0);#elseprintf("no symbol for NGROUPS_MAX\n");#endif#ifdef _SC_NGROUPS_MAXpr_sysconf("NGROUPS_MAX =", _SC_NGROUPS_MAX);#elseprintf("no symbol for _SC_NGROUPS_MAX\n");#endif#ifdef OPEN_MAXprintf("OPEN_MAX defined to be %ld\n",(long)OPEN_MAX +0);#elseprintf("no symbol for OPEN_MAX\n");#endif#ifdef _SC_OPEN_MAXpr_sysconf("OPEN_MAX =", _SC_OPEN_MAX);#elseprintf("no symbol for _SC_OPEN_MAX\n");#endif#ifdef PAGESIZEprintf("PAGESIZE defined to be %ld\n",(long)PAGESIZE +0);#elseprintf("no symbol for PAGESIZE\n");#endif#ifdef _SC_PAGESIZEpr_sysconf("PAGESIZE =", _SC_PAGESIZE);#elseprintf("no symbol for _SC_PAGESIZE\n");#endif#ifdef PAGE_SIZEprintf("PAGE_SIZE defined to be %ld\n",(long)PAGE_SIZE +0);#elseprintf("no symbol for PAGE_SIZE\n");#endif#ifdef _SC_PAGE_SIZEpr_sysconf("PAGE_SIZE =", _SC_PAGE_SIZE);#elseprintf("no symbol for _SC_PAGE_SIZE\n");#endif#ifdef RE_DUP_MAXprintf("RE_DUP_MAX defined to be %ld\n",(long)RE_DUP_MAX +0);#elseprintf("no symbol for RE_DUP_MAX\n");#endif#ifdef _SC_RE_DUP_MAXpr_sysconf("RE_DUP_MAX =", _SC_RE_DUP_MAX);#elseprintf("no symbol for _SC_RE_DUP_MAX\n");#endif#ifdef RTSIG_MAXprintf("RTSIG_MAX defined to be %ld\n",(long)RTSIG_MAX +0);#elseprintf("no symbol for RTSIG_MAX\n");#endif#ifdef _SC_RTSIG_MAXpr_sysconf("RTSIG_MAX =", _SC_RTSIG_MAX);#elseprintf("no symbol for _SC_RTSIG_MAX\n");#endif#ifdef SEM_NSEMS_MAXprintf("SEM_NSEMS_MAX defined to be %ld\n",(long)SEM_NSEMS_MAX +0);#elseprintf("no symbol for SEM_NSEMS_MAX\n");#endif#ifdef _SC_SEM_NSEMS_MAXpr_sysconf("SEM_NSEMS_MAX =", _SC_SEM_NSEMS_MAX);#elseprintf("no symbol for _SC_SEM_NSEMS_MAX\n");#endif#ifdef SEM_VALUE_MAXprintf("SEM_VALUE_MAX defined to be %ld\n",(long)SEM_VALUE_MAX +0);#elseprintf("no symbol for SEM_VALUE_MAX\n");#endif#ifdef _SC_SEM_VALUE_MAXpr_sysconf("SEM_VALUE_MAX =", _SC_SEM_VALUE_MAX);#elseprintf("no symbol for _SC_SEM_VALUE_MAX\n");#endif#ifdef SIGQUEUE_MAXprintf("SIGQUEUE_MAX defined to be %ld\n",(long)SIGQUEUE_MAX +0);#elseprintf("no symbol for SIGQUEUE_MAX\n");#endif#ifdef _SC_SIGQUEUE_MAXpr_sysconf("SIGQUEUE_MAX =", _SC_SIGQUEUE_MAX);#elseprintf("no symbol for _SC_SIGQUEUE_MAX\n");#endif#ifdef STREAM_MAXprintf("STREAM_MAX defined to be %ld\n",(long)STREAM_MAX +0);#elseprintf("no symbol for STREAM_MAX\n");#endif#ifdef _SC_STREAM_MAXpr_sysconf("STREAM_MAX =", _SC_STREAM_MAX);#elseprintf("no symbol for _SC_STREAM_MAX\n");#endif#ifdef SYMLOOP_MAXprintf("SYMLOOP_MAX defined to be %ld\n",(long)SYMLOOP_MAX +0);#elseprintf("no symbol for SYMLOOP_MAX\n");#endif#ifdef _SC_SYMLOOP_MAXpr_sysconf("SYMLOOP_MAX =", _SC_SYMLOOP_MAX);#elseprintf("no symbol for _SC_SYMLOOP_MAX\n");#endif#ifdef TIMER_MAXprintf("TIMER_MAX defined to be %ld\n",(long)TIMER_MAX +0);#elseprintf("no symbol for TIMER_MAX\n");#endif#ifdef _SC_TIMER_MAXpr_sysconf("TIMER_MAX =", _SC_TIMER_MAX);#elseprintf("no symbol for _SC_TIMER_MAX\n");#endif#ifdef TTY_NAME_MAXprintf("TTY_NAME_MAX defined to be %ld\n",(long)TTY_NAME_MAX +0);#elseprintf("no symbol for TTY_NAME_MAX\n");#endif#ifdef _SC_TTY_NAME_MAXpr_sysconf("TTY_NAME_MAX =", _SC_TTY_NAME_MAX);#elseprintf("no symbol for _SC_TTY_NAME_MAX\n");#endif#ifdef TZNAME_MAXprintf("TZNAME_MAX defined to be %ld\n",(long)TZNAME_MAX +0);#elseprintf("no symbol for TZNAME_MAX\n");#endif#ifdef _SC_TZNAME_MAXpr_sysconf("TZNAME_MAX =", _SC_TZNAME_MAX);#elseprintf("no symbol for _SC_TZNAME_MAX\n");#endif#ifdef FILESIZEBITSprintf("FILESIZEBITS defined to be %ld\n",(long)FILESIZEBITS+0);#elseprintf("no symbol for FILESIZEBITS\n");#endif#ifdef _PC_FILESIZEBITSpr_pathconf("FILESIZEBITS =", argv[1], _PC_FILESIZEBITS);#elseprintf("no symbol for _PC_FILESIZEBITS\n");#endif#ifdef LINK_MAXprintf("LINK_MAX defined to be %ld\n",(long)LINK_MAX+0);#elseprintf("no symbol for LINK_MAX\n");#endif#ifdef _PC_LINK_MAXpr_pathconf("LINK_MAX =", argv[1], _PC_LINK_MAX);#elseprintf("no symbol for _PC_LINK_MAX\n");#endif#ifdef MAX_CANONprintf("MAX_CANON defined to be %ld\n",(long)MAX_CANON+0);#elseprintf("no symbol for MAX_CANON\n");#endif#ifdef _PC_MAX_CANONpr_pathconf("MAX_CANON =", argv[1], _PC_MAX_CANON);#elseprintf("no symbol for _PC_MAX_CANON\n");#endif#ifdef MAX_INPUTprintf("MAX_INPUT defined to be %ld\n",(long)MAX_INPUT+0);#elseprintf("no symbol for MAX_INPUT\n");#endif#ifdef _PC_MAX_INPUTpr_pathconf("MAX_INPUT =", argv[1], _PC_MAX_INPUT);#elseprintf("no symbol for _PC_MAX_INPUT\n");#endif#ifdef NAME_MAXprintf("NAME_MAX defined to be %ld\n",(long)NAME_MAX+0);#elseprintf("no symbol for NAME_MAX\n");#endif#ifdef _PC_NAME_MAXpr_pathconf("NAME_MAX =", argv[1], _PC_NAME_MAX);#elseprintf("no symbol for _PC_NAME_MAX\n");#endif#ifdef PATH_MAXprintf("PATH_MAX defined to be %ld\n",(long)PATH_MAX+0);#elseprintf("no symbol for PATH_MAX\n");#endif#ifdef _PC_PATH_MAXpr_pathconf("PATH_MAX =", argv[1], _PC_PATH_MAX);#elseprintf("no symbol for _PC_PATH_MAX\n");#endif#ifdef PIPE_BUFprintf("PIPE_BUF defined to be %ld\n",(long)PIPE_BUF+0);#elseprintf("no symbol for PIPE_BUF\n");#endif#ifdef _PC_PIPE_BUFpr_pathconf("PIPE_BUF =", argv[1], _PC_PIPE_BUF);#elseprintf("no symbol for _PC_PIPE_BUF\n");#endif#ifdef SYMLINK_MAXprintf("SYMLINK_MAX defined to be %ld\n",(long)SYMLINK_MAX+0);#elseprintf("no symbol for SYMLINK_MAX\n");#endif#ifdef _PC_SYMLINK_MAXpr_pathconf("SYMLINK_MAX =", argv[1], _PC_SYMLINK_MAX);#elseprintf("no symbol for _PC_SYMLINK_MAX\n");#endif#ifdef _POSIX_TIMESTAMP_RESOLUTIONprintf("_POSIX_TIMESTAMP_RESOLUTION defined to be %ld\n",(long)_POSIX_TIMESTAMP_RESOLUTION+0);#elseprintf("no symbol for _POSIX_TIMESTAMP_RESOLUTION\n");#endif#ifdef _PC_TIMESTAMP_RESOLUTIONpr_pathconf("_POSIX_TIMESTAMP_RESOLUTION =", argv[1], _PC_TIMESTAMP_RESOLUTION);#elseprintf("no symbol for _PC_TIMESTAMP_RESOLUTION\n");#endifexit(0);}staticvoidpr_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);elseerr_sys("sysconf error");}else{fputs(" (no limit)\n", stdout);}}else{printf(" %ld\n", val);}}staticvoidpr_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);elseerr_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);intmain(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);}staticvoidpr_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);elseerr_sys("sysconf error");}else{fputs(" (no limit)\n", stdout);}}else{printf(" %ld\n", val);}}staticvoidpr_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);elseerr_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_MAXstaticlong openmax = OPEN_MAX;#elsestaticlong openmax =0;#endif/** If OPEN_MAX is indeterminate, this might be inadequate.*/#define OPEN_MAX_GUESS 256longopen_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_MAXstaticlong openmax = OPEN_MAX;#elsestaticlong openmax =0;#endif/** If OPEN_MAX is indeterminate, this might be inadequate.*/#define OPEN_MAX_GUESS 256longopen_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类型的编号),分 ...
随机推荐
- 验证代理IP
##author:wuhao#import urllib.requestfrom http import cookiejar import xlrd import threading #有效的代理,可 ...
- Hello World -- 第一篇博客
今年注定是不寻常的一年,因为技术,接触了许多大牛.通过一篇篇博文,看到了大牛们勤奋好学.孜孜不倦的精神,于是决定也开个博客,向大牛学习. 博客开了,写点什么呢?奈何肚子里墨水不多,吐出来也多是白沫,不 ...
- 运维&网络知识(一)
1. DNS 域名系统(Domain Name System),因特网上作为域名和IP地址映射的一个分布式数据库.
- socket__服务端于客户端
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2017/8/23 15:33 # @Author : Mr_zhang # @Site ...
- 开始Java8之旅(四) --四大函数接口
前言 Java8中函数接口有很多,大概有几十个吧,具体究竟是多少我也数不清,所以一开始看的时候感觉一脸懵逼,不过其实根本没那么复杂,毕竟不应该也没必要把一个东西设计的很复杂. 几个单词 在学习 ...
- KDevelop使用笔记【中文】
师从官方文档: https://userbase.kde.org/KDevelop4/Manual https://docs.kde.org/trunk5/en/extragear-kdevelop/ ...
- 2017上海QCon之旅总结(上)
本来这个公众号的交流消息中间件相关的技术的.这周去上海参加了QCon,第一次参加这样的技术会议,感受挺多的,所以整理一下自己的一些想法接公众号和大家交流一下. 下面进入正题,从自己参加了的一些分享中挑 ...
- Java boolean类型
有关java boolean类型的定义: The boolean data type has only two possible values: true and false. Use this da ...
- LINUX 笔记-重定向 :<,<<,>,>>
command>filename 把标准输出重定向到一个新文件中 command>>filename 把标准输出重定向到一个文件中(追加) command 1>filena ...
- AVL 树
一棵AVL树是每个节点的左子树和右子树的高度最多差1的二叉查找树 SearchTree Insert(ElementType X, SearchTree T) { if (T == NULL) { T ...