How to display a changing output like top

What if you wanted real time memory usage?, In other words, if a program which was using up memory did not run when you ran your memory usage script, you would not know about it right? So how do you make a script print an output like the top command?

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis