Esempio n. 1
0
        /// <summary>
        /// 从 shell ps 读取的一行中解析 pid
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        private PSLineInfo GetPSLineInfo(string line)
        {
            var match = s_regPsLine.Match(line);

            if (!match.Success)
            {
                return(null);
            }

            var        groups = match.Groups;
            PSLineInfo info   = new PSLineInfo();

            info.line  = line;
            info.user  = groups[1].Value;
            info.pid   = int.Parse(groups[2].Value);
            info.ppid  = int.Parse(groups[3].Value);
            info.vsz   = int.Parse(groups[4].Value);
            info.rss   = int.Parse(groups[5].Value);
            info.wchan = int.Parse(groups[6].Value);
            info.addr  = int.Parse(groups[7].Value);
            info.s     = groups[8].Value[0];
            info.name  = groups[9].Value;

            return(info);
        }
Esempio n. 2
0
        private void GetProcessList()
        {
            psList = new List <PSLineInfo>();
            ProcessStartInfo psi = new ProcessStartInfo();

            psi.FileName               = ADBFinder.adbPath;
            psi.Arguments              = "shell ps";
            psi.UseShellExecute        = false;
            psi.RedirectStandardOutput = true;

            List <string> strLst = new List <string>(1024);

            using (Process p = Process.Start(psi))
            {
                p.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
                {
                    if (e.Data == null)
                    {
                        return;
                    }

                    // shell ps 的输出内容不自带换行符因此可以存储到List中.....
                    strLst.Add(e.Data);
                };
                p.BeginOutputReadLine();
                p.WaitForExit();
            }

            foreach (string line in strLst)
            {
                PSLineInfo info = GetPSLineInfo(line.Trim());
                if (info != null)
                {
                    psList.Add(info);
                }
            }
        }