• 沒有找到結果。

Exercises

Chapter 2. UNIX Standardization and Implementations

2.2. UNIX Standardization

2.2.2. IEEE POSIX

POSIX is a family of standards developed by the IEEE (Institute of Electrical and Electronics Engineers). POSIX stands for Portable Operating System Interface. It originally referred only to the IEEE Standard 1003.11988the operating system interfacebut was later extended to include many of the standards and draft standards with the 1003 designation, including the shell and utilities (1003.2).

Of specific interest to this book is the 1003.1 operating system interface standard, whose goal is to promote the portability of applications among various UNIX System environments. This standard defines the services that must be provided by an operating system if it is to be

"POSIX compliant," and has been adopted by most computer vendors. Although the 1003.1 standard is based on the UNIX operating system, the standard is not restricted to UNIX and UNIX-like systems. Indeed, some vendors supplying proprietary operating systems claim that these systems have been made POSIX compliant, while still leaving all their proprietary features in place.

Because the 1003.1 standard specifies an interface and not an implementation, no distinction is made between system calls and library functions. All the routines in the standard are called functions.

Standards are continually evolving, and the 1003.1 standard is no exception. The 1988 version of this standard, IEEE Standard 1003.11988, was modified and submitted to the International Organization for Standardization. No new interfaces or features were added, but the text was revised. The resulting document was published as IEEE Std 1003.11990 [IEEE 1990]. This is also the international standard ISO/IEC 99451:1990. This standard is commonly referred to as POSIX.1, which we'll use in this text.

The IEEE 1003.1 working group continued to make changes to the standard. In 1993, a revised version of the IEEE 1003.1 standard was published. It included 1003.1-1990 standard and the 1003.1b-1993 real-time extensions standard. In 1996, the standard was again updated as international standard ISO/IEC 99451:1996. It included interfaces for multithreaded programming, called pthreads for POSIX threads. More real-time interfaces were added in 1999 with the publication of IEEE Standard 1003.1d-1999. A year later, IEEE Standard 1003.1j-2000 was published, including even more real-time interfaces, and IEEE Standard 1003.1q-2000 was published, adding event-tracing extensions to the standard.

The 2001 version of 1003.1 departed from the prior versions in that it combined several 1003.1 amendments, the 1003.2 standard, and portions of the Single UNIX Specification (SUS), Version 2 (more on this later). The resulting standard, IEEE Standard 1003.1-2001, includes the following other standards:

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 revision)

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)

IEEE Standard 1003.2d-1994 (batch extensions)

IEEE P1003.2b draft standard (additional utilities)

Parts of IEEE Standard 1003.1g-2000 (protocol-independent interfaces)

ISO/IEC 9945-2 (IEEE Standard 1003.2-1993)

The Base Specifications of the Single UNIX Specification, version 2, which include

System Interface Definitions, Issue 5

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks.

Commands and Utilities, Issue 5

System Interfaces and Headers, Issue 5

Open Group Technical Standard, Networking Services, Issue 5.2

ISO/IEC 9899:1999, Programming Languages - C

Figure 2.2, Figure 2.3, and Figure 2.4 summarize the required and optional headers as specified by POSIX.1. Because POSIX.1 includes the ISO C standard library functions, it also requires the headers listed in Figure 2.1. All four figures summarize which headers are included in the implementations discussed in this book.

Figure 2.2. Required headers defined by the POSIX standard

Header FreeBSD

5.2.1 Linux 2.4.22

Mac OS X

10.3 Solaris 9 Description

<dirent.h> • • • • directory entries (Section 4.21)

<fcntl.h> • • • • file control (Section 3.14)

<fnmatch.h> • • • • filename-matching types

<glob.h> • • • • pathname pattern-matching types

<grp.h> • • • • group file (Section 6.4)

<netdb.h> • • • • network database operations

<pwd.h> • • • • password file (Section 6.2)

