public class AndroidProcess
extends java.lang.Object
implements android.os.Parcelable
Modifier and Type | Field and Description |
---|---|
static android.os.Parcelable.Creator<AndroidProcess> |
CREATOR |
java.lang.String |
name
the process name
|
int |
pid
the process id
|
Modifier | Constructor and Description |
---|---|
|
AndroidProcess(int pid)
AndroidProcess constructor
|
protected |
AndroidProcess(android.os.Parcel in) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
attr_current()
/proc/[pid]/attr/current (since Linux 2.6.0)
|
Cgroup |
cgroup()
/proc/[pid]/cgroup (since Linux 2.6.24)
|
java.lang.String |
cmdline()
/proc/[pid]/cmdline
|
int |
describeContents() |
int |
oom_adj()
/proc/[pid]/oom_adj (since Linux 2.6.11)
|
int |
oom_score_adj()
/proc/[pid]/oom_score_adj (since Linux 2.6.36)
|
java.lang.String |
read(java.lang.String filename)
Read the contents of a file in /proc/[pid]/[filename].
|
Stat |
stat()
/proc/[pid]/stat
|
Statm |
statm()
Provides information about memory usage, measured in pages.
|
Status |
status()
/proc/[pid]/status
|
java.lang.String |
wchan()
The symbolic name corresponding to the location in the kernel where the process is sleeping.
|
void |
writeToParcel(android.os.Parcel dest,
int flags) |
public final java.lang.String name
public final int pid
public static final android.os.Parcelable.Creator<AndroidProcess> CREATOR
public AndroidProcess(int pid) throws java.io.IOException
pid
- the process idjava.io.IOException
- if /proc/[pid] does not exist or we don't have read access.protected AndroidProcess(android.os.Parcel in)
public java.lang.String read(java.lang.String filename) throws java.io.IOException
filename
- the relative path to the file.java.io.IOException
- if the file does not exist or we don't have read permissions.public java.lang.String attr_current() throws java.io.IOException
/proc/[pid]/attr/current (since Linux 2.6.0)
The contents of this file represent the current security attributes of the process.
In SELinux, this file is used to get the security context of a process. Prior to Linux 2.6.11, this file could not be used to set the security context (a write was always denied), since SELinux limited process security transitions to execve(2) (see the description of /proc/[pid]/attr/exec, below). ince Linux 2.6.11, SELinux lifted this restriction and began supporting "set" operations via writes to this node if authorized by policy, although use of this operation is only suitable for applications that are trusted to maintain any desired separation between the old and new security contexts. Prior to Linux 2.6.28, SELinux did not allow threads within a multi- threaded process to set their security context via this node as it would yield an inconsistency among the security contexts of the threads sharing the same memory space. Since Linux 2.6.28, SELinux lifted this restriction and began supporting "set" operations for threads within a multithreaded process if the new security context is bounded by the old security context, where the bounded relation is defined in policy and guarantees that the new security context has a subset of the permissions of the old security context. Other security modules may choose to support "set" operations via writes to this node.
java.io.IOException
- if the file does not exist or we don't have read permissions.public java.lang.String cmdline() throws java.io.IOException
/proc/[pid]/cmdline
This read-only file holds the complete command line for the process, unless the process is a zombie. In the latter case, there is nothing in this file: that is, a read on this file will return 0 characters. The command-line arguments appear in this file as a set of strings separated by null bytes ('\0'), with a further null byte after the last string.
java.io.IOException
- if the file does not exist or we don't have read permissions.name
public Cgroup cgroup() throws java.io.IOException
/proc/[pid]/cgroup (since Linux 2.6.24)
This file describes control groups to which the process/task belongs. For each cgroup hierarchy there is one entry containing colon-separated fields of the form:
5:cpuacct,cpu,cpuset:/daemons
The colon-separated fields are, from left to right:
This file is present only if the CONFIG_CGROUPS kernel configuration option is enabled.
Cgroup
for this processjava.io.IOException
public int oom_adj() throws java.io.IOException
/proc/[pid]/oom_adj (since Linux 2.6.11)
This file can be used to adjust the score used to select which process should be killed in an out-of-memory (OOM) situation. The kernel uses this value for a bit-shift operation of the process's oom_score value: valid values are in the* range -16 to +15, plus the special value -17, which disables OOM-killing altogether for this process. A positive score increases the likelihood of this process being killed by the OOM-killer; a negative score decreases the likelihood.
The default value for this file is 0; a new process inherits its parent's oom_adj setting. A process must be privileged (CAP_SYS_RESOURCE) to update this file.
Since Linux 2.6.36, use of this file is deprecated in favor of /proc/[pid]/oom_score_adj.
java.io.IOException
- if the file does not exist or we don't have read permissions.public int oom_score_adj() throws java.io.IOException
/proc/[pid]/oom_score_adj (since Linux 2.6.36)
This file can be used to adjust the badness heuristic used to select which process gets killed in out-of-memory conditions.
The badness heuristic assigns a value to each candidate task ranging from 0 (never kill) to 1000 (always kill) to determine which process is targeted. The units are roughly a proportion along that range of allowed memory the process may allocate from, based on an estimation of its current memory and swap use. For example, if a task is using all allowed memory, its badness score will be 1000. If it is using half of its allowed memory, its score will be 500.
There is an additional factor included in the badness score: root processes are given 3% extra memory over other tasks.
The amount of "allowed" memory depends on the context in which the OOM-killer was called. If it is due to the memory assigned to the allocating task's cpuset being exhausted, the allowed memory represents the set of mems assigned to that cpuset (see cpuset(7)). If it is due to a mempolicy's node(s) being exhausted, the allowed memory represents the set of mempolicy nodes. If it is due to a memory limit (or swap limit) being reached, the allowed memory is that configured limit. Finally, if it is due to the entire system being out of memory, the allowed memory represents all allocatable resources.
The value of oom_score_adj is added to the badness score before it is used to determine which task to kill. Acceptable values range from -1000 (OOM_SCORE_ADJ_MIN) to +1000 (OOM_SCORE_ADJ_MAX). This allows user space to control the preference for OOM-killing, ranging from always preferring a certain task or completely disabling it from OOM killing. The lowest possible value, -1000, is equivalent to disabling OOM- killing entirely for that task, since it will always report a badness score of 0.
Consequently, it is very simple for user space to define the amount of memory to consider for each task. Setting a oom_score_adj value of +500, for example, is roughly equivalent to allowing the remainder of tasks sharing the same system, cpuset, mempolicy, or memory controller resources to use at least 50% more memory. A value of -500, on the other hand, would be roughly equivalent to discounting 50% of the task's allowed memory from being considered as scoring against the task.
For backward compatibility with previous kernels, /proc/[pid]/oom_adj can still be used to tune the badness score. Its value is scaled linearly with oom_score_adj.
Writing to /proc/[pid]/oom_score_adj or /proc/[pid]/oom_adj will change the other with its scaled value.
java.io.IOException
- if the file does not exist or we don't have read permissions.public Stat stat() throws java.io.IOException
/proc/[pid]/stat
Status information about the process. This is used by ps(1). It is defined in the kernel source file fs/proc/array.c.
The fields, in order, with their proper scanf(3) format specifiers, are:
Stat
for this processjava.io.IOException
- if the file does not exist or we don't have read permissions.public Statm statm() throws java.io.IOException
Provides information about memory usage, measured in pages.
The columns are:
Statm
for this processjava.io.IOException
- if the file does not exist or we don't have read permissions.public Status status() throws java.io.IOException
/proc/[pid]/status
Provides much of the information in /proc/[pid]/stat and /proc/[pid]/statm in a format that's easier for humans to parse.
Here's an example:
$ cat /proc/$$/status Name: bash State: S (sleeping) Tgid: 3515 Pid: 3515 PPid: 3452 TracerPid: 0 Uid: 1000 1000 1000 1000 Gid: 100 100 100 100 FDSize: 256 Groups: 16 33 100 VmPeak: 9136 kB VmSize: 7896 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 7572 kB VmRSS: 6316 kB VmData: 5224 kB VmStk: 88 kB VmExe: 572 kB VmLib: 1708 kB VmPMD: 4 kB VmPTE: 20 kB VmSwap: 0 kB Threads: 1 SigQ: 0/3067 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000010000 SigIgn: 0000000000384004 SigCgt: 000000004b813efb CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: ffffffffffffffff Seccomp: 0 Cpus_allowed: 00000001 Cpus_allowed_list: 0 Mems_allowed: 1 Mems_allowed_list: 0 voluntary_ctxt_switches: 150 nonvoluntary_ctxt_switches: 545
The fields are as follows:
Status
for this processjava.io.IOException
- if the file does not exist or we don't have read permissions.public java.lang.String wchan() throws java.io.IOException
java.io.IOException
- if the file does not exist or we don't have read permissions.public int describeContents()
describeContents
in interface android.os.Parcelable
public void writeToParcel(android.os.Parcel dest, int flags)
writeToParcel
in interface android.os.Parcelable