15

Commands like ps come with a lot of parameters, especially because they give the use an option to choose between Unix and BSD style flags. I hope you get my point here.

So, when there's such an option available, which should I choose for maximum compatibility across all linux systems? (max. compatibility is one of the priorities for instance)

I know that Unix style is quite obvious, but BSD commands for some reason include more readable information (column titles for example, CPU column etc). Of course, please correct me if I am wrong, but that's what I felt.

its_me
  • 13,959

2 Answers2

17

Pretty much all Linuxes use GNU versions of the original core Unix commands like ps, which, as you've noted, supports both BSD and AT&T style options.

Since your stated goal is only compatibility among Linuxes, that means the answer is, "It doesn't matter."

Embedded and other very small variants of Linux typically use BusyBox instead of the GNU tools, but in the case of ps, it really doesn't affect the answer, since the BusyBox version is so stripped down it can be called neither AT&Tish nor BSDish.

Over time, other Unixy systems have reduced the ps compatibility differences. Mac OS X — which derives indirectly from BSD Unix and in general behaves most similarly to BSD Unix still — accepts both AT&Tish and BSDish ps flags.

Solaris/OpenIndiana behaves this way, too, though this is less surprising because it has a mixed BSD and AT&T history.

FreeBSD, OpenBSD, and NetBSD still hew to the BSD style exclusively.

The older a Unix box is, the more likely it is that it accepts only one style of flags. You can paper over the differences on such a box the same way we do now: install the GNU tools, if they haven't already been installed.

That said, there are still traps. ps output generally shouldn't be parsed in scripts that need to be portable, for example, since Unixy systems vary in what columns are available, the amount of data the OS is willing to make visible to non-root users, etc.

(By the way, note that it's "BSD vs. AT&T", not "BSD vs. Unix". BSD Unix is still UNIX®. BSD Unix shares a direct development history with the original AT&T branch. That sharing goes both ways, too: AT&T and its successors brought BSD innovations back home at several points in its history. This unification over time is partly due to the efforts of The Open Group and its predecessors.)

Warren Young
  • 72,032
  • Even though this is a great explanation (and answer) it doesn't help in the question: Which style should I choose to learn? – Jarl Apr 29 '16 at 06:30
  • @Jarl: Learn POSIX first. That's available everywhere. Then learn whatever weird variants are in use on the systems you use most. Ignore the rest. – Warren Young Apr 29 '16 at 06:31
  • In the case of ps argument styles, which one (BSD or Unix) is POSIX, then? – Jarl Apr 29 '16 at 07:50
  • @Jarl: See the spec. Generally speaking, POSIX leans more SysVish than BSD, since POSIX was economically-driven, and all the major commercial Unixes of the time were System V derivatives. – Warren Young Apr 29 '16 at 07:53
0

In case of doubt, use the SysV syntax. This has been agreed on by a lot of people, and is the de-facto standard. The BSD stuff either dates from the prehistory or is part of some divergent branch (SysV was an effort to end the Unix wars by bringing all the disparate lines under one roof).

vonbrand
  • 18,253
  • De facto standard for Linux, not Solaris, *BSD, OSX, etc. – chiggsy Jan 23 '13 at 15:17
  • Sure it is the standard for Solaris (that was the first SysV to come out, remember). It has been adhered to by IBM's AIX and HP-UX, at least. The BSDs are a holdout from a bygone era. – vonbrand Jan 23 '13 at 15:46
  • 1
    You are correct about Solaris being SysV, my error. – chiggsy Jan 23 '13 at 15:55
  • @chiggsy so, upvote instead of downvote? – its_me Jan 23 '13 at 17:03
  • 3
    Upvoted, although I question the disparaging references to BSD. It's not a bad thing to keep doing things the right way. – chiggsy Jan 25 '13 at 08:14
  • 3
    -1: First, I think you mean de jure standard. To consider SysV style options the de facto standard, you'd have to ignore several existence facts: FreeBSD, OpenBSD, and NetBSD. You can't hand-wave them out of existence with that "prehistory" argument. Second, Solaris was not the first System V. It might have been the first commercial shipment of SVR4, but SVR1 was developed for Vaxen and the PDP-11. – Warren Young Aug 05 '13 at 17:31