public class ProcessManager extends Object
This class provides process-related tools to obtain and manage process status, including the following functions:
| 构造器 | 说明 |
|---|---|
ProcessManager() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static int[] |
getAvailableCores() |
Obtains CPU cores available for the current process on a multi-core device.
|
static int |
getGidByName(String name) |
Obtains the ID of the user group where a user belongs based on the user name.
|
static long |
getPastCpuTime() |
Obtains the CPU time (in milliseconds) from the time when the process starts to the current time.
|
static int |
getPid() |
Obtains the PID of the current process.
|
static long |
getStartRealtime() |
Obtains the elapsed real time (in milliseconds) taken from the start of the system to the start of the process.
|
static long |
getStartUptime() |
Obtains the elapsed time (in milliseconds) taken from the start of the system to the start of the process.
|
static int |
getThreadPriority(int tid) |
Obtains the thread priority based on the specified TID.
|
static int |
getTid() |
Obtains the TID of the current thread.
|
static int |
getUid() |
Obtains the UID of the current process.
|
static int |
getUidByName(String name) |
Obtains the UID based on the specified user name.
|
static boolean |
is64Bit() |
Checks whether the process is running in a 64-bit environment.
|
static boolean |
isAppUid(int uid) |
Checks whether the specified UID belongs to a particular application.
|
static boolean |
isIsolatedProcess() |
Checks whether the process is isolated.
|
static void |
kill(int pid) |
Kills a process based on its PID.
|
static void |
sendSignal(int pid,
int signal) |
Sends the specified signal to the process based on its PID.
|
static void |
setThreadPriority(int priority) |
Sets the priority for the current thread.
|
static void |
setThreadPriority(int tid,
int priority) |
Sets the priority for a thread based on its TID.
|
public static final long getStartUptime()
The elapsed time does not include the system sleep time.
getStartRealtime()public static final long getStartRealtime()
The elapsed real time includes the system sleep time.
getStartUptime()public static final long getPastCpuTime()
public static final int[] getAvailableCores()
The multi-core device may reserve multiple CPU cores for the current process. You can use this method to obtain available CPU cores when the process runs on the foreground.
public static final int getPid()
public static final int getTid()
public static final int getUid()
public static final int getUidByName(String name)
name - Indicates the user name based on which the UID will be obtained.-1 otherwise.public static final int getGidByName(String name)
name - Indicates the user name based on which the user group ID will be obtained.-1 otherwise.public static final int getThreadPriority(int tid)
throws IllegalArgumentException
tid - Indicates the TID.IllegalArgumentException - Throws this exception if the TID is invalid.public static final boolean is64Bit()
true if the process is running in a 64-bit environment; returns false otherwise.public static boolean isAppUid(int uid)
uid - Indicates the UID.true if the passed UID belongs to an application; returns false otherwise.public static final boolean isIsolatedProcess()
true if the process is isolated; returns false otherwise.public static final void setThreadPriority(int priority)
throws IllegalArgumentException,
SecurityException
priority - Indicates the thread priority to set. The value ranges from -20 to 19, where -20 means
the highest priority and 19 means the lowest.IllegalArgumentException - Throws this exception if the thread does not exist.SecurityException - Throws this exception if the process does not have permission to change or use the
thread priority.setThreadPriority(int, int)public static final void setThreadPriority(int tid,
int priority)
throws IllegalArgumentException,
SecurityException
tid - Indicates the TID.priority - Indicates the thread priority to set. The value ranges from -20 to 19, where -20 means
the highest priority and 19 means the lowest.IllegalArgumentException - Throws this exception if the thread does not exist.SecurityException - Throws this exception if the process does not have permission to change or use the
thread priority.setThreadPriority(int)public static final void sendSignal(int pid,
int signal)
pid - Indicates the PID.signal - Indicates the signal to send. The value ranges from 1 to 64.public static final void kill(int pid)
pid - Indicates the PID.