嵌套类 |
---|
class | ProcessUtil.KillException |
公共方法 |
---|
static Optional<IFileEntry> | findFileLoadedByProcess (ITestDevice device, String process, String filenameSubstr) 返回由指定进程加载的具有指定名称的第一个文件的文件条目 |
static Optional<List<String>> | findFilesLoadedByProcess (ITestDevice device, int pid, Pattern filePattern) 返回由指定进程加载的指定文件的文件名。 |
static Optional<String> | getProcessName (ITestDevice device, int pid) 从 /proc/pid/cmdline 中获取内容。 |
static boolean | killAll (ITestDevice device, String pgrepRegex, long timeoutMs, boolean expectExist) 将 SIGKILL 发送到匹配模式的所有进程。 |
static boolean | killAll (ITestDevice device, String pgrepRegex, long timeoutMs) 将 SIGKILL 发送到匹配模式的所有进程。 |
static void | killPid (ITestDevice device, int pid, long timeoutMs) 向进程发送 SIGKILL 并等待它退出。 |
static void | killPid (ITestDevice device, int pid, int signal, long timeoutMs) 向进程发送信号并等待它退出。 |
static Optional<List<String>> | listOpenFiles (ITestDevice device, int pid) 返回指定进程当前打开的文件名。 |
static Optional<Integer> | pidOf (ITestDevice device, String pgrepRegex) 获取与传递给 `pgrep` 的模式匹配的单个 pid。 |
static Optional<Map<Integer, String>> | pidsOf (ITestDevice device, String pgrepRegex) 获取与传递给 `pgrep` 的模式相匹配的 pids。 |
static void | waitPidExited (ITestDevice device, int pid) 等待进程退出。 |
static void | waitPidExited (ITestDevice device, int pid, long timeoutMs) 等待进程退出。 |
static Map<Integer, String> | waitProcessRunning (ITestDevice device, String pgrepRegex, long timeoutMs) 等到为给定的正则表达式找到正在运行的进程。 |
static Map<Integer, String> | waitProcessRunning (ITestDevice device, String pgrepRegex) 等到为给定的正则表达式找到正在运行的进程。 |
static AutoCloseable | withProcessKill (ITestDevice device, String pgrepRegex, Runnable beforeCloseKill, long timeoutMs) 在测试开始和结束时终止进程。 |
static AutoCloseable | withProcessKill (ITestDevice device, String pgrepRegex, Runnable beforeCloseKill) 在测试开始和结束时终止进程。 |
常量
PROCESS_POLL_PERIOD_MS
public static final long PROCESS_POLL_PERIOD_MS
常数值:250 (0x00000000000000fa)
PROCESS_WAIT_TIMEOUT_MS
public static final long PROCESS_WAIT_TIMEOUT_MS
常数值:10000 (0x0000000000002710)
公共方法
findFileLoadedByProcess
public static Optional<IFileEntry> findFileLoadedByProcess (ITestDevice device,
String process,
String filenameSubstr)
返回由指定进程加载的具有指定名称的第一个文件的文件条目
参数 |
---|
device | ITestDevice :要运行的设备 |
process | String :要查找的进程的 pgrep 模式 |
filenameSubstr | String : 进程加载的部分文件名/路径 |
退货 |
---|
Optional<IFileEntry> | 设备上文件路径的可选 IFileEntry(如果存在)。 |
投掷 |
---|
DeviceNotAvailableException | |
findFilesLoadedByProcess
public static Optional<List<String>> findFilesLoadedByProcess (ITestDevice device,
int pid,
Pattern filePattern)
返回由指定进程加载的指定文件的文件名。
参数 |
---|
device | ITestDevice :要运行的设备 |
pid | int : 要搜索的进程的 ID |
filePattern | Pattern :要返回的文件名的模式 |
退货 |
---|
Optional<List<String>> | 一个可选的过滤文件;如果找不到进程或无法读取打开的文件,则为空。 |
投掷 |
---|
DeviceNotAvailableException | |
获取进程名称
public static Optional<String> getProcessName (ITestDevice device,
int pid)
从 /proc/pid/cmdline 中获取内容。
参数 |
---|
device | ITestDevice :要使用的设备 |
pid | int : 要获取其名称的进程的 ID |
退货 |
---|
Optional<String> | /proc/pid/cmdline 内容的可选字符串;如果找不到 pid,则为空 |
投掷 |
---|
DeviceNotAvailableException | |
全杀
public static boolean killAll (ITestDevice device,
String pgrepRegex,
long timeoutMs,
boolean expectExist)
将 SIGKILL 发送到匹配模式的所有进程。
参数 |
---|
device | ITestDevice :要使用的设备 |
pgrepRegex | String :表示 pgrep 正则表达式的字符串 |
timeoutMs | long :在抛出 TimeoutException 之前等待多长时间 |
expectExist | boolean : 当没有进程被杀死时是否应该抛出异常 |
全杀
public static boolean killAll (ITestDevice device,
String pgrepRegex,
long timeoutMs)
将 SIGKILL 发送到匹配模式的所有进程。
参数 |
---|
device | ITestDevice :要使用的设备 |
pgrepRegex | String :表示 pgrep 正则表达式的字符串 |
timeoutMs | long :在抛出 TimeoutException 之前等待多长时间 |
杀死Pid
public static void killPid (ITestDevice device,
int pid,
long timeoutMs)
向进程发送 SIGKILL 并等待它退出。
参数 |
---|
device | ITestDevice :要使用的设备 |
pid | int : 等待直到退出的进程的 ID |
timeoutMs | long :在抛出 TimeoutException 之前等待多长时间 |
杀死Pid
public static void killPid (ITestDevice device,
int pid,
int signal,
long timeoutMs)
向进程发送信号并等待它退出。
参数 |
---|
device | ITestDevice :要使用的设备 |
pid | int : 等待直到退出的进程的 ID |
signal | int : 发送给进程的信号 |
timeoutMs | long :在抛出 TimeoutException 之前等待多长时间 |
列出打开的文件
public static Optional<List<String>> listOpenFiles (ITestDevice device,
int pid)
返回指定进程当前打开的文件名。
参数 |
---|
device | ITestDevice :要运行的设备 |
pid | int : 要搜索的进程的 ID |
退货 |
---|
Optional<List<String>> | 打开文件的可选;如果找不到进程或无法读取打开的文件,则为空。 |
投掷 |
---|
DeviceNotAvailableException | |
pidOf
public static Optional<Integer> pidOf (ITestDevice device,
String pgrepRegex)
获取与传递给 `pgrep` 的模式匹配的单个 pid。当有多个 PID 匹配该模式时抛出IllegalArgumentException
。
参数 |
---|
device | ITestDevice :要使用的设备 |
pgrepRegex | String :表示 pgrep 正则表达式的字符串 |
退货 |
---|
Optional<Integer> | pid 的可选整数;如果 pgrep 没有返回 EXIT_SUCCESS 则为空 |
投掷 |
---|
DeviceNotAvailableException | |
IllegalArgumentException | |
pids的
public static Optional<Map<Integer, String>> pidsOf (ITestDevice device,
String pgrepRegex)
获取与传递给 `pgrep` 的模式相匹配的 pids。因为 /proc/pid/comm 被截断了,所以将 `pgrep` 与 `-f` 一起传递以检查完整的命令行。
参数 |
---|
device | ITestDevice :要使用的设备 |
pgrepRegex | String :表示 pgrep 正则表达式的字符串 |
退货 |
---|
Optional<Map<Integer, String>> | pid 到命令行的可选映射;如果 pgrep 没有返回 EXIT_SUCCESS 则为空 |
投掷 |
---|
DeviceNotAvailableException | |
等待Pid退出
public static void waitPidExited (ITestDevice device,
int pid)
等待进程退出。这不是等待它改变,而是根本不存在。在轮询之间重用 pid 是可能的,但不太可能
参数 |
---|
device | ITestDevice :要使用的设备 |
pid | int : 等待直到退出的进程的 ID |
等待Pid退出
public static void waitPidExited (ITestDevice device,
int pid,
long timeoutMs)
等待进程退出。这不是等待它改变,而是根本不存在。在轮询之间重用 pid 是可能的,但不太可能
参数 |
---|
device | ITestDevice :要使用的设备 |
pid | int : 等待直到退出的进程的 ID |
timeoutMs | long :在抛出 TimeoutException 之前等待多长时间 |
等待进程运行
public static Map<Integer, String> waitProcessRunning (ITestDevice device,
String pgrepRegex,
long timeoutMs)
等到为给定的正则表达式找到正在运行的进程。
参数 |
---|
device | ITestDevice :要使用的设备 |
pgrepRegex | String :表示 pgrep 正则表达式的字符串 |
timeoutMs | long :在抛出 TimeoutException 之前等待多长时间 |
退货 |
---|
Map<Integer, String> | 从 pidsOf(...) 到命令映射的 pid |
投掷 |
---|
TimeoutException | |
DeviceNotAvailableException | |
等待进程运行
public static Map<Integer, String> waitProcessRunning (ITestDevice device,
String pgrepRegex)
等到为给定的正则表达式找到正在运行的进程。
参数 |
---|
device | ITestDevice :要使用的设备 |
pgrepRegex | String :表示 pgrep 正则表达式的字符串 |
退货 |
---|
Map<Integer, String> | 从 pidsOf(...) 到命令映射的 pid |
投掷 |
---|
TimeoutException | |
DeviceNotAvailableException | |
withProcessKill
public static AutoCloseable withProcessKill (ITestDevice device,
String pgrepRegex,
Runnable beforeCloseKill,
long timeoutMs)
在测试开始和结束时终止进程。
参数 |
---|
device | ITestDevice :要使用的设备 |
pgrepRegex | String : 要杀死的进程的名称模式,以提供给 pgrep |
beforeCloseKill | Runnable :在测试结束时在正常环境中终止进程之前需要清理的任何操作的可运行。可以为空。 |
timeoutMs | long :等待进程终止的毫秒数 |
退货 |
---|
AutoCloseable | 关闭时会再次杀死进程的对象 |
withProcessKill
public static AutoCloseable withProcessKill (ITestDevice device,
String pgrepRegex,
Runnable beforeCloseKill)
在测试开始和结束时终止进程。
参数 |
---|
device | ITestDevice :要使用的设备 |
pgrepRegex | String : 要杀死的进程的名称模式,以提供给 pgrep |
beforeCloseKill | Runnable :在测试结束时在正常环境中终止进程之前需要清理的任何操作的可运行。可以为空。 |
退货 |
---|
AutoCloseable | 关闭时会再次杀死进程的对象 |
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2022-11-18。
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"没有我需要的信息"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"太复杂/步骤太多"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"内容需要更新"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"示例/代码问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]