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).
-
Why does
ps -a
list different processes thanps 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, whereasps x
does. Jul 26, 2019 at 21:42
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
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
(historicallya
) 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 various other command line options specify selectors:
- The
-x
(historicallyx
) option turns off the restriction thatps
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
-
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
, orps -A
(that last one you must leave the - on). Jul 26, 2019 at 21:22