POSIX是什么?我读过维基百科上的文章,每次遇到这个词我都会去读。事实上,我从来没有真正理解它是什么。
有没有人可以通过解释“POSIX的需求”来解释给我听?
POSIX是什么?我读过维基百科上的文章,每次遇到这个词我都会去读。事实上,我从来没有真正理解它是什么。
有没有人可以通过解释“POSIX的需求”来解释给我听?
当前回答
关于如何使操作系统与晚期UNIX操作系统兼容的规范(蓝图)(愿上帝保佑他!)这就是为什么macOS和GNU/Linux有非常相似的终端命令行、GUI、库等。因为它们都是根据POSIX蓝图设计的。
POSIX并不告诉工程师和程序员如何编码,而是告诉他们编码什么。
其他回答
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是一种操作系统标准,旨在使编写跨平台软件变得更容易。这在Unix世界中是一件特别重要的事情。
关于如何使操作系统与晚期UNIX操作系统兼容的规范(蓝图)(愿上帝保佑他!)这就是为什么macOS和GNU/Linux有非常相似的终端命令行、GUI、库等。因为它们都是根据POSIX蓝图设计的。
POSIX并不告诉工程师和程序员如何编码,而是告诉他们编码什么。
POSIX是:
POSIX(发音为/ pɒzɪks/)或 便携式操作系统接口 “1是一个家族的名字 的相关标准 IEEE定义应用程序 编程接口(API),沿 使用shell和实用程序接口 为软件兼容的变种 Unix操作系统,尽管 该标准适用于任何领域 操作系统。
基本上,它是一组措施,通过拥有(大部分)公共API和实用程序来减轻开发和使用不同UNIX风格的痛苦。有限的POSIX遵从性也扩展到各种版本的Windows。
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函数的列表在哪里?