/// <summary> /// Gets the process information for a given process /// </summary> /// <param name="pid">The PID (process ID) of the process</param> /// <returns> /// Returns a valid proc_taskallinfo struct for valid processes that the caller /// has permission to access; otherwise, returns null /// </returns> internal static unsafe proc_taskallinfo?GetProcessInfoById(int pid) { // Negative PIDs are invalid if (pid < 0) { throw new ArgumentOutOfRangeException(nameof(pid)); } // Get the process information for the specified pid int size = sizeof(proc_taskallinfo); proc_taskallinfo info = default(proc_taskallinfo); int result = proc_pidinfo(pid, PROC_PIDTASKALLINFO, 0, &info, size); return(result == size ? new proc_taskallinfo?(info) : null); }
private static unsafe extern int proc_pidinfo( int pid, int flavor, ulong arg, proc_taskallinfo* buffer, int bufferSize);