{
  "id": "posix",
  "title": "POSIX",
  "lang": "en",
  "source_lang": "en",
  "summary": "POSIX is a family of standards defining operating-system interfaces, command-line utilities, and shell behavior to support portable software.",
  "category": "computer-science",
  "subcategory": "software",
  "type": "concept",
  "aliases": [
    "Portable Operating System Interface",
    "IEEE Std 1003.1",
    "ISO/IEC/IEEE 9945"
  ],
  "generated_at": "2026-11-03",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/posix/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/posix/",
      "json": "https://aiwiki.page/zh/posix.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "POSIX, short for Portable Operating System Interface, is a family of standards specifying interfaces between application software and an operating system. Its central purpose is to make programs portable across different implementations: software written against the standardized interfaces can often be moved to another conforming system by recompiling it, rather than redesigning its interaction with the operating system. POSIX covers programming interfaces, command-line utilities, and the shell language used to combine those utilities.\n\nThe standards grew out of Unix, but POSIX is neither a particular Unix implementation nor a requirement to use a Unix-derived kernel. It describes externally observable behavior rather than prescribing internal architecture. Its specifications include process creation, files and directories, input and output, threads, synchronization, signals, networking interfaces, and text-processing commands. The principal standard is IEEE Std 1003.1, developed in coordination with international standardization and The Open Group; its 2024 revision is also published as Issue 8 of the Base Specifications.\n\nPOSIX has provided a common foundation for commercial Unix systems, Linux environments, development tools, and software portability layers. Its significance lies as much in the precise definition of edge cases—such as interrupted operations, pathname resolution, or concurrent access—as in its familiar function names. Understanding POSIX therefore requires distinguishing the standard from particular implementations, source portability from binary compatibility, and formal conformance from broad practical compatibility."
    },
    {
      "heading": "Historical development and institutional organization",
      "text": "The need for POSIX arose from the proliferation of Unix variants during the 1970s and 1980s. Unix, originally developed at Bell Labs, spread through universities, research organizations, and commercial vendors. Although these systems shared concepts such as hierarchical directories, processes, pipes, and a C programming environment, their interfaces diverged. Differences between AT&T’s System V lineage and the Berkeley Software Distribution were especially important. A program could depend on facilities available on one system but absent or behaviorally different on another, making software maintenance expensive.\n\nEarly efforts sought to identify a stable common interface without requiring vendors to adopt a single implementation. The IEEE’s standardization work produced IEEE Std 1003.1-1988, the first published POSIX.1 standard, concentrating on operating-system interfaces associated with C programs. Richard Stallman is credited with suggesting the name POSIX. The name emphasized portability and retained an association with Unix without using the Unix trademark as the standard’s title. An international version followed as ISO/IEC 9945-1:1990.\n\nThe original specification did not encompass everything now associated with POSIX. Shell and utility behavior was standardized separately in POSIX.2, published in 1992. Other projects developed real-time interfaces, threads, and additional facilities. The real-time extensions commonly associated with POSIX.1b were standardized in 1993, while the threads extension associated with POSIX.1c followed in 1995. These historical names remain common in technical discussion even though later editions integrated much of the material into a consolidated specification.\n\nA major organizational change came with the formation of the Austin Group in 1998. Bringing together participants from IEEE, The Open Group, and ISO/IEC JTC 1, it worked toward a common text for previously overlapping standards. The 2001 revision of POSIX.1 and Issue 6 of The Open Group’s Base Specifications established this unified basis. Later major publications included the 2008 revision, the 2017 edition incorporating accumulated corrections, and the 2024 revision, corresponding to Issue 8.\n\nPOSIX and the Single UNIX Specification are closely connected but are not interchangeable labels. The shared Base Specifications supply much of their technical foundation, while UNIX certification is associated with The Open Group’s product standards and trademark program. Historical editions have also distinguished a base interface set from additional X/Open System Interfaces, commonly called XSI extensions. Consequently, “Unix-like,” “POSIX-conforming,” and “UNIX-certified” express different claims: resemblance, standards conformance, and participation in a defined certification system."
    },
    {
      "heading": "Scope, specification structure, and the portability contract",
      "text": "POSIX primarily defines a source-level contract between applications and their execution environment. An application programming interface specifies functions, types, constants, headers, and associated behavior. For example, the specification for a file-reading function describes not only its declaration but also its return values, error conditions, and interaction with other operations. A conforming implementation may realize that function through a kernel entry point, a library routine, or a combination of mechanisms. The standard does not generally dictate that implementation choice.\n\nThis distinction is important because a POSIX function is not necessarily a system call. Applications usually invoke interfaces through a language library, such as the GNU C Library on many Linux systems. The library may translate arguments, perform additional work, or use different kernel facilities depending on the platform. Conversely, a kernel may expose many operations that POSIX never specifies. Portability depends on the behavior visible to the application, not on identical kernel internals.\n\nThe consolidated standard is organized into four principal parts: Base Definitions, System Interfaces, Shell and Utilities, and Rationale. Base Definitions establishes terminology, headers, data types, and general rules. System Interfaces specifies callable functions. Shell and Utilities defines the command language and standard commands. Rationale explains design decisions and historical considerations; it is informative rather than a source of additional conformance requirements. Reading a function entry in isolation can therefore miss rules established elsewhere, including conventions for errors, strings, or thread interactions.\n\nThe C programming language provides the main notation for system interfaces, but POSIX is not simply an extension of the C language standard. ISO C defines language semantics and a portable library that need not assume a Unix-style environment. POSIX adds a richer operating-system model: processes, file descriptors, ownership, signals, directories, and other facilities. Other languages can expose these operations through bindings, but the portability of those bindings also depends on the language runtime and its own specifications.\n\nPOSIX carefully distinguishes kinds of permitted variability. Implementation-defined behavior requires an implementation to document its choice; unspecified behavior permits alternatives without requiring such documentation; undefined behavior imposes no requirements in the relevant circumstances. The standard also defines limits and option indicators rather than assuming that every implementation has identical capacities. This framework creates a bounded portability contract, not a promise that all systems behave identically in every respect.\n\nPOSIX does not prescribe a graphical desktop, package manager, service manager, complete directory layout, or device-driver architecture. Nor does it establish a universal application binary interface. Executable formats, calling conventions, machine instructions, and library binary layouts can differ between systems that implement the same POSIX interfaces."
    },
    {
      "heading": "Processes, program execution, and signals",
      "text": "The POSIX execution model centers on the process, an execution environment containing resources and attributes such as an address space, open file descriptors, credentials, a working directory, and signal dispositions. A process can contain multiple threads, but it remains an important unit for resource ownership and program execution. Parent-child relationships connect processes into a hierarchy, while process identifiers provide handles for operations such as waiting for termination or sending signals.\n\nThe traditional process-creation sequence combines fork() with an exec function. fork() creates a child process whose initial state largely derives from the parent. It returns twice: once in the parent, with the child’s identifier, and once in the child, with a return value of zero. An exec function then replaces the calling process’s program image with another program while retaining the process identity and selected attributes. This separation allows a shell to create a child, arrange redirections, and then execute a command.\n\nThe model specifies observable semantics rather than requiring a complete physical copy of memory. Implementations commonly use copy-on-write techniques, sharing memory pages until a process modifies them. POSIX also provides posix_spawn(), which combines program creation with controlled setup operations. It is particularly useful where the full generality of fork() is unnecessary or expensive. Neither interface implies that every inherited attribute remains unchanged: close-on-exec flags, signal rules, and other specified transitions determine what survives execution of a new program.\n\nParent processes use waiting interfaces such as waitpid() to collect termination information. A terminated child can retain a small amount of status information until that information is collected, producing the state commonly called a zombie. Process groups and sessions support job control and terminal interaction. They allow a shell to treat a pipeline as a job and coordinate foreground and background execution, rather than managing each command independently.\n\nSignals provide asynchronous notification of events such as termination requests, arithmetic faults, or terminal-generated interrupts. Each signal has rules governing its default action, whether it can be blocked, and whether an application can install a handler. SIGKILL and SIGSTOP cannot be caught, blocked, or ignored. In multithreaded programs, signal dispositions are generally process-wide, while signal masks belong to individual threads; delivery rules distinguish signals directed at a process from those directed at a particular thread.\n\nSignal handlers impose unusually strict constraints. A handler can interrupt library code while shared internal state is inconsistent, so only designated async-signal-safe operations can be relied upon in that context. Ordinary formatted output and dynamic memory allocation are not generally safe choices. Blocking operations can also fail with EINTR when interrupted, although restart behavior depends on the operation and signal configuration. These details make signals substantially more than a simple event-callback mechanism."
    },
    {
      "heading": "Files, descriptors, and input-output semantics",
      "text": "POSIX presents a hierarchical file system whose objects are reached through pathnames. A pathname can be absolute, beginning at the root directory, or relative to a process’s working directory or another specified directory. Directories associate names with objects; they are not merely textual prefixes. Pathname resolution consequently has rules for directory search permissions, symbolic links, special components such as . and .., and failure conditions encountered while traversing the hierarchy.\n\nA central abstraction is the file descriptor, a small non-negative integer used by a process to refer to an open resource. The conventional descriptors 0, 1, and 2 identify standard input, standard output, and standard error when those streams are established in the usual way. Functions including open(), read(), write(), and close() operate on descriptors. Pipes, terminals, and sockets can also participate in this model, allowing common operations without implying that every resource supports every file operation.\n\nA descriptor is distinct from an open file description. The latter holds state such as the current file offset and file status flags. Duplicated descriptors, or descriptors inherited through fork(), can refer to the same open file description and therefore share that state. By contrast, opening the same regular file independently normally creates distinct open file descriptions with separate offsets. This distinction explains why a read in one process can affect the position used by another process sharing an inherited descriptor.\n\nPOSIX input and output are byte-oriented, and successful operations do not necessarily transfer the requested amount. A read can return fewer bytes because less data is currently available or because the end of a regular file has been reached. A write can also complete only partially. Applications must distinguish a positive transfer count, a zero return where applicable, and an error indication; treating any successful call as a complete transfer is not portable. Nonblocking operation introduces additional conditions, commonly reported through EAGAIN or, where applicable, EWOULDBLOCK.\n\nNames and object lifetimes are separate. A hard link creates another directory entry referring to the same file, whereas a symbolic link contains a pathname used in subsequent resolution. Removing a name with unlink() does not necessarily destroy the underlying object immediately: an open file can remain accessible through existing descriptors after its last directory entry has disappeared. Renaming provides important atomic namespace operations, but namespace atomicity is not equivalent to persistence after a power failure.\n\nPermissions and ownership supply a basic access-control model using user and group identities and mode bits. Interfaces such as fstat() and the directory-relative *at() family also help programs operate on already identified objects instead of repeatedly resolving potentially changing pathnames. POSIX defines significant behavior here, but it does not standardize every filesystem feature, administrative policy, or crash-recovery guarantee."
    },
    {
      "heading": "Threads, synchronization, and interprocess communication",
      "text": "The POSIX threads interfaces, widely known as Pthreads, define a portable model for multiple threads of control within a process. Threads share the process’s address space and many resources while maintaining individual execution state, including stacks and scheduling attributes. pthread_create() starts a thread, and pthread_join() allows another thread to wait for its termination and obtain its result. Detached threads have different resource-reclamation rules and cannot subsequently be joined.\n\nThese interfaces support concurrent computing, but concurrency introduces requirements that single-threaded programs can avoid. Accessing shared mutable state without appropriate coordination can create data races and invalid assumptions about memory visibility. POSIX specifies synchronization effects for operations such as mutex locking and unlocking. A mutex is therefore not merely a convention that discourages simultaneous access; it participates in the ordering guarantees on which correctly synchronized programs depend.\n\nCondition variables allow threads to wait for changes in application state. A wait operation releases an associated mutex and, before returning, reacquires it. The condition variable itself does not store the application’s logical condition, and a return from a wait does not prove that the desired predicate is true. The predicate is normally tested under the mutex in a loop, accounting for spurious wakeups and for competing threads that may alter the state before the awakened thread proceeds. This distinction is fundamental to correct synchronization.\n\nThe standard also includes facilities such as read-write locks, semaphores, thread-specific data, one-time initialization, and cancellation. Their purposes differ: a semaphore maintains a count, a mutex establishes ownership-based exclusion, and thread-specific data associates separate values with different threads under a common key. Cancellation introduces cleanup requirements and is deferred to defined cancellation points in the normal deferred mode. Many Pthreads routines return an error number directly rather than reporting failure through the -1 and errno convention familiar from numerous other POSIX interfaces.\n\nPOSIX interprocess communication extends beyond threads. Pipes and FIFOs provide byte streams; shared memory allows processes to map common storage; message queues preserve message boundaries and support priorities. Shared memory does not itself provide coordination, so applications must combine it with suitable synchronization. Some synchronization objects can be configured for use across processes, subject to the interface’s requirements and implementation support.\n\nScheduling and real-time facilities add further constraints. Policies such as SCHED_FIFO and SCHED_RR define behavior for eligible threads under specified conditions, while priority-inheritance mutexes address certain forms of priority inversion. These mechanisms do not automatically make an application deterministic. Page faults, device operations, interrupt handling, resource contention, and implementation limits still affect timing. The availability of an interface and the operating environment’s ability to meet a deadline are separate questions."
    },
    {
      "heading": "Shell language, utilities, and text processing",
      "text": "POSIX standardizes not only callable functions but also a shell command language and a collection of utilities. This layer makes scripts and command-based build procedures portable across systems. The standardized sh language defines command execution, variables, quoting, expansions, redirections, pipelines, functions, and control structures. It is not synonymous with every feature supported by Bash, KornShell, or another implementation; those shells may provide extensions beyond a particular POSIX edition.\n\nShell evaluation has several stages whose interaction determines behavior. Parsing identifies language constructs, while expansions can substitute variable values, execute commands, perform arithmetic, split fields, and expand pathname patterns in appropriate contexts. Quoting affects these stages. For example, \"$name\" preserves a variable’s expanded value as a single field in ordinary argument contexts, whereas an unquoted expansion can undergo field splitting and pathname expansion. Such distinctions explain why a script may fail on filenames containing spaces or wildcard characters even when its command names are fully standardized.\n\nPipelines connect the standard output of one command to the standard input of another. Redirections can change those connections, open files, or duplicate descriptors. Their order matters: command >out 2>&1 directs both standard output and standard error to out, whereas command 2>&1 >out first duplicates the original standard-output destination for standard error and only then redirects standard output. The shell’s syntax is therefore closely tied to the underlying descriptor model rather than being merely a notation for launching programs.\n\nStandard utilities include text-processing tools such as sed, awk, grep, sort, and cut, along with commands for file manipulation, process interaction, comparison, archiving, and development. Their portability comes from specified options, input formats, output behavior, and exit statuses. An implementation may offer additional options, but scripts relying on those options are no longer portable solely by virtue of POSIX. Similarly, familiar behavior in a GNU utility is not automatically a requirement for all conforming implementations.\n\nRegular expressions are an important part of this environment. POSIX distinguishes basic and extended regular expressions, with different syntactic rules, and defines matching behavior that can differ from backtracking-oriented expression engines used elsewhere. Filename patterns used by the shell are a separate language, despite superficial similarities. An asterisk in a pathname pattern does not have the same grammatical role as an asterisk in a regular expression.\n\nText processing is also shaped by locales. Environment variables such as LANG, LC_ALL, and category-specific LC_* variables influence character classification, collation, messages, and other behavior. Consequently, sorting and pattern matching need not produce the same results in every locale. Character-oriented operations must also be distinguished from byte-oriented ones, especially with multibyte encodings such as UTF-8. POSIX portability involves controlling or accommodating these environmental properties, not merely choosing standardized command names."
    },
    {
      "heading": "Networking, clocks, and specialized facilities",
      "text": "POSIX includes the socket interface, which originated in Berkeley Unix and became a common foundation for network programming. A socket is accessed through a descriptor, but its creation and operation involve additional properties such as address family, communication type, and protocol. Typical connection-oriented server operations include socket(), bind(), listen(), and accept(), while clients commonly use connect(). Data transfer can use socket-specific functions or, in suitable cases, ordinary descriptor-based input and output.\n\nThe distinction between stream and message-oriented communication is essential. A stream socket, commonly used with the Transmission Control Protocol, carries an ordered byte stream rather than application-defined records. Separate writes by a sender do not establish corresponding read boundaries at the receiver. Applications therefore need a framing convention, such as explicit lengths or delimiters. Datagram sockets preserve message boundaries but have different delivery properties, depending on the protocol. POSIX standardizes interfaces and observable results without turning all network transports into a single communication model.\n\nAddress-handling interfaces such as getaddrinfo() help applications avoid assumptions tied to one network address format. Descriptor-readiness facilities including select() and poll() support multiplexing across multiple inputs and outputs. Readiness generally indicates that an operation can proceed under the specified conditions, not that an arbitrarily large operation will complete or that application-level work is finished. These interfaces commonly underpin an event loop, although many systems also provide non-POSIX mechanisms for handling large numbers of descriptors.\n\nTime interfaces distinguish different purposes for measuring time. A real-time clock represents civil-time-related timestamps and may be adjusted, while a monotonic clock is intended for measuring elapsed intervals without discontinuous setting changes of that kind. POSIX defines interfaces including clock_gettime() and sleep operations, with availability and supported clock properties subject to the relevant requirements and options. Confusing a wall-clock timestamp with an elapsed-time measurement can produce incorrect timeout behavior when the clock changes.\n\nTime representation also exposes a broader compatibility issue. POSIX defines the meaning of seconds since the Epoch using rules that do not count leap seconds as an additional accumulating total. Representation limits remain an implementation concern: historical systems with signed 32-bit seconds encounter the familiar January 2038 boundary, while wider time representations extend the range. POSIX conformance alone is not a substitute for checking the types, limits, and binary interfaces of a particular target.\n\nAdditional facilities cover areas such as memory mapping, asynchronous input and output, timers, and memory locking. mmap() connects files or other supported objects to an address space and interacts with virtual memory; synchronization and persistence still require attention to the applicable semantics. POSIX does not provide a complete specification for network protocols, distributed consistency, transport encryption, or every aspect of storage hardware. Those concerns depend on other standards and implementation contracts."
    },
    {
      "heading": "Source portability and implementation differences",
      "text": "POSIX portability is strongest when an application stays within the interfaces, assumptions, and environmental conditions that the standard defines. This normally means source portability: the same source code can be compiled for different systems with limited adaptation. It does not imply that one executable runs unchanged on machines with different processors, executable formats, library implementations, or calling conventions. Even closely related operating systems can agree at the source level while exposing incompatible binary interfaces.\n\nHeader visibility is one practical boundary. Implementations often support several standards profiles and extension sets simultaneously, using feature-test macros to determine which declarations are exposed. Defining _POSIX_C_SOURCE to an appropriate value before including system headers requests interfaces associated with a POSIX version; for example, 200809L is associated with POSIX.1-2008. _XOPEN_SOURCE is used for relevant X/Open environments. These macros do not add missing kernel capabilities, and the exact supported values and interactions must match the implementation.\n\nPortable code must also account for variable limits and options. Functions such as sysconf(), pathconf(), and confstr() provide information about properties of the running environment or particular filesystem objects. A compile-time constant can express a guaranteed minimum, an actual limit, or an indeterminate property according to the relevant specification. Assuming that every pathname fits into one fixed-size buffer, or that every system supports the same number of simultaneous resources, can undermine portability even when all function names are standardized.\n\nExtensions are a major source of accidental dependency. Linux provides facilities such as epoll and inotify, while other systems expose different event-notification and filesystem-monitoring mechanisms. Shells and command-line tools likewise add options and syntax. Such facilities may be valuable, but their use requires a platform-specific path or a portability abstraction. Build systems often test for particular interfaces rather than inferring every capability from an operating-system name, because versions and configurations differ.\n\nLinux environments implement a large proportion of the familiar POSIX programming model, but conformance is not a property of the Linux kernel alone. The kernel, C library, utilities, shell, and selected configuration collectively determine the application environment. Systems using different C libraries or reduced utility sets can therefore expose different capabilities. Likewise, certification of a particular commercial Unix or macOS product applies to a defined product and version, not automatically to every related release or configuration.\n\nOn Microsoft Windows, environments such as Cygwin provide a substantial POSIX-oriented compatibility layer, while Windows Subsystem for Linux supports Linux user-space environments through a different architectural approach. Neither situation makes native Windows interfaces identical to POSIX. Differences in pathname syntax, permissions, process behavior, text handling, and filesystem semantics remain important at interoperability boundaries. Portable software frequently isolates these differences in a relatively small adaptation layer."
    },
    {
      "heading": "Conformance, certification, and continuing revision",
      "text": "A conformance claim must identify the standard edition and the applicable environment. “Supports POSIX” can mean anything from implementing a useful subset of familiar functions to satisfying a formal set of requirements. The distinction matters because a function with the right name can still have incorrect error behavior, missing synchronization guarantees, or incompatible handling of edge cases. Conformance concerns the specified behavior of the environment, not just the presence of declarations in header files.\n\nFormal certification adds testing and administrative requirements to this technical foundation. The Open Group operates certification programs associated with POSIX and UNIX product standards. The details depend on the particular program and version, including the required interface set and declared implementation properties. Certification is evidence concerning a specified product under defined conditions; it is not a universal guarantee that every application will work correctly, nor a claim that the implementation contains no defects.\n\nTesting itself has limits. A test suite can exercise representative inputs, boundary conditions, and interactions, but it cannot exhaust every possible program or execution schedule. Concurrency, asynchronous signals, resource exhaustion, and unusual filesystems create especially large behavioral spaces. Implementations also need documentation for choices that the standard leaves implementation-defined. For application developers, meaningful portability testing therefore combines standards-aware review with execution on multiple systems rather than treating a single successful build as conclusive.\n\nThe standard evolves through defect reports, interpretations, technical corrections, and revisions. The Austin Group’s work frequently addresses ambiguities exposed by real programs or disagreements between implementations. A correction may clarify the intended contract, while a major revision can add interfaces, revise requirements, or remove obsolete facilities. The 2024 edition, IEEE Std 1003.1-2024 and Base Specifications Issue 8, illustrates that POSIX remains an evolving specification rather than a fixed description of 1980s Unix.\n\nThis evolution creates a recurring tension between established practice and improved design. Standardizing a widely deployed extension can make existing programs more portable, but an interface must have sufficiently clear semantics and implementation support. Conversely, retaining historical behavior can preserve compatibility while carrying forward complexity. Different versions of a utility, shell, or library may therefore correspond to different stages in the standard’s development, making edition-specific claims more useful than an undifferentiated assertion of POSIX compatibility.\n\nImportant areas remain outside its contract. Security depends on implementation quality, application design, and administrative policy as well as standardized permission and process mechanisms. POSIX does not fully specify modern container isolation, graphical environments, service supervision, or application packaging. Nor does it define a general transaction model for filesystem changes across crashes. These boundaries explain why systems sharing a POSIX foundation still require additional platform documentation for deployment, performance, security analysis, and failure recovery."
    }
  ],
  "links": [
    "operating-system",
    "unix",
    "linux",
    "bell-labs",
    "application-programming-interface",
    "system-call",
    "c-programming-language",
    "process-computing",
    "file-system",
    "access-control",
    "posix-threads",
    "concurrent-computing",
    "synchronization-computing",
    "interprocess-communication",
    "locale-computing",
    "utf-eight",
    "event-loop",
    "virtual-memory",
    "source-code",
    "microsoft-windows"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}