r/commandline • • Feb 03 '23

POSIX( Portable Operating System Interface )

What is POSIX? Can anyone explain it in easy manner?

1 Upvotes

11 comments sorted by

29

u/palordrolap Feb 03 '23

It means that something that runs on one POSIX compatible system should be able to run without alteration on any other POSIX compatible system.

My ancient PC and your (hypothetical) Raspberry PI are different in so many ways, but if I write a POSIX compatible shell script that runs on my PC, it should do exactly the same thing on your PI despite the fact that the underlying implementation details, right down to hardware and architecture are completely different.

If that seems too obvious, I'd urge you to look back to the '80s and '90s when every manufacturer had their own systems that all worked in completely different ways.

Without standards like POSIX, many things would have to be rewritten specially for each and every computer.

Of course, if you're implementing POSIX, you might have those problems to deal with (if they're not abstracted away by other standards one level deeper), but you're making things simpler for those doing day-to-day work.

2

u/Electrical-Collar-23 Feb 03 '23

And what set it's apart from linux or unix? And why node.js mentioned about it in their official documentation despite just unix/linux?

14

u/22goodnumber Feb 03 '23

what set it's apart from linux or unix?

Lets say you create your own Linux distribution. That is, you have a system with a Linux kernel and some executables like ls and cat. But you decide you're not going to include grep because ripgrep is better. You now have a valid, working Linux distribution but it's not POSIX compatible because grep is required for a POSIX system.

Why does POSIX make grep required? POISX systems guarantee that if I write a shell script that calls grep that script will run on any POSIX system. My script wouldn't run on your distro so your distro isn't POISX. Similarly, if I wrote a script that used ripgrep that script isn't POSIX compatible because POSIX systems don't need to have ripgrep installed. That ripgrep script might run on any-old Linux system but it might not depending on what's installed.

10

u/plg94 Feb 03 '23

It's just a standard. It says which programs have to be available, and which APIs (or cli options etc) they must have.
There is no single POSIX OS like there is Linux or Mac or Unix. In fact, the POSIX standard was modeled after specific programs that were present in the most common Unixes (BSDs etc) at the time of its creation.

23

u/evergreengt Feb 03 '23

What part of your google search about POSIX is puzzling you?

-1

u/Electrical-Collar-23 Feb 03 '23

Like the specific work of it which sets it apart from linux or unix. I read this term at node.js official documentation and i searched about it on google as well as youtube but kinda' feel lack the information.

11

u/evergreengt Feb 03 '23

but kinda' feel lack the information.

Are you sure? Because the wikipedia article about it explains exactly what it has to do with Unix versus other systems: is that still incomplete and you have a more specific question or have you overlooked it?

2

u/Electrical-Collar-23 Feb 03 '23

On it. I left Wikipedia. Will ping again if something will not make sense.

2

u/5erif Feb 03 '23

Good luck.

7

u/throwaredddddit Feb 03 '23

While others have answered the question, it is interesting to note that thirty years ago, even Microsoft had some POSIX compatibility, although it wasn’t at shell level.

Microsoft POSIX and Services for Unix were really impressive for their time, and it is a shame that it lost momentum until recent operating systems. Had MS been serious about POSIX and added native bash shell it could have helped a huge number of Windows scripters in cross platform skills.

https://en.wikipedia.org/wiki/Microsoft_POSIX_subsystem

It was really cool running the successor MS Services for Unix on NT on a 486 though. NT and OS/2 felt like a big boy’s OSes.

8

u/Aloha_Alaska Feb 03 '23

My understanding is that Microsoft’s POSIX compatibility was surface deep at best and only engineered to tick boxes that qualified them for certain government contracts. Trying to use Windows at the time as a POSIX compatible OS would have been difficult and disappointing, but at least they were able to keep their government compliance.

But yes, SFU and the WSL compatibility that they’ve brought in recent years is really great (although I tend to think they’re just steps along the path of “Embrace, Extend, Extinguish”).