POSIX是什么?我读过维基百科上的文章,每次遇到这个词我都会去读。事实上,我从来没有真正理解它是什么。
有没有人可以通过解释“POSIX的需求”来解释给我听?
POSIX是什么?我读过维基百科上的文章,每次遇到这个词我都会去读。事实上,我从来没有真正理解它是什么。
有没有人可以通过解释“POSIX的需求”来解释给我听?
当前回答
让我来给出粗鲁的“非官方”解释。
POSIX是一组标准,试图将“UNIX”和类UNIX系统与与它们不兼容的系统区分开来。它是由美国政府为采购目的而创建的。当时的想法是,美国联邦采购部需要一种方法来合法地规定各种投标和合同的要求,这种方法可以用来排除现有代码库或编程人员无法移植到的系统。
因为POSIX是事后写的……为了描述一组大致相似的竞争系统……它不是以一种可以实现的方式编写的。
因此,例如,微软的NT是用足够的POSIX一致性编写的,有资格参加一些投标…尽管POSIX子系统在实际可移植性和与UNIX系统的兼容性方面基本上是无用的。
在过去的几十年里,已经编写了各种UNIX标准。比如SPEC1170(指定了1170个函数调用,必须兼容地实现)和SUS(单一UNIX规范)的各种版本。
在大多数情况下,这些“标准”对任何实际技术应用都是不够的。它们大多是为了争论、法律纠纷和其他不正常的原因而存在的。
其他回答
关于POSIX的一些事实并不那么明朗。
POSIX也是系统调用接口或API,它有将近30年的历史。
它被设计用于对本地存储的串行数据访问,使用具有单个cpu的单台计算机。
在POSIX的设计中,安全性并不是一个主要的问题,这导致了多年来大量的竞争条件攻击,迫使程序员绕过这些限制。
严重的错误仍在被发现,这些错误本可以通过更安全的POSIX API设计来避免。
POSIX期望用户一次发出一个同步调用,并在发出下一个调用之前等待它的结果。今天的程序员希望一次发出许多异步请求,以提高总体吞吐量。
这种同步API对于访问远程和云对象尤其不利,因为在这些地方,高延迟很重要。
关于如何使操作系统与晚期UNIX操作系统兼容的规范(蓝图)(愿上帝保佑他!)这就是为什么macOS和GNU/Linux有非常相似的终端命令行、GUI、库等。因为它们都是根据POSIX蓝图设计的。
POSIX并不告诉工程师和程序员如何编码,而是告诉他们编码什么。
Posix更像是一个操作系统,它是一个“操作系统标准”。你可以把它想象成一个虚构的操作系统,它实际上并不存在,但它有一个文档。这些论文是由IEEE定义的“posix标准”,IEEE是美国的大型标准组织。 实现该规范的操作系统是“posix兼容的”。
政府法规在投资中更倾向于posix兼容的解决方案,因此posix兼容具有显著的财务优势,特别是对于美国的大型IT公司。
一个完全兼容posix的操作系统的回报是,它可以保证无缝地编译和运行所有兼容posix的应用程序。
Linux是最著名的。OSX、Solaris、NetBSD和Windows NT也可以在这里使用。Free和OpenBSD只是“几乎”兼容posix。WinNT的posix-compliance只是避免上述政府监管的伪解决方案。
POSIX为操作系统或程序定义了一组标准。 目标是编写与类unix系统兼容的新软件。
例如,在Linux上运行的程序也可以在其他类unix系统上编译和运行,如Solaris、HP-UX和AIX等。
最流行的例子是GNU Bash,它100%符合POSIX和gawk实用程序。
POSIX 7定义的最重要的东西
C API 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. 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 E.g., a=b; echo "$a" Major Linux desktop implementation: GNU Bash. Environment variables E.g.: HOME, PATH. PATH search semantics are specified, including how slashes prevent PATH search. Program exit status ANSI C says 0 or EXIT_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: https://unix.stackexchange.com/questions/99112/default-exit-code-when-process-is-terminated See also: What is the meaning of $? (dollar question mark) in shell scripts? Regular expression 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. Directory structure E.g.: /dev/null, /tmp The Linux FHS greatly extends POSIX. Filenames / is the path separator NUL cannot be used . is cwd, .. 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.
谁符合POSIX?
许多系统密切遵循POSIX,但很少有系统实际上得到维护该标准的开放组织的认证。值得注意的认证包括:
OS X (Apple) X同时代表10和UNIX。是第一个苹果POSIX系统,发布于2001年左右。请参见:OSX是POSIX操作系统吗? AIX (IBM) HP - ux (HP) Solaris (Oracle)
大多数Linux发行版都是非常合规的,但没有认证,因为他们不想支付合规检查。浪潮的K-UX和华为的EulerOS就是两个经过认证的例子。
认证系统的官方列表可以在https://www.opengroup.org/openbrand/register/和wiki页面上找到。
窗户
Windows在它的一些专业发行版上实现了POSIX。
因为它是一个可选的特性,所以程序员不能在大多数终端用户应用程序中依赖它。
Windows 8已弃用支持:
微软Windows 7 POSIX实现目前处于什么位置? https://superuser.com/questions/495360/does-windows-8-still-implement-posix 专题请求:https://windows.uservoice.com/forums/265757-windows-feature-suggestions/suggestions/6573649-full-posix-support
2016年,一个名为“Windows子系统for Linux”的新的官方类Linux API发布。它包括Linux系统调用,ELF运行,部分/proc文件系统,Bash, GCC, (TODO可能是glibc?), apt-get和更多:https://channel9.msdn.com/Events/Build/2016/P488所以我相信它将允许Windows运行大部分POSIX,如果不是全部的话。但是,它关注的是开发人员/部署,而不是最终用户。特别是,没有允许访问Windows GUI的计划。
官方Microsoft POSIX兼容性的历史概述:http://brianreiter.org/2010/08/24/the-sad-history-of-the-microsoft-posix-subsystem/
Cygwin是一个著名的GPL第三方项目,因为它为Windows“提供了大量的POSIX API功能”,但如果你想让应用程序在Windows上运行,就需要你“从源代码重新构建应用程序”。MSYS2是一个相关的项目,它似乎在Cygwin的基础上添加了更多的功能。
If the only thing from POSIX that you need are the command line utilities, also consider: https://github.com/shelljs/shelljs 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有自己的C库(Bionic),不完全支持POSIX作为Android O: Android POSIX兼容吗?
奖金水平
Linux标准库进一步扩展了POSIX。
使用非框架索引,它们更易于阅读和搜索:http://pubs.opengroup.org/onlinepubs/9699919799/nfindex.html
获取grepping的HTML页面的完整压缩版本:POSIX C API函数的列表在哪里?