The most important things POSIX 7 defines
-
Greatly extends ANSI C with things like:
- more file operations:
mkdir
,dirname
,symlink
,readlink
,link
(hardlinks), poll(),stat
,sync
, nftw() - process and threads:
fork
,execl
, wait,pipe
, semaphors sem_*, shared memory (shm_*
),kill
, scheduling parameters (nice
,sched_*
),sleep
,mkfifo
, setpgid() - networking: socket()
- memory management:
mmap
,mlock
,mprotect
,madvise
, brk() - utilities: regular expressions (
reg*
)
Those APIs also determine 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.
- more file operations:
-
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. -
E.g.,
a=b; echo "$a"
Major Linux desktop implementation: GNU Bash.
-
E.g.:
HOME
,PATH
.PATH
search semantics are specified, including how slashes prevent PATH search. -
ANSI C says
0
orEXIT_SUCCESS
for success,EXIT_FAILURE
for failure, and leaves the rest implementation defined.POSIX adds:
-
126
: command found but not executable. -
127
: command not found. -
> 128
: terminated by a signal.But POSIX does not seem to specify the
128 + SIGNAL_ID
rule used by Bash: kill - Default exit code when process is terminated? - Unix & Linux Stack Exchange
-
-
There are two types: BRE (Basic) and ERE (Extended). Basic is deprecated and only kept to not break APIs.
Those are implemented by C API functions, and used throughout CLI utilities, e.g.
grep
accepts BREs by default, and EREs with-E
.E.g.:
echo 'a.1' | grep -E 'a.[[:digit:]]'
Major Linux implementation: glibc implements the functions under regex.h which programs like
grep
can use as backend. -
E.g.:
/dev/null
,/tmp
The Linux FHS greatly extends POSIX.
-
/
is the path separatorNUL
cannot be used.
iscwd
,..
parent- portable filenames
- use at most max 14 chars and 256 for the full path
- can only contain:
a-zA-Z0-9._-
See also: what is posix compliance for filesystem?
-
Command line utility API conventions
Not mandatory, used by POSIX, but almost nowhere else, notably not in GNU. But true, it is too restrictive, e.g. single letter flags only (e.g.
-a
), no double hyphen long versions (e.g.--all
).A few widely used conventions:
-
means stdin where a file is expected--
terminates flags, e.g.ls -- -l
to list a directory named-l
See also: Are there standards for Linux command line switches and arguments?
-
"POSIX ACLs" (Access Control Lists), e.g. as used as backend for setfacl.
This was withdrawn but it was implemented in several OSes, including in Linux with setxattr.
Who conforms to POSIX?
Many systems follow POSIX closely, but few are actually certified by the Open Group which maintains the standard. Notable certified ones include:
- OS X (Apple) X stands for both 10 and UNIX. Was the first Apple POSIX system, released circa 2001. See also: Is OSX a POSIX OS?
- AIX (IBM)
- HP-UX (HP)
- Solaris (Oracle)
Most Linux distros are very compliant, but not certified because they don't want to pay the compliance check. Inspur's K-UX and Huawei's EulerOS are two certified examples.
The official list of certified systems be found at: The Register of UNIX® Certified Productsand also at the wiki page.
Windows
Windows implemented POSIX on some of its professional distributions.
Since it was an optional feature, programmers could not rely on it for most end user applications.
Support was deprecated in Windows 8:
- Where does Microsoft Windows' 7 POSIX implementation currently stand?
- sua - Does Windows 8 still implement POSIX? - Super User
- Feature request: https://windows.uservoice.com/forums/265757-windows-feature-suggestions/suggestions/6573649-full-posix-support
In 2016 a new official Linux-like API called "Windows Subsystem for Linux" was announced. It includes Linux system calls, ELF running, parts of the /proc
filesystem, Bash, GCC, (TODO likely glibc?), apt-get
and more: Running Bash on Ubuntu on Windows! | Build 2016 | Channel 9 so I believe that it will allow Windows to run much, if not all, of POSIX. However, it is focused on developers / deployment instead of end users. In particular, there were no plans to allow access to the Windows GUI.
Historical overview of the official Microsoft POSIX compatibility: The Sad History of the Microsoft POSIX Subsystem | Brian Reiter's Thoughtful Code
Cygwin is a well known GPL third-party project for that "provides substantial POSIX API functionality" for Windows, but requires that you "rebuild your application from source if you want it to run on Windows". MSYS2 is a related project that seems to add more functionality on top of Cygwin.
If the only thing from POSIX that you need are the command line utilities, also consider: GitHub - shelljs/shelljs: Portable Unix shell commands for Node.js which re-implements a bunch of CLI utilities in Node.js, which already essentially implements a portability layer for the simpler system calls like mkdir
etc. Many people use that project in the package.json
of their project to allow running the project on Windows as well. Of course, it requires users to install the Node.js runtime, but given the popularity of Node.js, I don't expect that to break/be hard to satisfy anytime soon.
Android
Android has its own C library (Bionic) which does not fully support POSIX as of Android O: Is Android POSIX-compatible?
Bonus level
The Linux Standard Base further extends POSIX.
Use the non-frames indexes, they are much more readable and searchable: The Base Specifications Issue 7
Get a full zipped version of the HTML pages for grepping: Where is the list of the POSIX C API functions?