<regex.h> • • • • regular expressions

<tar.h> • • • • tar archive values

<termios.h> • • • • terminal I/O (Chapter 18)

<unistd.h> • • • • symbolic constants

<utime.h> • • • • file times (Section 4.19)

<wordexp.h> • • • word-expansion types

<arpa/inet.h> • • • • Internet definitions (Chapter 16)

<net/if.h> • • • • socket local interfaces (Chapter 16)

<netinet/in.h> • • • • Internet address family (Section 16.3)

<netinet/tcp.h> • • • • Transmission Control Protocol definitions

<sys/mman.h> • • • • memory management declarations

<sys/select.h> • • • • select function (Section 14.5.1)

<sys/socket.h> • • • • sockets interface (Chapter 16)

<sys/stat.h> • • • • file status (Chapter 4)

<sys/times.h> • • • • process times (Section 8.16)

<sys/types.h> • • • • primitive system data types (Section 2.8)

Header FreeBSD

5.2.1 Linux 2.4.22

Mac OS X

10.3 Solaris 9 Description

<sys/un.h> • • • • UNIX domain socket definitions (Section

17.3)

<sys/utsname.h> • • • • system name (Section 6.9)

<sys/wait.h> • • • • process control (Section 8.6)

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks

.

Figure 2.3. XSI extension headers defined by the POSIX standard

Header FreeBSD

5.2.1 Linux 2.4.22

Mac OS X

10.3 Solaris 9 Description

<cpio.h> • • • cpio archive values

<dlfcn.h> • • • • dynamic linking

<fmtmsg.h> • • • message display structures

<ftw.h> • • file tree walking (Section 4.21)

<iconv.h> • • • codeset conversion utility

<langinfo.h> • • • • language information constants

<libgen.h> • • • • definitions for pattern-matching function

<monetary.h> • • • • monetary types

<ndbm.h> • • • database operations

<nl_types.h> • • • • message catalogs

<poll.h> • • • • poll function (Section 14.5.2)

<search.h> • • • • search tables

<strings.h> • • • • string operations

<syslog.h> • • • • system error logging (Section 13.4)

<ucontext.h> • • • • user context

<ulimit.h> • • • • user limits

<utmpx.h> • • user accounting database

<sys/ipc.h> • • • • IPC (Section 15.6)

<sys/msg.h> • • • message queues (Section 15.7)

<sys/resource.h> • • • • resource operations (Section 7.11)

<sys/sem.h> • • • • semaphores (Section 15.8)

<sys/shm.h> • • • • shared memory (Section 15.9)

<sys/statvfs.h> • • • file system information

<sys/time.h> • • • • time types

<sys/timeb.h> • • • • additional date and time definitions

<sys/uio.h> • • • • vector I/O operations (Section 14.7)

Figure 2.4. Optional headers defined by the POSIX standard

Header FreeBSD

5.2.1 Linux 2.4.22

Mac OS X

10.3 Solaris 9 Description

<aio.h> • • • • asynchronous I/O

<mqueue.h> • • message queues

<pthread.h> • • • • threads (Chapters 11 and 12)

<sched.h> • • • • execution scheduling

<semaphore.h> • • • • semaphores

<spawn.h> • real-time spawn interface

<stropts.h> • • XSI STREAMS interface (Section 14.4)

<trace.h> event tracing

In this text we describe the 2001 version of POSIX.1, which includes the functions specified in the ISO C standard. Its interfaces are divided into required ones and optional ones. The optional interfaces are further divided into 50 sections, based on functionality. The sections containing nonobsolete programming interfaces are summarized in Figure 2.5 with their respective option codes. Option codes are two- to three-character abbreviations that help identify the interfaces that belong to each functional area. The option codes highlight text on manual pages where interfaces depend on the support of a particular option. Many of the options deal with real-time extensions.

Figure 2.5. POSIX.1 optional interface groups and codes

