2

What is the difference between the processes listed by ps and ps -A ?

0

2 Answers 2

3

without the -A, ps will only print the processes belonging to the current session. Think of it like "absolutely everything". On a related note -a does the same thing, but restricting it to the session-owner (username).

2
  • Why does ps -a list different processes than ps x for GNU ps? I would think both would restrict it to the current user. Jul 26, 2019 at 21:25
  • According to the man page, ps -a does not include session leaders, whereas ps x does. Jul 26, 2019 at 21:42
1

The GNU ps command suffers from a severe case of multiple personality disorder. So it is no wonder that its manual page is confusing. Perhaps a look at the BSD manuals might help. After all, this question is tagged .

The operation of BSD ps is fairly straightforward when one bears two things in mind:

  • Processes are selected for display using two basic filters. Those filters are on by default and command line options turn them off. Plain unadorned ps is thus filtered through both.
  • BSD syntax goes back a long way. Although the modern BSDs use getopt and the convention of options prefixed by a minus sign, the options and behaviour relevant here are much the same as from 30 years ago.

That behaviour is this:

  • The -a (historically a) option turns off all "selector" filtering.
    • The various other command line options specify selectors: -U selects by UID, -t by controlling terminal name, -p selects by process ID, and so forth. All of these are bypassed by -a.
    • If no selectors are explicitly supplied, the default selector is to only display processes running with the same effective UID as the user who invoked ps. This default selector is the historic filter that this option turns off.
  • The -x (historically x) option turns off the restriction that ps only display processes that have a controlling terminal.

Historically, BSD ps did not have an A option. But modern BSDs implement an -A option, also usable as A, for (a degree of) compatibility with the (later) Single UNIX Specification. -A is simply the same as using both -a and -x: it turns both restrictions off, leaving one with all processes, unfiltered.

OpenBSD and NetBSD document the -A option, in NetBSD's case explicitly as -a -x. FreeBSD does not, but a comment in the source code states that it is there as an intentionally undocumented SUSv5 compatibility option.

Further reading

  • ps 1983-04-13. 4.2BSD Manual pages.
  • ps OpenBSD Manual pages.
  • ps 2009-10-22. NetBSD Manual pages.
  • ps 2014-08-07. FreeBSD Manual pages.
1
  • To get the BSD behavior with GNU ps (the default ps in ubuntu), leave off the - in the arguments: ps a, ps x, ps ax, or ps -A (that last one you must leave the - on). Jul 26, 2019 at 21:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .