[Mono-bugs] [Bug 77196][Wis] New - GetProcessByID sometimes has difficulty getting the process.

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Jan 10 13:22:36 EST 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by carlos at applianz.com.

http://bugzilla.ximian.com/show_bug.cgi?id=77196

--- shadow/77196	2006-01-10 13:22:36.000000000 -0500
+++ shadow/77196.tmp.6609	2006-01-10 13:22:36.000000000 -0500
@@ -0,0 +1,92 @@
+Bug#: 77196
+Product: Mono: Class Libraries
+Version: 1.1
+OS: 
+OS Details: Gentoo 64bit
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: carlos at applianz.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: GetProcessByID sometimes has difficulty getting the process.
+
+I have written an example that involves a two line shell script.
+The shell script launches xcalc then returns the PID of xcalc.
+The C# code launches the shell script, reads the PID and tries to do a
+GetProcessByID. While right now everytime I run it the call has failed, I
+have sometimes seen it retrieve the process just fine, although its always
+less than 50% of the time.
+I am using:
+Mono JIT compiler version 1.1.12.1, (C) 2002-2005 Novell, Inc and
+Contributors. www.mono-project.com
+        TLS:           __thread
+        GC:            Included Boehm (with typed GC)
+        SIGSEGV      : normal
+
+on Gentoo 64bit and I am logged in as root.
+
+Here is the code:
+
+========================================
+using System;
+using System.Diagnostics;
+
+class Test{
+	
+	public static void Main(){
+		while(true){
+			
+		ProcessStartInfo info = new ProcessStartInfo("test.sh");
+		info.UseShellExecute = false;
+		info.RedirectStandardOutput = true;
+			Console.WriteLine("About to launch proc.");
+		String err = Process.Start(info).StandardOutput.ReadLine();
+			Console.WriteLine("Read output: " +err);
+		try{
+			int pid = Int32.Parse(err);
+				Console.WriteLine("Parsed output");
+			Process p = Process.GetProcessById(pid);
+				Console.WriteLine("Got process by ID");
+				if (p != null){
+					Console.WriteLine("Told process to die");
+					p.Kill();
+					Console.WriteLine("Done killing process");
+				}else{
+					throw new Exception("process was null");
+				}
+			}catch(Exception ex){
+			Console.WriteLine(ex);
+				return;
+		}
+		}
+	}
+}
+========================================
+
+Shell script:
+========================================
+#!/bin/sh
+xcalc&
+echo $!
+
+========================================
+output:
+========================================
+serenity test # mono ConsoleApplication2.exe
+About to launch proc.
+Read output: 12807
+Parsed output
+System.ArgumentException: Can't find process with ID 12807
+in <0x000a9> System.Diagnostics.Process:GetProcessById (Int32 processId)
+in <0x00100> Test:Main ()
+serenity test # ps -ef | grep 12807
+root     12807     1  0 11:16 pts/1    00:00:00 xcalc
+root     12809 10934  0 11:16 pts/1    00:00:00 grep 12807
+
+========================================


More information about the mono-bugs mailing list