What is the difference between the processes listed by `ps` and `ps -A`?
Matthew Martinez
What is the difference between the processes listed by ps and ps -A ?
2 Answers
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).
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 unix.
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
psis thus filtered through both. - BSD syntax goes back a long way. Although the modern BSDs use
getoptand 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(historicallya) option turns off all "selector" filtering.- The various other command line options specify selectors:
-Uselects by UID,-tby controlling terminal name,-pselects 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 various other command line options specify selectors:
- The
-x(historicallyx) option turns off the restriction thatpsonly 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
ps1983-04-13. 4.2BSD Manual pages.psOpenBSD Manual pages.ps2009-10-22. NetBSD Manual pages.ps2014-08-07. FreeBSD Manual pages.