Code SUS mandatory Symbolic constant Description

ADV _POSIX_ADVISORY_INFO advisory information (real-time)

AIO _POSIX_ASYNCHRONOUS_IO asynchronous input and output (real-time)

BAR _POSIX_BARRIERS barriers (real-time)

CPT _POSIX_CPUTIME process CPU time clocks (real-time)

CS _POSIX_CLOCK_SELECTION clock selection (real-time)

CX • extension to ISO C standard

FSC • _POSIX_FSYNC file synchronization

IP6 _POSIX_IPV6 IPv6 interfaces

MF • _POSIX_MAPPED_FILES memory-mapped files

ML _POSIX_MEMLOCK process memory locking (real-time)

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks

.

Code SUS mandatory Symbolic constant Description

MLR _POSIX_MEMLOCK_RANGE memory range locking (real-time)

MON _POSIX_MONOTONIC_CLOCK monotonic clock (real-time)

MPR • _POSIX_MEMORY_PROTECTION memory protection

MSG _POSIX_MESSAGE_PASSING message passing (real-time)

MX IEC 60559 floating-point option

PIO _POSIX_PRIORITIZED_IO prioritized input and output

PS _POSIX_PRIORITIZED_SCHEDULING process scheduling (real-time)

RS _POSIX_RAW_SOCKETS raw sockets

RTS _POSIX_REALTIME_SIGNALS real-time signals extension

SEM _POSIX_SEMAPHORES semaphores (real-time)

SHM _POSIX_SHARED_MEMORY_OBJECTS shared memory objects (real-time)

SIO _POSIX_SYNCHRONIZED_IO synchronized input and output (real-time)

SPI _POSIX_SPIN_LOCKS spin locks (real-time)

SPN _POSIX_SPAWN spawn (real-time)

SS _POSIX_SPORADIC_SERVER process sporadic server (real-time)

TCT _POSIX_THREAD_CPUTIME thread CPU time clocks (real-time)

TEF _POSIX_TRACE_EVENT_FILTER trace event filter

THR • _POSIX_THREADS threads

TMO _POSIX_TIMEOUTS timeouts (real-time)

TMR _POSIX_TIMERS timers (real-time)

TPI _POSIX_THREAD_PRIO_INHERIT thread priority inheritance (real-time)

TPP _POSIX_THREAD_PRIO_PROTECT thread priority protection (real-time)

TPS _POSIX_THREAD_PRIORITY_SCHEDULING thread execution scheduling (real-time)

TRC _POSIX_TRACE trace

TRI _POSIX_TRACE_INHERIT trace inherit

Code SUS mandatory Symbolic constant Description

TRL _POSIX_TRACE_LOG trace log

TSA • _POSIX_THREAD_ATTR_STACKADDR thread stack address attribute

TSF • _POSIX_THREAD_SAFE_FUNCTIONS thread-safe functions

TSH • _POSIX_THREAD_PROCESS_SHARED thread process-shared synchronization

TSP _POSIX_THREAD_SPORADIC_SERVER thread sporadic server (real-time)

TSS • _POSIX_THREAD_ATTR_STACKSIZE thread stack address size

TYM _POSIX_TYPED_MEMORY_OBJECTS typed memory objects (real-time)

XSI • _XOPEN_UNIX X/Open extended interfaces

XSR _XOPEN_STREAMS XSI STREAMS

POSIX.1 does not include the notion of a superuser. Instead, certain operations require "appropriate privileges," although POSIX.1 leaves the definition of this term up to the implementation. UNIX systems that conform to the Department of Defense security guidelines have many levels of security. In this text, however, we use the traditional terminology and refer to operations that require superuser privilege.

After almost twenty years of work, the standards are mature and stable. The POSIX.1 standard is maintained by an open working group known as the Austin Group (http://www.opengroup.org/austin). To ensure that they are still relevant, the standards need to be either updated or reaffirmed every so often.