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.
| Volume | Content | Main audience |
|---|---|---|
| Base Definitions | Terms, headers, environment variables, regular expressions | Library and compiler authors |
| System Interfaces | C functions such as fork, read, pthread_create | Application developers |
| Shell and Utilities | The sh language and commands such as ls, grep, awk | Script authors and administrators |
| Rationale | Explanations of design decisions and history | Implementers and reviewers |
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.
| Family | Representative functions | Kernel concept involved |
|---|---|---|
| Process control | fork, exec, waitpid, _exit | Process creation and scheduling |
| File and I/O | open, read, write, close, lseek | File descriptors and the virtual file system |
| Signals | sigaction, kill, sigprocmask | Asynchronous notification and interrupts |
| Threads | pthread_create, pthread_mutex_lock | Kernel threads and context switch |
| IPC | pipe, mq_open, shm_open, sem_open | Inter-process communication |
| Memory | mmap, munmap, mprotect | Virtual memory and paging |
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.
| System | Relationship to POSIX | Practical consequence |
|---|---|---|
| macOS | Certified as UNIX 03 on supported versions | Formally conformant shell and APIs |
| AIX, HP-UX, Solaris | Certified Unix systems | Strong conformance, vendor extensions |
| Linux distributions | Largely compliant, mostly uncertified | Behaves as POSIX with documented deviations |
| FreeBSD | Largely compliant, not certified | Close conformance with BSD extensions |
| QNX, VxWorks | Real-time systems with POSIX profiles | Portable code on embedded targets |
| Windows | Not POSIX; compatibility via WSL or Cygwin | Native Win32 API differs fundamentally |
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.
| Situation | Recommended choice | Reason |
|---|---|---|
| Shell script for many systems | Use plain sh syntax, avoid bash extensions | Only the POSIX shell language is guaranteed |
| Need for threads | Use pthreads | Available on every major Unix-like system |
| High-performance event loop | Wrap epoll or kqueue behind one interface | POSIX only standardizes poll and select |
| Resource limits | Query sysconf at runtime | Limits vary between implementations |
| Native Windows target | Use an abstraction library | Windows lacks fork and POSIX signals |
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
echotreats backslashes, so portable scripts preferprintf.
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.