To answer the first part of your question, there are several flags you can add to -f
. They include -l
, -j
, -m
, and -L
. Unfortunately -o <format>
can't be combined with -f
.
Indeed, the best way to get exactly what you want, is to specify exactly what you want, e.g.
ps -e -o pid,ppid,pgid,sid,user,comm
But you can get really close by adding -j
to -f
, to make ps -efj
. This adds both the PGID
and SID
columns.
Demonstrating without the -e
flag to make the output shorter, compare:
$ ps -f
UID PID PPID C STIME TTY TIME CMD
myuser 123 4513 0 18:20 pts/26 00:00:00 zsh
myuser 1282 123 0 18:20 pts/26 00:00:00 ps -f
$ ps -fj
UID PID PPID PGID SID C STIME TTY TIME CMD
myuser 123 4513 123 123 0 18:20 pts/26 00:00:00 zsh
myuser 1402 123 1402 123 0 18:20 pts/26 00:00:00 ps -fj
To answer the second part of your question, the reason ps -ef -o sid
only shows your own processes, is it switches to BSD mode when it decides your flags weren't POSIX compliant. This is indicated by the message
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
So it's equivalent to running ps ef o sid
.
In BSD mode, e
means it will print the process's environment, and f
means "forest". And BSD mode defaults to printing all processes owned by the current user that have any terminal, not just those on the current terminal.
Try changing the -o sid
to -o sid,cmd
to see the effects of e
and f
options.
$ ps ef o sid
SID
12345
567
567
...
$ ps ef o sid,cmd
SID CMD
12345 -zsh USER=... LOGNAME=...
567 zsh PWD=... LANG=...
567 \_ ps ef o sid,cmd LANG=... PWD=...
...
And compare to ps u
to see that the processes shown are the same (I added | wc -l
for brevity).
$ ps ef o cmd | wc -l
20
$ ps u | wc -l
20
It seems to be a misleading error message.
If you look at the procps
source, file common.h
line 290:
extern unsigned format_modifiers; /* -c -j -y -P -L... */
-j
implied format_modifiers
flag to be set, which cause the error if used with user defined output:
if(format_list){
if(format_flags) return "Conflicting format options.";
if(format_modifiers) return "Can't use output modifiers with user-defined output";
if(thread_flags&TF_must_use) return "-L/-T with H/m/-m and -o/-O/o/O is nonsense";
return NULL;
}
A message like Can't use output format modifiers with user-defined output would be better.
FreeBSD ps
doesn't have this issue, -j
option cause ps
to print information about user, pid, ppid, pgid, sid, jobc, state, tt, time, and command
. Adding -o
makes the output aggregated:
$ ps -j -o ppid,sid
USER PID PPID PGID SID JOBC STAT TT TIME COMMAND PPID SID
cuonglm 1196 1195 1196 1196 0 Ss 0 0:00.02 -sh (sh) 1195 1196
cuonglm 1233 1196 1233 1196 1 R+ 0 0:00.00 ps -j -o ppid,si 1196 1196
Output modifiers control how information displayed, while output format controls control what information displayed.
Example the s
options is an output format control, because it added process signal information to ps
output:
$ ps s
UID PID PENDING BLOCKED IGNORED CAUGHT STAT TTY TIME COMMAND
1000 12831 0000000000000000 0000000000000002 0000000000384004 0000000188013003 Ss pts/1 0:00 zsh
1000 13067 0000000000000000 0000000000000000 0000000000000000 0000000073d3fef9 R+ pts/1 0:00 ps s
f
is an output modifier, because it changed how the output displayed:
$ ps f
PID TTY STAT TIME COMMAND
12831 pts/1 Ss 0:00 zsh
13238 pts/1 R+ 0:00 \_ ps f
Here the output was displayed as hierarchy.
Best Answer
You can control the columns that get output by
ps
. Note that the exact commandline does vary between the various flavours of Linux/Unix but I believe the following will do what you want.The man page for
ps(1)
will list all of the options available to you.