a3fa [Solved] How to make top run continuously in Mono? - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Development > Userland Programming & Scripting

Userland Programming & Scripting C, Shell, Perl, Sed & Awk

Reply
 
Thread Tools Display Modes
  #1  
Old August 5th, 2012, 00:34
fryshke fryshke is offline
Junior Member
 
Join Date: Sep 2011
Posts: 19
Thanks: 5
Thanked 0 Times in 0 Posts
Default How to make top run continuously in Mono?

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
Code:
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?

Last edited by fryshke; August 5th, 2012 at 19:14.
Reply With Quote
  #2  
Old August 5th, 2012, 01:59
wblock@'s Avatar
wblock@ wblock@ is offline
Moderator
 
Join Date: Sep 2009
Location: Milky Way galaxy
Posts: 7,701
Thanks: 429
Thanked 1,757 Times in 1,456 Posts
Default

See the description of the -d option.
Reply With Quote
The Following User Says Thank You to wblock@ For This Useful Post:
fryshke (August 5th, 2012)
  #3  
Old August 5th, 2012, 13:31
fryshke fryshke is offline
Junior Member
 
Join Date: Sep 2011
Posts: 19
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by wblock@ View Post
See the description of the -d option.
Thanks, -d 9999 helped, after 9999 times, I just start another process.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mono-sgen ArsenShnurkov Porting New Software 6 January 22nd, 2013 22:40
deleted content of rc.conf, now machine continuously reboots Vitamin General 11 February 1st, 2012 09:08
[Solved] Mono Winforms timmmay Userland Programming & Scripting 2 September 17th, 2011 23:49
[Solved] Mono VGA driver jbt302 X.Org 2 October 19th, 2009 18:35
[Solved] mono tim-m89 Installation and Maintenance of FreeBSD Ports or Packages 8 June 6th, 2009 08:12


All times are GMT +1. The time now is 20:12.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0