What is the difference between ps and top command?

What is the difference between ps and top command ? I see that both can display information about running processes . Which one should be used when ?

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

top is mostly used interactively (try reading man page or pressing “h” while top is running) and ps is designed for non-interactive use (scripts, extracting some information with shell pipelines etc.)

Method 2

top allows you display of process statistics continuously until stopped vs. ps which gives you a single snapshot.

Method 3

Another point:

ps – (Process Status) – It reports a snapshot of current processes.
top (Table Of Processes) – is a task manager program displays information about CPU and memory utilization.

Method 4

top enables you to see your processes ordered by the amount of processor power they use.
ps enables you to see all your processes, or just the processes used by certain users, for example root or yourself.

top should be used to see which processes are most active, ps could be used to see which processes you (or any other user) are running currently.

for more information about how to use top and ps, run man top or man ps in your terminal 😉

Method 5

For CPU usage, ps displays average CPU usage over the lifetime of the process as it is instantaneous and would always be 0% or 100%. top gives a more instantaneous look at it from averaging over recent polls.

More information here:
Top and ps not showing the same cpu result


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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x