Everytime I run ps, it returns the usual PID and CMD, but

In every book I've read, it never returns like this:

PID CMD
2748 -bash
8114 awk
7900 -bash

Which is what my ps returns. Is that normal for the - to be in front of the bash? I've only ever seen 2290 bash, never without the - in front of it. Trivial question, but I assume it isn't normal. Thank you, and sorry for the stupid question.

Upvotes: 1

Views: 231

Answers (1)

Tom
Tom

Reputation: 2254

This means a login shell. Take a look at man bash:

A login shell is one whose first character of argument zero is a -, or one started with the --login option.

If you run cat /proc/2748/cmdline you will see the hyphen there. This is where ps is getting it from. -f will look at /proc/[pid]/cmdline, whereas by default it will look at /proc/[pid]/comm.

tom@riki:~$ ps
  PID TTY          TIME CMD
 9230 pts/2    00:00:00 bash
 9429 pts/2    00:00:00 ps

tom@riki:~$ ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
tom       9230  9229  0 17:39 pts/2    00:00:00 -bash
tom       9427  9230  0 18:22 pts/2    00:00:00 ps -f

tom@riki:~$ cat /proc/9230/comm
bash

tom@riki:~$ cat /proc/9230/cmdline
-bash

Upvotes: 1

Related Questions