ChatGPT解决这个技术问题 Extra ChatGPT

What is the meaning of "POSIX"?

What is POSIX? I have read the Wikipedia article and I read it every time I encounter the term. The fact is that I never really understood what it is.

Can anyone please explain it to me by explaining "the need for POSIX" too?

quick definition reference - whatis.techtarget.com/definition/…
Just since it might help some people: Two examples of Unix-y OSes are BSD and GNU/Linux. > BSD is a 'unix-like' complete OS, with its own kernel and its own userland (no linux kernel nor GNU). GNU/Linux and *BSD family (FreeBSD, OpenBSD and NetBSD) are 'unix-like' OS, they behave like Unix.

A
Amila

POSIX is a family of standards, specified by the IEEE, to clarify and make uniform the application programming interfaces (and ancillary issues, such as commandline shell utilities) provided by Unix-y operating systems.

When you write your programs to rely on POSIX standards, you can be pretty sure to be able to port them easily among a large family of Unix derivatives (including Linux, but not limited to it!); if and when you use some Linux API that's not standardized as part of Posix, you will have a harder time if and when you want to port that program or library to other Unix-y systems (e.g., MacOSX) in the future.


No, the standard is at an API level -- each specified call can be implemented in the kernel, or in the C library in terms of another call, and that's just fine for Posix (and for your programs too;-). MacOSX is Posix compliant, see devworld.apple.com/leopard/overview/osfoundations.html . For Windows, see en.wikipedia.org/wiki/POSIX#POSIX_for_Windows : Posix compliance is currently included in Enterprise and Ultimate editions only (not in the cheaper ones!-), though you can get partways w/Cygwin, en.wikipedia.org/wiki/Cygwin .
Your comment is flawed, as Microsoft's market share on desktops, at least, makes it "what the world follows".
I think what claws meant is that Microsoft doesn't put much effort into being interoperable with other platforms.
@deltaray embrace, extend, and extinguish. MS java (non-standard java.util. java.security, java.io, java.lang, and java.awt), Internet Explorer (almost said 'exploder'), and .NET (yes, I know they have released partial source for .NET, but it's license is restrictive and it's NOT a linux port yet. Mono is incomplete). Also, exFAT patents. You are absolutely correct.
Microsoft's market share on desktops, at least, makes it "what the world follows" - Interesting to note how much things have changed since this comment from 2009 :)
C
Ciro Santilli Путлер Капут 六四事

The most important things POSIX 7 defines

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.

Who conforms to POSIX?

Many systems follow POSIX closely, but few are actually certified by the Open Group which maintains the standard. Notable certified ones include:

OS X (Apple) X stands for both 10 and UNIX. Was the first Apple POSIX system, released circa 2001. See also: Is OSX a POSIX OS?

AIX (IBM)

HP-UX (HP)

Solaris (Oracle)

Most Linux distros are very compliant, but not certified because they don't want to pay the compliance check. Inspur's K-UX and Huawei's EulerOS are two certified examples.

The official list of certified systems be found at: https://www.opengroup.org/openbrand/register/ and also at the wiki page.

Windows

Windows implemented POSIX on some of its professional distributions.

Since it was an optional feature, programmers could not rely on it for most end user applications.

Support was deprecated in Windows 8:

Where does Microsoft Windows' 7 POSIX implementation currently stand?

https://superuser.com/questions/495360/does-windows-8-still-implement-posix

Feature request: https://windows.uservoice.com/forums/265757-windows-feature-suggestions/suggestions/6573649-full-posix-support

In 2016 a new official Linux-like API called "Windows Subsystem for Linux" was announced. It includes Linux system calls, ELF running, parts of the /proc filesystem, Bash, GCC, (TODO likely glibc?), apt-get and more: https://channel9.msdn.com/Events/Build/2016/P488 so I believe that it will allow Windows to run much, if not all, of POSIX. However, it is focused on developers / deployment instead of end users. In particular, there were no plans to allow access to the Windows GUI.

Historical overview of the official Microsoft POSIX compatibility: http://brianreiter.org/2010/08/24/the-sad-history-of-the-microsoft-posix-subsystem/

Cygwin is a well known GPL third-party project for that "provides substantial POSIX API functionality" for Windows, but requires that you "rebuild your application from source if you want it to run on Windows". MSYS2 is a related project that seems to add more functionality on top of 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

