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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
Method 2
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)
Method 3
Answer including Filtering its Output Effectively Along with Automated bash Function
ps -elf | head -n 1; ps -elf | grep -i search_term | grep -v grep | grep -v "ps -elf"
Replace search_term above with any term you wish to search on to find 0 or more processes, for instance term.
Example usage:
ps -elf | head -n 1; ps -elf | grep -i term | grep -v grep | grep -v "ps -elf"
Output:
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 0 S user 14919 1394 0 80 0 - 217553 poll_s 04:14 ? 00:00:12 /usr/lib/gnome-terminal/gnome-terminal-server
Automate
In the root of your home directory, if you do not already have a .bash_aliases file, type the following:
touch .bash_aliases
Next, add a function to do the commands to the end of your .bash_aliases file:
echo 'pself() { ps -elf | head -n 1; ps -elf | grep -i "$1" | grep -v grep | grep -v "ps -elf"; }' >> .bash_aliases
Example usage (open up a new terminal window first):
pself term
Output:
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 0 S user 14919 1394 0 80 0 - 217553 poll_s 04:14 ? 00:00:12 /usr/lib/gnome-terminal/gnome-terminal-server
(Above tested on Ubuntu 18.04).
Article explaining all this in detail: here
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0