POSIX是什么?我读过维基百科上的文章,每次遇到这个词我都会去读。事实上,我从来没有真正理解它是什么。
有没有人可以通过解释“POSIX的需求”来解释给我听?
POSIX是什么?我读过维基百科上的文章,每次遇到这个词我都会去读。事实上,我从来没有真正理解它是什么。
有没有人可以通过解释“POSIX的需求”来解释给我听?
当前回答
让我来给出粗鲁的“非官方”解释。
POSIX是一组标准,试图将“UNIX”和类UNIX系统与与它们不兼容的系统区分开来。它是由美国政府为采购目的而创建的。当时的想法是,美国联邦采购部需要一种方法来合法地规定各种投标和合同的要求,这种方法可以用来排除现有代码库或编程人员无法移植到的系统。
因为POSIX是事后写的……为了描述一组大致相似的竞争系统……它不是以一种可以实现的方式编写的。
因此,例如,微软的NT是用足够的POSIX一致性编写的,有资格参加一些投标…尽管POSIX子系统在实际可移植性和与UNIX系统的兼容性方面基本上是无用的。
在过去的几十年里,已经编写了各种UNIX标准。比如SPEC1170(指定了1170个函数调用,必须兼容地实现)和SUS(单一UNIX规范)的各种版本。
在大多数情况下,这些“标准”对任何实际技术应用都是不够的。它们大多是为了争论、法律纠纷和其他不正常的原因而存在的。
其他回答
让我来给出粗鲁的“非官方”解释。
POSIX是一组标准,试图将“UNIX”和类UNIX系统与与它们不兼容的系统区分开来。它是由美国政府为采购目的而创建的。当时的想法是,美国联邦采购部需要一种方法来合法地规定各种投标和合同的要求,这种方法可以用来排除现有代码库或编程人员无法移植到的系统。
因为POSIX是事后写的……为了描述一组大致相似的竞争系统……它不是以一种可以实现的方式编写的。
因此,例如,微软的NT是用足够的POSIX一致性编写的,有资格参加一些投标…尽管POSIX子系统在实际可移植性和与UNIX系统的兼容性方面基本上是无用的。
在过去的几十年里,已经编写了各种UNIX标准。比如SPEC1170(指定了1170个函数调用,必须兼容地实现)和SUS(单一UNIX规范)的各种版本。
在大多数情况下,这些“标准”对任何实际技术应用都是不够的。它们大多是为了争论、法律纠纷和其他不正常的原因而存在的。
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函数的列表在哪里?
POSIX为操作系统或程序定义了一组标准。 目标是编写与类unix系统兼容的新软件。
例如,在Linux上运行的程序也可以在其他类unix系统上编译和运行,如Solaris、HP-UX和AIX等。
最流行的例子是GNU Bash,它100%符合POSIX和gawk实用程序。
In 1985, individuals from companies throughout the computer industry joined together to develop the POSIX (Portable Operating System Interface for Computer Environments) standard, which is based largely on the UNIX System V Interface Definition (SVID) and other earlier standardization efforts. These efforts were spurred by the U.S. government, which needed a standard computing environment to minimize its training and procurement costs. Released in 1988, POSIX is a group of IEEE standards that define the API, shell, and utility interfaces for an operating system. Although aimed at UNIX-like systems, the standards can apply to any compatible operating system. Now that these stan- dards have gained acceptance, software developers are able to develop applications that run on all conforming versions of UNIX, Linux, and other operating systems.
摘自《Linux实用指南》
Posix governs interoperability, portability, and in other areas such as the usage and mechanism of fork, permissions and filesystem standards such as /etc, /var, /usr and so on . Hence, when developers write a program under a Posix compliant system such as for example Linux, it is generally, not always, guaranteed to run on another posix compliant system such as IBM's AIX system or other commercial variants of Unix. Posix is a good thing to have as such it eases the software development for maximum portability which it strives for. Hope this answer makes sense.
感谢Jed Smith和Tinkertim指出我的错误——我的错!!:(