The Portable Operating System Interface (POSIX)

Portable Operating System Interface (POSIX) banner

What is POSIX?

The computer as we know it today is a system that comprises different parts like file I/O, process management, system calls etc. Due to the incompatibility between computer systems in the 80s, there was a need to standardise certain parts of the computer system to maintain compatibility and interoperability between the vendors of each computer system.

Portable Operating System Interface (POSIX) is a set of specifications crafted by the Institute of Electrical and Electronics Engineers that standardises the interoperability of Operating Systems. The specification outlines the common interface that systems deemed POSIX-compliant must implement to allow for the portability of programs between operating systems.

The POSIX standards aim to standardise the application programming interface (API), command line shell, and utility interfaces for Unix-like operating systems. These standards cover a wide range of functionalities, including file I/O, process management, system calls, and inter-process communication.

The Open Group and IEEE

The Open Group is a consortium that focuses on developing technology standards and certifications, particularly in areas related to enterprise architecture, information technology, and IT management. The Open Group is widely known for its development and maintenance of the TOGAF (The Open Group Architecture Framework) and the UNIX certification, as well as the Single UNIX Specification.

The IEEE (Institute of Electrical and Electronics Engineers) is a large professional organization known for its contributions to the advancement of technology, electrical engineering, and associated fields. It is involved in developing standards, fostering technological innovation, and organizing conferences and publications in various technical domains. POSIX as a standard was first introduced in 1988 before the Single UNIX Specification which is partly based on the POSIX framework. It was a way to unify all the UNIX forks and UNIX-like systems. However, because the IEEE does not own the UNIX trademark, POSIX is not considered a UNIX specification.

The Open Group released the Single UNIX Specification (SUSv2) in 1997 based on IEEE’s work on the POSIX standard. Work on SUSv3 started in 2001 from a joint working group between IEEE and The Open Group known as the Austin Group. It was released on January 30, 2002 SUSv3 is also known as POSIX:2001.

There is now also POSIX:2004 and POSIX:2008 which is the core of SUSv4. As for what UNIX is, UNIX is whatever the current registered trademark holder says it is. Since 1994, that has been The Open Group.

Linux, Unix and the C Library API.

UNIX is the building block on which the POSIX standard was first created. UNIX and the C language API are intertwined. POSIX standards are heavily influenced by UNIX, and Linux, being UNIX-like and POSIX-compliant, has a close relationship with both POSIX and UNIX. The C language serves as the primary language for implementing POSIX Compliant APIs, providing a standardised way for applications to interact with the underlying Operating System thereby promoting portability and compatibility between various systems.

The C programming language plays a significant role in the POSIX standards. POSIX interfaces are primarily defined in terms of C language APIs. The POSIX standards specify functions, macros, and conventions for C programming that are intended to provide a consistent interface for interacting with the operating system. These standardized APIs cover a wide range of functionalities, including file I/O, process control, memory management, and more.

Posix Specification for Certain Utilities

C APIs

POSIX specification greatly extends ANSI C with things like:

Those APIs also determine the underlying system concepts on which they depend, e.g. fork requires a concept of a process. Many Linux system calls exist to implement a specific POSIX C API function and make Linux compliant, e.g. sys_write, sys_read, Many of those syscalls also have Linux-specific extensions, however. Major Linux desktop implementation: glibc, which in many cases just provides a shallow wrapper to system calls.

CLI Utilities

E.g: cd, ls, echo. Many utilities are direct shell front ends for a corresponding C API function, e.g. mkdir. Major Linux desktop implementation: GNU Coreutils for the small ones, separate GNU projects for the big ones: sed, grep, awk, Some CLI utilities are implemented by Bash as built-ins.

Shell Language

The POSIX standard specifies how each line in the command line is read into the stdin, analysed, parsed, and the result returned to the stdout. It provides rules around token recognition, characters with special meaning to the command lines, and how to handle complexities that may arise due to these special characters having different meanings in a given context.

E.g., a=b; echo “$a”

Environment Variables

POSIX Standard introduces the HOME and PATH variables to the existing list of environment variables available in all UNIX and UNIX-like systems. Also, it specifies the search semantics for the PATH variable rules guiding how commands related to the PATH variable are executed. See this section of the POSIX specification to see the list of rules regarding environment variables

Program exit status code

There are already defined exit status codes for Unix-like systems. Status codes such as 0 and EXIT_SUCCESS for successful operations and non-zero exit status codes or EXIT_FAILURE for failed operations.

The POSIX Standard extends the list of exit status codes that are available within a Unix-like system. Some of the examples include:

Directory Structure

According to Wikipedia, the Filesystem Hierarchy Standard (FHS) is a reference describing the conventions used for the layout of Unix-like systems. It has been made popular by its use in Linux distributions, but it is used by other Unix-like systems as well. It is maintained by the Linux Foundation. The latest version is 3.0, released on June 3rd, 2015.

The POSIX standard extends the FHS by adding a few more directories to the existing list of directories specified by the Filesystem Hierarchy Standard. Examples of these files include the “/tmp” which holds temporary files.

Conclusion

We have looked at a brief guide to understanding the Portable Operating System Interface (POSIX), the need for POSIX, and the problem it seeks to solve. The POSIX standard is an essential concept when understanding the UNIX ecosystem.

Here is a link to the entire POSIX standard specification.