Skip to content

Commit 2155a0c

Browse files
committed
target: Add is_running()
Add the "is_running" function that can be used to check if a given process is running on the target device. It will return True if a process matching the name is found and Falsa otherwise. Signed-off-by: Kajetan Puchalski <[email protected]>
1 parent 1730f69 commit 2155a0c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

devlib/target.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
from devlib.exception import (DevlibTransientError, TargetStableError,
5555
TargetNotRespondingError, TimeoutError,
5656
TargetTransientError, KernelConfigKeyError,
57-
TargetError, HostError, TargetCalledProcessError) # pylint: disable=redefined-builtin
57+
TargetError, HostError, TargetCalledProcessError,
58+
TargetStableCalledProcessError) # pylint: disable=redefined-builtin
5859
from devlib.utils.ssh import SshConnection
5960
from devlib.utils.android import AdbConnection, AndroidProperties, LogcatMonitor, adb_command, adb_disconnect, INTENT_FLAGS
6061
from devlib.utils.misc import memoized, isiterable, convert_new_lines, groupby_value
@@ -279,6 +280,12 @@ def shutils(self):
279280
self._setup_shutils()
280281
return self._shutils
281282

283+
def is_running(self, comm):
284+
cmd_ps = f'''{self.busybox} ps -A -T -o stat,comm'''
285+
cmd_awk = f'''{self.busybox} awk 'BEGIN{{found=0}} {{state=$1; $1=""; if ($state != "Z" && $0 == " {comm}") {{found=1}}}} END {{print found}}' '''
286+
result = self.execute(f"{cmd_ps} | {cmd_awk}")
287+
return bool(int(result))
288+
282289
@tls_property
283290
def _conn(self):
284291
try:

0 commit comments

Comments
 (0)