コード例 #1
0
 /// <summary>
 /// Attempt to use evil reflection tricks to determine the
 /// pid of a launched process.
 /// </summary>
 /// <remarks>
 /// Attempt to use evil reflection tricks to determine the
 /// pid of a launched process. This is helpful to ops
 /// if debugging a fencing process that might have gone
 /// wrong. If running on a system or JVM where this doesn't
 /// work, it will simply return null.
 /// </remarks>
 private static string TryGetPid(SystemProcess p)
 {
     try
     {
         Type clazz = p.GetType();
         if (clazz.FullName.Equals("java.lang.UNIXProcess"))
         {
             FieldInfo f = Runtime.GetDeclaredField(clazz, "pid");
             return(f.GetInt(p).ToString());
         }
         else
         {
             Log.Trace("Unable to determine pid for " + p + " since it is not a UNIXProcess");
             return(null);
         }
     }
     catch (Exception t)
     {
         Log.Trace("Unable to determine pid for " + p, t);
         return(null);
     }
 }