Bugzilla – Bug 319992
GetProcessByID sometimes has difficulty getting the process.
Last modified: 2007-11-05 17:00:22 UTC
---- Reported by carlos@applianz.com 2006-01-10 13:22:36 MST ---- 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 ======================================== ---- Additional Comments From dick@ximian.com 2006-01-10 15:20:18 MST ---- See https://bugzilla.novell.com/show_bug.cgi?id=MONO51445 I'd mark this as duplicate but for the "sometimes works" part - it shouldn't ever with the current code. ---- Additional Comments From carlos@applianz.com 2006-01-10 15:28:13 MST ---- I gave that a little more thought. It was sometimes working on 1.1.9.2 but then I upgraded straight to 1.1.12 which is when it started happening so much that I needed to write the little sample posted above. Is there anything anyone can do to help solve this problem? we were so close to releasing our Linux code until this problem ocurred! Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>Gentoo 64bit</cf_op_sys_details> Unknown operating system unknown. Setting to default OS "Other".
Dick, can we confirm this bug and close it?
This is definitely a duplicate, as mentioned above *** This bug has been marked as a duplicate of bug 313231 ***