Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I use Ubuntu Server 10.10 and I would like to see what processes are running. I know that PostgreSQL is running on my machine but I can not see it with the top or ps commands, so I assume that they aren't showing all of the running processes. Is there another command which will show all running processes or is there any other parameters I can use with top or ps for this?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

From the ps man page:

-e Select all processes. Identical to -A.

Thus, ps -e will display all of the processes. The common options for "give me everything" are ps -ely or ps aux, the latter is the BSD-style. Often, people then pipe this output to grep to search for a process, as in xenoterracide's answer. In order to avoid also seeing grep itself in the output, you will often see something like:

 ps -ef | grep [f]oo

where foo is the process name you are looking for.

However, if you are looking for a particular process, I recommend using the pgrep command if it is available. I believe it is available on Ubuntu Server. Using pgrep means you avoid the race condition mentioned above. It also provides some other features that would require increasingly complicated grep trickery to replicate. The syntax is simple:

pgrep foo

where foo is the process for which you are looking. By default, it will simply output the Process ID (PID) of the process, if it finds one. See man pgrep for other output options. I found the following page very helpful:

http://mywiki.wooledge.org/ProcessManagement

share|improve this answer
    
I wonder what percentage of people use ps without knowing the flags. I just throw aux at it always; I have no idea what the individual flags actually control –  Michael Mrozek Oct 21 '10 at 5:07
add comment

have you tried ps aux | grep postgres? it really should show up if postgres is running. If it doesn't... how do you know postgres is running?

(note: it's a common misconception that's it's ps -aux but that's not correct)

share|improve this answer
    
Thanks, ps aux worked better, it showed around 70 processes, while ps showed only two. I know PostgreSQL was running since I saw that it was started on boot up and it was stopped on shutdown. –  Jonas Oct 21 '10 at 0:20
    
@Jonas some init scripts are poorly written. Don't believe them just because they say something was started and stopped. Just some advice –  xenoterracide Oct 21 '10 at 0:41
    
There's also pgrep for this, which has the benefit of never catching your ps aux | grep postgres command itself in the process list and outputting it –  Michael Mrozek Oct 21 '10 at 5:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.