# How to make top run continuously in Mono?



## fryshke (Aug 5, 2012)

Hello, I'm launching top process in Mono (I know right - herecy) and redirecting it's output to a string (then the parsing will begin). Problem is, that it runs once and quits.

In Linux this code runs flawlessly: http://i.imgur.com/hrB85.jpg

```
using System;
using System.Diagnostics;

namespace top2
{
	class Program
	{
		static int Main(string[] args)
		{
			var proc = new ProcessStartInfo("/usr/bin/top", "-b")
			           	{
			           		UseShellExecute = false,
			           		RedirectStandardError = true,
			           		RedirectStandardInput = true,
			           		RedirectStandardOutput = true
			           	};

			using(Process p = Process.Start(proc))
				{
					try
					{
						while(p.StandardOutput.Peek() > 0)
						{
							string line = p.StandardOutput.ReadLine();
							//string line2 = p.StandardError.ReadLine() ?? "";
							//Console.WriteLine(line);
							//if(line2.Length > 0) Console.WriteLine("error: " + line2);
							if(line.Contains("Cpu(s):"))
							{
								Console.WriteLine(line);
							}
						}
					}
					catch(Exception ex)
					{
						Console.WriteLine(ex.Message);
					}
				}

			return 0;
		}
	}
}
```
For FreeBSD's top I tried -b, -i, -n, even no arguments, top just prints it's output once and process exits.

Why why why?


----------



## wblock@ (Aug 5, 2012)

See the description of the -d option.


----------



## fryshke (Aug 5, 2012)

wblock@ said:
			
		

> See the description of the -d option.



Thanks, -d 9999 helped, after 9999 times, I just start another process.


----------

