POSIX

Also known as: Portable Operating System Interface

On this page 7

POSIX, the Portable Operating System Interface, is a family of standards published as IEEE Std 1003.1 and ISO/IEC 9945 that defines the application programming interface, shell and utilities an operating system must provide so that source code written for one compliant system compiles and behaves the same way on another. Within operating systems and their OS fundamentals, POSIX sits at the boundary between user space and the kernel: it does not describe how a kernel works internally, only the contract that applications can rely on.

The standard grew out of the fragmentation of Unix in the 1980s, when vendors shipped incompatible variants. POSIX captured the common ground, and today it is maintained jointly by the IEEE, The Open Group and ISO, with the current revision known as POSIX.1-2024. Its text is also the core of the Single UNIX Specification, which adds certification and branding.

What the POSIX standard defines

POSIX defines interfaces, not implementations: it states what a function must do, which errors it may return and what guarantees it gives, while leaving the internal design to each system. A call such as open() must return the lowest available file descriptor, but the standard is silent on how the kernel stores open-file tables.

The modern standard is organized into four volumes, and the table below shows what each one covers and who relies on it most.

VolumeContentMain audience
Base DefinitionsTerms, headers, environment variables, regular expressionsLibrary and compiler authors
System InterfacesC functions such as fork, read, pthread_createApplication developers
Shell and UtilitiesThe sh language and commands such as ls, grep, awkScript authors and administrators
RationaleExplanations of design decisions and historyImplementers and reviewers
Volumes of the POSIX.1 standard

Earlier work was split into numbered amendments, of which POSIX.1b (real-time extensions) and POSIX.1c (threads, known as pthreads) are still widely cited. These were later merged into the single base document, so a modern compliant system offers them under one specification, although some remain formally optional.

How POSIX interfaces map to the kernel

Most POSIX functions are thin wrappers around a system call: the C library prepares arguments, triggers the transition from user space to kernel space and translates the result into a return value plus the errno variable. Some functions, such as printf, run entirely in the library and only occasionally reach the kernel through write.

The interface families below are the ones that shape how processes, files and threads behave on any POSIX-conforming system.

FamilyRepresentative functionsKernel concept involved
Process controlfork, exec, waitpid, _exitProcess creation and scheduling
File and I/Oopen, read, write, close, lseekFile descriptors and the virtual file system
Signalssigaction, kill, sigprocmaskAsynchronous notification and interrupts
Threadspthread_create, pthread_mutex_lockKernel threads and context switch
IPCpipe, mq_open, shm_open, sem_openInter-process communication
Memorymmap, munmap, mprotectVirtual memory and paging
Core POSIX interface families

The fork and exec model is the most distinctive POSIX idea. A process duplicates itself with fork, and the child replaces its image with a new program through exec. This two-step design lets the child adjust file descriptors, signals and environment before the new program starts, which is how shells implement redirection and pipelines. The newer posix_spawn function combines both steps for systems where duplicating a large address space is costly.

Levels of POSIX compliance

Operating systems relate to POSIX at three distinct levels: formal certification, practical compliance and partial compatibility layers. Confusing these levels is a common source of wrong assumptions about portability.

SystemRelationship to POSIXPractical consequence
macOSCertified as UNIX 03 on supported versionsFormally conformant shell and APIs
AIX, HP-UX, SolarisCertified Unix systemsStrong conformance, vendor extensions
Linux distributionsLargely compliant, mostly uncertifiedBehaves as POSIX with documented deviations
FreeBSDLargely compliant, not certifiedClose conformance with BSD extensions
QNX, VxWorksReal-time systems with POSIX profilesPortable code on embedded targets
WindowsNot POSIX; compatibility via WSL or CygwinNative Win32 API differs fundamentally
How common systems relate to POSIX

Certification is a commercial process: a vendor runs conformance test suites and pays for the brand. Many systems, including most Linux distributions, follow the standard closely without paying for certification. For developers, observed behavior matters more than the certificate, because even certified systems differ in optional features.

Writing portable software against POSIX

Portable code declares which version of the standard it expects by defining a feature test macro such as _POSIX_C_SOURCE set to 200809L before including headers. The system then exposes only the interfaces of that revision, which helps catch accidental use of platform-specific extensions at compile time.

Optional features are detected at runtime with sysconf, pathconf and the getconf utility, which report limits such as the maximum path length or whether real-time signals exist. The decision table below summarizes typical portability choices.

SituationRecommended choiceReason
Shell script for many systemsUse plain sh syntax, avoid bash extensionsOnly the POSIX shell language is guaranteed
Need for threadsUse pthreadsAvailable on every major Unix-like system
High-performance event loopWrap epoll or kqueue behind one interfacePOSIX only standardizes poll and select
Resource limitsQuery sysconf at runtimeLimits vary between implementations
Native Windows targetUse an abstraction libraryWindows lacks fork and POSIX signals
Portability decisions in practice

Tools such as checkbashisms and testing on at least two unrelated implementations, for example a Linux system and a BSD, reveal more portability defects than reading the standard alone.

Limitations and common misconceptions

POSIX guarantees a minimum common denominator, not complete behavior. Several practical gaps and misunderstandings recur among developers and administrators:

  • POSIX is not Unix: a system can be compliant without Unix heritage, and a Unix-derived system can lack certification.
  • Graphics, networking configuration and package management are outside the scope of the standard.
  • Modern scalable I/O interfaces such as epoll, kqueue and io_uring are not standardized, so high-performance servers still need platform code.
  • The fork model scales poorly for very large multithreaded processes, which is why posix_spawn and vfork-style optimizations exist.
  • Signal handling is notoriously subtle: only async-signal-safe functions may be called inside a handler, a rule frequently violated.
  • Implementations may deviate quietly, for example in locale handling or in how echo treats backslashes, so portable scripts prefer printf.

Despite these limits, POSIX remains the reason a C program or shell script written decades ago can still compile and run unchanged on current systems, which makes it one of the most durable agreements in computing.

A non-technical view

POSIX is a shared rulebook that many operating systems agree to follow. It lists the basic requests a program may make, such as opening a file, starting another program or waiting for a task to finish, and it says exactly how the system must answer.

Think of it like standard electrical sockets in one country. Any appliance with the right plug works in any house, whoever built the wiring behind the wall. In the same way, a program written for POSIX runs on many systems without being rewritten, because each system offers the same sockets even if its insides are different.

A concrete example

A university research group maintains a data processing tool written in C, with a set of shell scripts that start jobs and collect results. The code runs on a Linux compute cluster, on several macOS laptops used by students and on a FreeBSD storage server.

Early versions used bash arrays and the Linux-only epoll call, so the scripts failed on the FreeBSD server and the program would not compile on macOS. The maintainers rewrote the scripts in plain POSIX sh, defined _POSIX_C_SOURCE as 200809L, replaced epoll with the standard poll function and used pthreads for parallel work.

After the change, one source tree builds and runs on all three systems without conditional code for the core logic. Throughput on the cluster dropped by only a few percent, which the group accepted in exchange for removing separate maintenance branches.