ps command can't display its own process in terminal

Hello,

I'm having strange 'ps' problem in my terminal. As far as I can remember when using Unix, if you just execute 'ps' with no options in the prompt, you'll get something like the following:
PID TTY TIME CMD
3511 pts/1 00:00:00 bash
3514 pts/1 00:00:00 ps

However, my terminal today stopped doing that. It was doing it before. To be exact, it's not showing the 'ps' command itself, only the 'bash', like the following:
PID TT STAT TIME COMMAND
216 p1 S 0:00.06 -bash

Please help. Thanks and Happy Holidays!

Edison

MacBook Pro 2 GHz Intel Core Duo Mac OS X (10.4.8) 1.5GB 667 MHz DDR2 SDRAM

Posted on Dec 23, 2006 4:48 PM

Reply
9 replies

Dec 24, 2006 10:39 AM in response to tejizo

Hi Edison,
I don't think that b3av1s has thought that suggestion through. System files are owned by root for a reason. To change that would introduce unnecessary vulnerability; all you really need is remove the SetUID bit.

Normally I would admonish you against changing system files just because you don't want to use an option with a command. However, SetUID applications introduce vulnerabilities themselves unless they are very carefully written. I was interested to learn that the authors of most versions of "ps" have put their efforts into writing it so that it no longer requires root privileges to function normally.

Hopefully the FreeBSD version used in OS X is one of those "enlightened" versions. I checked it and it does run fine without being SetUID. I read that it might throw some errors when having difficulty reading its temporary cache but it will still function. Thus, it seems to me that it shouldn't cause any problems to remove the SetUID bit. You can do that with the command:

sudo chmod 755 /bin/ps

Of course this will be changed back next time you repair permissions so you'll have to keep doing it. Naturally we'd be curious to hear whether this causes problems. If it does, you can post back and we'll tell you how to put it back.
--
Gary
~~~~
The chat program is in public domain. This is not the
GNU public license. If it breaks then you get to keep
both pieces.
(Copyright notice for the chat program)

Dec 24, 2006 1:18 PM in response to Gary Kerbaugh

That solved it. Thanks for all your help, guys. Hopefully, I won't run into case where it might throw errors. I'll definitely post back if this change ever causes problem(s).

In another thought, if I get it correct, 'ps' executable in general is SetUID and runs as root, and also, it requires root privileges for 'ps' to function normally. And since mine does not function 'normally,' does that mean I as a user do not have root privileges?

Dec 25, 2006 7:51 AM in response to tejizo

And since mine does not function 'normally,'


On MacOS X, ps command is "SetUID root" and does not list the ps command itself (without option -a); THIS IS NORMAL (of cause you may think it inconvenient). In most of UNIX and UNIX-like OS's, the OS has a mechanism which allows the ps command to access (without root privilege) to various information of processes currently running in the system. For example, Linux and FreeBSD (and some others?) have "procfs" to allow this. But the current (and all of previous) versions of MacOS X do not have any such mechanism, so the ps command must be SetUID root if it want to access these information. Of cause there are some information which can be accessed without root privilege, and the ps command gives no error messages even if it is not SetUID root (it just can't list some of the information).

does that mean I as a user do not have root privileges?


Even if your account is an admin account (and you know the admin password), your account itself is not the root account. You must supply the admin password when you need a root privilege (unless the command itself has the root privilege through the SetUID root mechanism).


If you have removed the "SetUID" bit from /bin/ps, then the ps command lists itself without the -a option; but if you look into the output carefully, especially if you specify options like '-ax' or '-axe', then you will notice that many information are missing in the output of non-setUID-root version of ps. For example, for the processes owned by other users (such as root), the full path name of the command is missing, and the TIME column is always 0:00.00. On my iMac(Core2Duo), the TIME column is 0:00.00 even for my own processes (on my PowerBookG4 the TIME column correctly shows the accumulated cpu time for my own processes).

If you are satisfied with the output of 'ps -a' (of SetUID veriosn of ps) but just don't want to type the '-a' option, then you can define an alias in your shell startup files (.bash_profile, .bashrc, etc.).

PowerMac G4 Mac OS X (10.4.8)

Dec 25, 2006 2:18 PM in response to Jun T.

Thanks, Jun T. This is a very helpful knowledge. You were correct on that. I tried both ps version with and without the "SetUID root." As far as my knowledge goes when using Unix-like OS (Red Hat Linux and Cygwin in Windows), it always shows the "ps" process itself. Therefore, I thought this was "normal." But the difference is actually on the "procfs." I see that Mac OS X does not have the directory /proc, which should explain it.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

ps command can't display its own process in terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.