From cd19462002fb1363038cf3db02a9fdbecf0200f3 Mon Sep 17 00:00:00 2001 From: Toki Date: Wed, 1 Jan 2025 09:37:56 +0900 Subject: [PATCH] process list modified --- lib/platform/process.dart | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/platform/process.dart b/lib/platform/process.dart index 6dbfa85..eff242a 100644 --- a/lib/platform/process.dart +++ b/lib/platform/process.dart @@ -429,6 +429,45 @@ Future> findProcess(String searchWord, ? await ProcessSilentExecutor.runSlientBat(shell) : await runGetStdout(shell); pList = parseProcessStd(stdout); + } else if (Platform.isLinux) { + var shell = StringBuffer('ps -ef | grep \'$searchWord\' | grep -v grep'); + var result = await ProcessExecutor.run(shell, printStdout: false); + if (result.exitCode == 0) { + var procList = result.stdout.toString().split('\n'); + for (var proc in procList) { + if (proc.isNotEmpty) { + var info = ProcessInfo(); + var index = proc.indexOf(' '); + //deck 61218 920 0 08:24 ? 00:00:11 /home/deck/SDK/flutter/bin/cache/dart-sdk/bin/dart /home/deck/work/oto_cli/bin/main.dart scheduler -s + proc = proc.substring(index, proc.length).trimLeft(); + index = proc.indexOf(' '); + info.pid = int.parse(proc.substring(0, index)); + proc = proc.substring(index).trimLeft(); + + index = proc.indexOf(' '); + info.ppid = int.parse(proc.substring(0, index)); + proc = proc.substring(index).trimLeft(); + + index = proc.indexOf(' '); + info.cpuUsage = int.parse(proc.substring(0, index)); + proc = proc.substring(index).trimLeft(); + + index = proc.indexOf(' '); + info.startTime = proc.substring(0, index); + proc = proc.substring(index).trimLeft(); + + index = proc.indexOf(' '); + info.sessionName = proc.substring(0, index); + proc = proc.substring(index).trimLeft(); + + index = proc.indexOf(' '); + info.duration = proc.substring(0, index); + + info.name = proc.substring(index).trimLeft(); + pList.add(info); + } + } + } } else { var shell = StringBuffer( 'ps -A | grep \'$searchWord\' | grep -v grep | awk \'{\$2=\$3=""; print \$0}\''); @@ -628,6 +667,10 @@ class ProcessInfoListener { } class ProcessInfo { + String? startTime; + String? duration; + int? ppid; + int? cpuUsage; late String name; late int pid; late String sessionName;