嵌套類 |
---|
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」的模式相符的 pid。 |
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)
公共方法
尋找透過進程載入的文件
public static Optional<IFileEntry> findFileLoadedByProcess (ITestDevice device,
String process,
String filenameSubstr)
傳回由指定進程載入的具有指定名稱的第一個檔案的檔案條目
參數 |
---|
device | ITestDevice :要運行的設備 |
process | String : 要尋找的程序的 pgrep 模式 |
filenameSubstr | String : 進程載入的檔案名稱/路徑的一部分 |
退貨 |
---|
Optional<IFileEntry> | 裝置上檔案路徑的可選 IFileEntry(如果存在)。 |
投擲 |
---|
DeviceNotAvailableException | |
尋找按進程載入的文件
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 | |
行程編號
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 | |
pidsOf
public static Optional<Map<Integer, String>> pidsOf (ITestDevice device,
String pgrepRegex)
取得與傳遞給「pgrep」的模式相符的 pid。因為 /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 | |
行程終止
public static AutoCloseable withProcessKill (ITestDevice device,
String pgrepRegex,
Runnable beforeCloseKill,
long timeoutMs)
在測試開始和結束時終止進程。
參數 |
---|
device | ITestDevice :要使用的設備 |
pgrepRegex | String :要終止的程序的名稱模式,以提供給 pgrep |
beforeCloseKill | Runnable :在測試結束時在正常環境中終止進程之前需要清理的任何操作的可運行狀態。可以為空。 |
timeoutMs | long :等待進程終止的時間(以毫秒為單位) |
退貨 |
---|
AutoCloseable | 當進程關閉時會再次終止進程的對象 |
行程終止
public static AutoCloseable withProcessKill (ITestDevice device,
String pgrepRegex,
Runnable beforeCloseKill)
在測試開始和結束時終止進程。
參數 |
---|
device | ITestDevice :要使用的設備 |
pgrepRegex | String :要終止的程序的名稱模式,以提供給 pgrep |
beforeCloseKill | Runnable :在測試結束時在正常環境中終止進程之前需要清理的任何操作的可運行狀態。可以為空。 |
退貨 |
---|
AutoCloseable | 當進程關閉時會再次終止進程的對象 |
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2023-12-01 (世界標準時間)。
[]
[]