cancel
Showing results for 
Search instead for 
Did you mean: 

CMD field in ps output

Jdamian
Respected Contributor

CMD field in ps output

Hi

I need some explanation on the CMD field of ps command output.

As su(1) shows, if su is used and ONLY if the shell of the new user is /usr/bin/sh, the parameter 0 in the new shell is set to "su".

I checked that it is true but ps command shows "su" ONLY if "-f" option is used:

$ ps -p 5398; ps -p 5398 -f
PID TTY TIME COMMAND
5398 pts/1 0:00 sh
UID PID PPID C STIME TTY TIME COMMAND
monuser 5398 5381 0 09:03:34 pts/1 0:00 su

IF XPG4 format is used, "su" is always displayed:

$ UNIX95= ps -p 5398; UNIX95= ps -p 5398 -f
PID TTY TIME CMD
5398 pts/1 00:00 su
UID PID PPID C STIME TTY TIME CMD
monuser 5398 5381 0 09:03:34 pts/1 00:00 su

I didn't find a reason for this behaviour in ps(1) man pages.

Does anyone know why?
2 REPLIES
Duncan Edmonstone
Honored Contributor

Re: CMD field in ps output

Its certainly not that clear from the man page, but all I can surmise (guess at!) is that

- the default beahviour of ps is to show the command if no options are specified and to show arguments if "-f" is specified

- the default beahviour of ps in UNIX95 standard mode is to show the show arguments regardless of whether "-f" is specified.

You can see an interesting comparison by running:

UNIX95= ps -eo pid,comm,args

HTH

Duncan

HTH

Duncan
Dennis Handly
Acclaimed Contributor

Re: CMD field in ps output

This seems to be a bug? in ps(1) and unrelated to su. It has to do with processes that exec and don't fork.

Basically su is no longer there, only sh.