Portable Operating System Interface (POSIX)
- is an IEEE standard designed to facilitate application portability
- is an attempt by a consortium of vendors to create a single standard version of UNIX
- If they are successful, it will make it easier to port applications between hardware platforms
POSIX - Standards
C API
Click here to expand...
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, semaphoressem_*, 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.
forkrequires 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
Click here to expand...
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
Click here to expand...
e.g.
a=b; echo “$a”Major Linux desktop implementation: GNU Bash.
Environment Variables
Click here to expand...
e.g.
HOME,PATH.
PATHsearch semantics are specified, including how slashes preventPATHsearch.
Program Exit Status
Click here to expand...
ANSI C says
0orEXIT_SUCCESSfor success,EXIT_FAILUREfor failure, and leaves the rest implementation defined.POSIX adds:
126: command found but not executable127: command not found>128: terminated by a signalBut POSIX does not seem to specify the
128 + SIGNAL_IDrule used by Bash: https://unix.stackexchange.com/questions/99112/default-exit-code-when-process-is-terminated
Regular Expression
Click here to expand...
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.
grepaccepts 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
grepcan use as backend.
Directory Structure
Click here to expand...
e.g.
/dev/null,/tmpThe Linux FHS greatly extends POSIX
Filenames
Click here to expand...
/is the path separatorNULcannot 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
Click here to expand...
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 — -lto list a directory named-lSee also: Are there standards for Linux command line switches and arguments?
”POSIX ACLs” (Access Control Lists)
Click here to expand...
e.g. as used as backend for
setfaclThis was withdrawn but it was implemented in several OSes, including in Linux with
setxattr