Android has its own C library (Bionic) which does not fully support POSIX as of Android O: Is Android POSIX-compatible?

Bonus level

The Linux Standard Base further extends POSIX.

Use the non-frames indexes, they are much more readable and searchable: http://pubs.opengroup.org/onlinepubs/9699919799/nfindex.html

Get a full zipped version of the HTML pages for grepping: Where is the list of the POSIX C API functions?


Fantastic examples, if you had a definition as well like the accepted answer this would be the top answer.
@Marc thanks! I try not to repeat what is said in other answers as people probably have already read those and to avoid duplication ;-) This is a known dilemma: meta.stackoverflow.com/questions/305645/…
Good idea to actually explain what POSIX covers (and what not).
Everywhere in the literature, references to "POSIX compliance" pop up, and the typical definition of POSIX people find is "a set of standards for interoperability among Unix-like operating systems". Although useful, this definition leaves a lot of doubts, specially regarding the features that are expected to interoperate. Sure, you can go and read the whole POSIX spec to delve into the details (and spend a whole lot of time on that). But, this answer provides the much needed summary to get the big picture on the scope of POSIX. Special thanks to Ciro for taking the time to write it!
It might also be good to add some Posix guarantees about integer types. I don't know exactly what is and isn't specified, but I know that at minimum Posix requires the existence of uint8_t, uint16_t, uint32_t and the corresponding signed types. I'm not sure if it guarantees that types like "int" have power-of-two sizes and that a system won't do something nasty like have an "int" with 32 value bits, 1 sign bit, and 31 padding bits [so incrementing a uint32_t could yield UB]; if you have the Standard handy it might be nice to say what is and isn't guaranteed in that regard.
c
cletus

POSIX is:

POSIX (pronounced /ˈpɒzɪks/) or "Portable Operating System Interface [for Unix]"1 is the name of a family of related standards specified by the IEEE to define the application programming interface (API), along with shell and utilities interfaces for software compatible with variants of the Unix operating system, although the standard can apply to any operating system.

Basically it was a set of measures to ease the pain of development and usage of different flavours of UNIX by having a (mostly) common API and utilities. Limited POSIX compliance also extended to various versions of Windows.


1. You mean POSIX says that all *nix OSes (kernels) should have atleast these set of system calls. right? 2. does WINDOWS/MAC follows POSIX? If/Ifnot does WINDOWS (95,98,2000,xp,vista,7) is following some common standard (may be their own proprietary) standard? In other words, POSIX in Microsoft world ==?
Basically it "was" a set of measures to ease the pain of development. WAS??
I questioned the use of the word was, too, but it's debatable. To answer your questions: (1) no, POSIX has absolutely zilch to do with the kernel, it just describes how it should operate; (2) OS X is BSD and is quite POSIX-compliant, but there are gray areas. Windows 2008 is closest to POSIX complaint; there is no equivalent of POSIX in the Microsoft world.
@claws: Don't mean to dirty up the area under cletus's answer...but. I linked POSIX.1-2008 in my answer...right there.
@Jed Smith, there are no gray areas in terms of Mac OS X compliance; Mac OS X is certified compliant with the Single UNIX Specification v3, a standard of which POSIX is a subset.
J
Jim Dennis

Let me give the churlish "unofficial" explanation.

POSIX is a set of standards which attempts to distinguish "UNIX" and UNIX-like systems from those which are incompatible with them. It was created by the U.S. government for procurement purposes. The idea was that the U.S. federal procurements needed a way to legally specify the requirements for various sorts of bids and contracts in a way that could be used to exclude systems to which a given existing code base or programming staff would NOT be portable.

Since POSIX was written post facto ... to describe a loosely similar set of competing systems ... it was NOT written in a way that could be implemented.

So, for example, Microsoft's NT was written with enough POSIX conformance to qualify for some bids ... even though the POSIX subsystem was essentially useless in terms of practical portability and compatibility with UNIX systems.

Various other standards for UNIX have been written over the decades. Things like the SPEC1170 (specified eleven hundred and seventy function calls which had to be implemented compatibly) and various incarnations of the SUS (Single UNIX Specification).

For the most part these "standards" have been inadequate to any practical technical application. They mostly exist for argumentation, legal wrangling and other dysfunctional reasons.


