CreateProcessInfo() static private method

Creates a ProcessInfo from the data parsed from a /proc/pid/stat file and the associated tasks directory.
static private CreateProcessInfo ( Interop procFsStat, System.Text.ReusableTextReader reusableReader ) : ProcessInfo
procFsStat Interop
reusableReader System.Text.ReusableTextReader
return ProcessInfo
Example #1
0
        public static Process[] GetProcessesByName(string?processName, string machineName)
        {
            ProcessManager.ThrowIfRemoteMachine(machineName);

            int[] procIds   = ProcessManager.GetProcessIds();
            var   processes = new ArrayBuilder <Process>(string.IsNullOrEmpty(processName) ? procIds.Length : 0);

            // Iterate through all process IDs to load information about each process
            foreach (int pid in procIds)
            {
                ProcessInfo?processInfo = ProcessManager.CreateProcessInfo(pid, processName);
                if (processInfo != null)
                {
                    processes.Add(new Process(machineName, isRemoteMachine: false, pid, processInfo));
                }
            }

            return(processes.ToArray());
        }
Example #2
0
        /// <summary>
        /// Creates an array of <see cref="Process"/> components that are associated with process resources on a
        /// remote computer. These process resources share the specified process name.
        /// </summary>
        public static Process[] GetProcessesByName(string processName, string machineName)
        {
            ProcessManager.ThrowIfRemoteMachine(machineName);
            if (processName == null)
            {
                processName = string.Empty;
            }

            var reusableReader = new ReusableTextReader();
            var processes      = new List <Process>();

            foreach (int pid in ProcessManager.EnumerateProcessIds())
            {
                if (string.Equals(processName, Process.GetProcessName(pid), StringComparison.OrdinalIgnoreCase))
                {
                    ProcessInfo processInfo = ProcessManager.CreateProcessInfo(pid, reusableReader, processName);
                    processes.Add(new Process(machineName, false, processInfo.ProcessId, processInfo));
                }
            }

            return(processes.ToArray());
        }
Example #3
0
        /// <summary>
        /// Creates an array of <see cref="Process"/> components that are associated with process resources on a
        /// remote computer. These process resources share the specified process name.
        /// </summary>
        public static Process[] GetProcessesByName(string? processName, string machineName)
        {
            ProcessManager.ThrowIfRemoteMachine(machineName);
            if (processName == null)
            {
                processName = string.Empty;
            }

            var processes = new List<Process>();
            foreach (int pid in ProcessManager.EnumerateProcessIds())
            {
                if (Interop.procfs.TryReadStatFile(pid, out Interop.procfs.ParsedStat parsedStat) &&
                    string.Equals(processName, Process.GetUntruncatedProcessName(ref parsedStat), StringComparison.OrdinalIgnoreCase) &&
                    Interop.procfs.TryReadStatusFile(pid, out Interop.procfs.ParsedStatus parsedStatus))
                {
                    ProcessInfo processInfo = ProcessManager.CreateProcessInfo(ref parsedStat, ref parsedStatus, processName);
                    processes.Add(new Process(machineName, false, processInfo.ProcessId, processInfo));
                }
            }

            return processes.ToArray();
        }
Example #4
0
        public static Process[] GetProcessesByName(string?processName, string machineName)
        {
            ProcessManager.ThrowIfRemoteMachine(machineName);

            processName ??= "";

            ArrayBuilder <Process> processes = default;

            foreach (int pid in ProcessManager.EnumerateProcessIds())
            {
                if (Interop.procfs.TryReadStatFile(pid, out Interop.procfs.ParsedStat parsedStat))
                {
                    string actualProcessName = GetUntruncatedProcessName(ref parsedStat);
                    if ((processName == "" || string.Equals(processName, actualProcessName, StringComparison.OrdinalIgnoreCase)) &&
                        Interop.procfs.TryReadStatusFile(pid, out Interop.procfs.ParsedStatus parsedStatus))
                    {
                        ProcessInfo processInfo = ProcessManager.CreateProcessInfo(ref parsedStat, ref parsedStatus, actualProcessName);
                        processes.Add(new Process(machineName, isRemoteMachine: false, pid, processInfo));
                    }
                }
            }

            return(processes.ToArray());
        }