Skip to content

Commit b018d02

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 0a91007 commit b018d02

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

devlib/target.py

Lines changed: 7 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,11 @@ def shutils(self):
279280
self._setup_shutils()
280281
return self._shutils
281282

283+
def is_running(self, process):
284+
cmd = f'''{self.busybox} ps -A -o comm,stat | {self.busybox} awk '$1 == "{process}" && $2 != "Z"' '''
285+
result = self.execute(cmd, as_root=False)
286+
return bool(result)
287+
282288
@tls_property
283289
def _conn(self):
284290
try:

0 commit comments

Comments
 (0)