Then how come Linux implement most of POSIX, including many of the extensions?
@ninjalj: Linux was written to implement a practical set of UNIX-like functions. Doing so while conforming to POSIX makes perfect sense. However, my point was that POSIX wasn't created as a specification for implementing new operating systems ... it was created as a way for U.S. government procurement staff to distinguish among those which qualified for certain categories in bids from those which wouldn't. The focus in Linux is to provide the usable features in a way which is reasonable compatible, robust and performant. POSIX is not quite an accident along the way.
Rather ingenious of you to claim that the POSIX was written post facto! That is the hallmark of a good standards development organization (SDO) where consensus is not achieved until at least one conformant implementation exists.
@fpmurphy: Creating an ex post facto specification based on one or two interoperable implementations is the norm for IETF ... networking protocol standards which interact over intentionally loose couplings. It hasn't been a successful process for OS standardization. The API between programs and the system (kernel or microkernel and its subsystem servers) is far more tightly coupled than clients and servers or peers over networks. (I'm not saying it's impossible; merely pointing out that there are differences and the history hasn't shown the latter to be promising).
The efforts by IEEE to specify POSIX back in 1985 were spurred by the U.S. Government. Do some research, read a history book or something.
H
Hank Gay

POSIX is a standard for operating systems that was supposed to make it easier to write cross-platform software. It's an especially big deal in the world of Unix.


It isn't just "supposed to" make it easier to write cross-platform code, it does make it easier to write cross-platform code. The only exception is Windows, because Microsoft thinks it is somehow better than everyone else and does not need to comply. However, I predict this will work against them, especially as Mac and Linux gain more market share. If they really are for the "developers, developers, developers", they will realize that developers want UNIX compliance.
Based on what I've heard from people who work with it much more closely than I ever did, it may have made things easier, but it certainly wasn't sufficient for the write-once, run-on-any-POSIX impression most people get when they hear it's a "standard" for operating systems.
They don't think they're "better than everyone else"; they know they're bigger than everyone else. That's also why they'll change their tune as they lose market share. It's not unique to them, e.g., Netscape started caring a lot more about web standards when they were no longer the most popular.
@Ken and that's why we shouldn't let Google's chromium get too comfy.
@MichaelAaronSafyan unfortunately, *inx users are still adamantly divided on how to maintain and develop software (see Linux display managers, Linux gaming, Linux patching methods, Linux package managers) where Microsoft seems to be standardizing across platforms
J
Jed Smith

POSIX is a set of standards put forth by IEEE and The Open Group that describes how an ideal Unix would operate. Programmers, users, and administrators can all become familiar with the POSIX document, and expect a POSIX-complaint Unix to provide all of the standard facilities mentioned.

Since every Unix does things a little differently -- Solaris, Mac OS X, IRIX, BSD, and Linux all have their quirks -- POSIX is especially useful to those in the industry as it defines a standard environment to operate in. For example, most of the functions in the C library are based in POSIX; a programmer can, therefore, use one in his application and expect it to behave the same across most Unices.

However, the divergent areas of Unix are typically the focus, rather than the standard ones.

The great thing about POSIX is that you're welcome to read it yourself:

The Open Group Base Specifications Issue 7

Issue 7 is known as POSIX.1-2008, and there are new things in there -- however, Google-fu for POSIX.1 and such will allow you to see the entire history behind what Unix is.


I think you are using the term "UNIX" incorrectly. UNIX now refers to the Single UNIX Specification, and any UNIX operating system is an operating system that conforms to the Single UNIX Specification. Perhaps you mean UNIX-like?
@Michael: Given your comments in other answers, you're obviously a very polarized person with opinions that aren't exactly constructive. This specific comment is very pedantic, and my meaning was conveyed regardless of the choice of a label that you might disagree with. Also, Windows is POSIX compliant in the higher-end versions. Take a breath and step back, please.
@Jed Smith, strong opinions aside, the implication of the post is that some operating systems that are certified UNIX compliant are not... so, I think it is fair to say that that is misleading. Also, with regard to Windows, so long as there are editions that are not compliant, developers cannot rely on POSIX when targeting the Windows platform, thereby negating the entire purpose of having POSIX.
Unix is an operating system. UNIX is a brand held by The Open Group. Systems that are certified to either the UNIX95, UNIX98 or UNIX03 branding profiles, of which conformance to a particular version of the Single UNIX Specification forms the majority of the branding requirements, can use use the term UNIX.
K
Koray Tugay

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.

