什么是POSIX

POSIX表示可移植操作系统接口(Portable Operating System Interface of UNIX,缩写为 POSIX ),POSIX标准定义了操作系统应该为应用程序提供的接口标准,是IEEE为要在各种UNIX操作系统上运行的软件而定义的一系列API标准的总称,其正式称呼为IEEE 1003,而国际标准名称为ISO/IEC 9945。


POSIX更像是一个操作系统,它是一个"操作系统标准"。你可以想象它是一个虚构的操作系统,实际上并不存在,但是它有一个文档。这些论文是由美国大标准组织IEEE定义的"POSIX标准"。实现此规范的操作系统是"符合POSIX的"。

政府法规更倾向于在投资中采用符合POSIX的解决方案,因此符合POSIX具有显著的财务优势,特别是对于美国的大型IT公司。

Linux是最有名的。OSX、Solaris、NetBSD和Windows NT也在这里播放。免费和OpenBSD只"几乎"符合POSIX。Winnt的POSIX遵从性只是避免上述政府法规的一个伪解决方案。

本标准为类Unix操作系统提供了通用基础。它指定了shell的工作方式、ls和grep等命令的期望值,以及C作者希望提供的一些C库。
例如,命令行用户用来将命令串在一起的管道在这里被详细地指定,这意味着C的popen(管道打开)函数是POSIX标准,而不是ISO C标准。

操作系统家族

  • Unix家族成员包括Unix(惠普、IBM)、BSD(gnu、sun、macos)和UnixLike(minix、Linux)
  • Linux家族包括Redhat(redhat、fodara[费多拉]、centos)和Debian(ubuntu、Kali)

UNIX

各个操作系统体系,五花八门,差异性也较大,其中很典型的一个案例就是ps命令,使用man ps命令查命令文档:

txt
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 DESCRIPTION
     ps displays information about a selection of the active processes.  If
     you want a repetitive update of the selection and the displayed
     information, use top(1) instead.
     ps displays information about a selection of the active processes.  If
     you want a repetitive update of the selection and the displayed
     information, use top(1) instead.

     This version of ps accepts several kinds of options:

     1   UNIX options, which may be grouped and must be preceded by a dash.
     2   BSD options, which may be grouped and must not be used with a dash.
     3   GNU long options, which are preceded by two dashes.
     This version of ps accepts several kinds of options:

     1   UNIX options, which may be grouped and must be preceded by a dash.
     2   BSD options, which may be grouped and must not be used with a dash.
     3   GNU long options, which are preceded by two dashes.

     Options of different types may be freely mixed, but conflicts can
     appear.  There are some synonymous options, which are functionally
     identical, due to the many standards and ps implementations that this
     ps is compatible with.

     Note that "ps -aux" is distinct from "ps aux".  The POSIX and UNIX
     standards require that "ps -aux" print all processes owned by a user
     named "x", as well as printing all processes that would be selected by
     the -a option.  If the user named "x" does not exist, this ps may
     interpret the command as "ps aux" instead and print a warning.  This
     behavior is intended to aid in transitioning old scripts and habits.
     It is fragile, subject to change, and thus should not be relied upon.

     By default, ps selects all processes with the same effective user ID
     (euid=EUID) as the current user and associated with the same terminal
     as the invoker.  It displays the process ID (pid=PID), the terminal
     associated with the process (tname=TTY), the cumulated CPU time in
     [DD-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD).
     Output is unsorted by default.

     The use of BSD-style options will add process state (stat=STAT) to the
     default display and show the command args (args=COMMAND) instead of the
     executable name.  You can override this with the PS_FORMAT environment
     variable. The use of BSD-style options will also change the process
     selection to include processes on other terminals (TTYs) that are owned
     by you; alternately, this may be described as setting the selection to
     be the set of all processes filtered to exclude processes owned by
     other users or not on a terminal.  These effects are not considered
     when options are described as being "identical" below, so -M will be
     considered identical to Z and so on.

     Except as described below, process selection options are additive.  The
     default selection is discarded, and then the selected processes are
     added to the set of processes to be displayed.  A process will thus be
     shown if it meets any of the given selection criteria.

如:aux是BSD风格,-ef是System V风格。可以看出,如果不对操作系统加以规范,系统会千差万别,就很难实现操作系统之间的兼容。

参考链接

https://www.codenong.com/1780599/
https://en.wikipedia.org/wiki/POSIX


「真诚赞赏,手留余香」

Hollson码夫庄园

嗯,我的梦想是被读者的稿费包养~

使用微信扫描二维码完成支付

Hollson

评论