From the book: A Practical Guide To Linux


p
peterh

Posix is more as an OS, it is an "OS standard". You can imagine it as an imaginary OS, which actually doesn't exist, but it has a documentation. These papers are the "posix standard", defined by the IEEE, which is the big standard organization of the USA. The OSes implementing this specification are "Posix-compliant".

Government regulations prefer Posix-compliant solutions in their investments, thus being Posix-compliant has a significant financial advantage, particularly for the big IT companies of the USA.

The reward for an OS being fully posix compliant, that it is a guarantee that it will compile and run all Posix-compliant applications seamlessly.

Linux is the most well-known one. OSX, Solaris, NetBSD and Windows NT play here as well. Free- and OpenBSD are only "nearly" Posix-compliant. The posix-compliance of the WinNT is only a pseudo-solution to avoid this government regulation above.


K
Koray Tugay

This standard provides a common basis for Unix-like operating systems. It specifies how the shell should work, what to expect from commands like ls and grep, and a number of C libraries that C authors can expect to have available.

For example, the pipes that command-line users use to string together commands are specified in detail here, which means C’s popen (pipe open) function is POSIX-standard, not ISO C-standard.


F
Farruh Habibullaev

POSIX stands for Portable Operating System Interface, and is an IEEE standard designed to facilitate application portability. POSIX is an attempt by a consortium of vendors to create a single standard version of UNIX.


C
Community

POSIX stands for Portable Operating System Interface.

POSIX is a set of standards codified by the IEEE and issued by ANSI and ISO. The goal of POSIX is to ease the task of cross-platform software development by establishing a set of guidelines for operating system vendors to follow. Ideally, a developer should have to write a program only once to run on all POSIX-compliant systems. Most modern commercial Unix implementations and many free ones are POSIX compliant. There are actually several different POSIX releases, but the most important are POSIX.1 and POSIX.2, which define system calls and command-line interface, respectively.

The POSIX specifications describe an operating system that is similar to, but not necessarily the same as, Unix. Though POSIX is heavily based on the BSD and System V releases, non-Unix systems such as Microsoft's Windows NT and IBM's OpenEdition MVS are POSIX compliant.

source


s
sras

POSIX defines set of standards for an operating system or a program. The goal is to write new software that is compatible with UNIX-like systems.

For example a program runs on Linux is also can be compile and run on other UNIX-like systems like Solaris, HP-UX, and AIX etc..

The most popular examples are GNU Bash which is 100% POSIX compliance and gawk utility.


t
t0mm13b

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.

Thanks to Jed Smith & Tinkertim for pointing out my error - my bad!!! :(


Filesystem standards are handled outside of POSIX.
You are confusing POSIX with things like the LSB (Linux Standard Base). Two (mostly) POSIX compliant operating systems would be FBSD and Linux, yet both have rather different file system organization and default library installations.
M
MCH

A specification (blueprint) about how to make an OS compatible with late UNIX OS (may God bless him!). This is why macOS and GNU/Linux have very similar terminal command lines, GUI's, libraries, etc. Because they both were designed according to POSIX blueprint.

POSIX does not tell engineers and programmers how to code but what to code.


p
prosti

Some facts about POSIX that are not so bright.

POSIX is also the system call interface or API, and it is nearly 30 years old.

It was designed for serialized data access to local storage, using single computers with single CPUs.

Security was not a major concern in POSIX by design, leading to numerous race condition attacks over the years and forcing programmers to work around these limitations.

Serious bugs are still being discovered, bugs that could have been averted with a more secure POSIX API design.

POSIX expects users to issue one synchronous call at a time and wait for its results before issuing the next. Today's programmers expect to issue many asynchronous requests at a time to improve overall throughput.

This synchronous API is particularly bad for accessing remote and cloud objects, where high latency matters.


Synchronous kernel API does not need to mean single-threaded processes and serialized IO. It has also nothing to do to SMP machines. These are completely unrelated. (While I agree that the sync kernel API is suboptimal, but not so heavily as in your post seems.)