Build 1.0_r1(from source)

android.os
Class Process

java.lang.Object
  extended by android.os.Process

public class Process
extends Object

Tools for managing OS processes.


Field Summary
static String ANDROID_SHARED_MEDIA
          Name of a process for running the platform's media services.
static int BLUETOOTH_GID
          Defines a secondary group id for access to the bluetooth hardware.
static int FIRST_APPLICATION_UID
          Defines the start of a range of UIDs (and GIDs), going from this number to LAST_APPLICATION_UID that are reserved for assigning to applications.
static String GOOGLE_SHARED_APP_CONTENT
          Name of the process that Google content providers can share.
static int LAST_APPLICATION_UID
          Last of application-specific UIDs starting at FIRST_APPLICATION_UID.
static int PHONE_UID
          Defines the UID/GID under which the telephony code runs.
static int PROC_COMBINE
           
static int PROC_OUT_FLOAT
           
static int PROC_OUT_LONG
           
static int PROC_OUT_STRING
           
static int PROC_PARENS
           
static int PROC_SPACE_TERM
           
static int PROC_TERM_MASK
           
static int PROC_ZERO_TERM
           
static int SIGNAL_KILL
           
static int SIGNAL_QUIT
           
static int SIGNAL_USR1
           
(package private) static boolean sPreviousZygoteOpenFailed
          true if previous zygote open failed
static int SYSTEM_UID
          Defines the UID/GID under which system code runs.
(package private) static DataInputStream sZygoteInputStream
           
(package private) static LocalSocket sZygoteSocket
           
(package private) static BufferedWriter sZygoteWriter
           
static int THREAD_PRIORITY_AUDIO
          Standard priority of audio threads.
static int THREAD_PRIORITY_BACKGROUND
          Standard priority background threads.
static int THREAD_PRIORITY_DEFAULT
          Standard priority of application threads.
static int THREAD_PRIORITY_DISPLAY
          Standard priority of system display threads, involved in updating the user interface.
static int THREAD_PRIORITY_FOREGROUND
          Standard priority of threads that are currently running a user interface that the user is interacting with.
static int THREAD_PRIORITY_LESS_FAVORABLE
          Minimum increment to make a priority less favorable.
static int THREAD_PRIORITY_LOWEST
          Lowest available thread priority.
static int THREAD_PRIORITY_MORE_FAVORABLE
          Minimum increment to make a priority more favorable.
static int THREAD_PRIORITY_URGENT_AUDIO
          Standard priority of the most important audio threads.
static int THREAD_PRIORITY_URGENT_DISPLAY
          Standard priority of the most important display threads, for compositing the screen and retrieving input events.
(package private) static int ZYGOTE_RETRY_MILLIS
          retry interval for opening a zygote socket
 
Constructor Summary
Process()
           
 
Method Summary
static long getElapsedCpuTime()
          Returns elapsed milliseconds of the time this process has run.
static int getFreeMemory()
           
static int getGidForName(String name)
          Returns the GID assigned to a particular user name, or -1 if there is none.
static int[] getPids(String path, int[] lastArray)
           
static long getPss(int pid)
          Gets the total Pss value for a given process, in bytes.
static int getThreadPriority(int tid)
          Return the current priority of a thread, based on Linux priorities.
static int getUidForName(String name)
          Returns the UID assigned to a partlicular user name, or -1 if there is none.
static void killProcess(int pid)
          Kill the process with the given PID.
static int myPid()
          Returns the identifier of this process, which can be used with killProcess(int) and sendSignal(int, int).
static int myTid()
          Returns the identifier of the calling thread, which be used with setThreadPriority(int, int).
static boolean readProcFile(String file, int[] format, String[] outStrings, long[] outLongs, float[] outFloats)
           
static void readProcLines(String path, String[] reqFields, long[] outSizes)
           
static void sendSignal(int pid, int signal)
          Send a signal to the given process.
static void setArgV0(String text)
          Change this process's argv[0] parameter.
static int setGid(int uid)
           
static boolean setOomAdj(int pid, int amt)
          Set the out-of-memory badness adjustment for a process.
static void setThreadPriority(int priority)
          Set the priority of the calling thread, based on Linux priorities.
static void setThreadPriority(int tid, int priority)
          Set the priority of a thread, based on Linux priorities.
static int setUid(int uid)
           
static int start(String processClass, int uid, int gid, int[] gids, boolean enableDebugger, String[] zygoteArgs)
          Start a new process.
static int start(String processClass, String niceName, int uid, int gid, int[] gids, boolean enableDebugger, String[] zygoteArgs)
          Start a new process.
static boolean supportsProcesses()
          Determine whether the current environment supports multiple processes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANDROID_SHARED_MEDIA

public static final String ANDROID_SHARED_MEDIA
Name of a process for running the platform's media services.

See Also:
Constant Field Values

GOOGLE_SHARED_APP_CONTENT

public static final String GOOGLE_SHARED_APP_CONTENT
Name of the process that Google content providers can share.

See Also:
Constant Field Values

SYSTEM_UID

public static final int SYSTEM_UID
Defines the UID/GID under which system code runs.

See Also:
Constant Field Values

PHONE_UID

public static final int PHONE_UID
Defines the UID/GID under which the telephony code runs.

See Also:
Constant Field Values

FIRST_APPLICATION_UID

public static final int FIRST_APPLICATION_UID
Defines the start of a range of UIDs (and GIDs), going from this number to LAST_APPLICATION_UID that are reserved for assigning to applications.

See Also:
Constant Field Values

LAST_APPLICATION_UID

public static final int LAST_APPLICATION_UID
Last of application-specific UIDs starting at FIRST_APPLICATION_UID.

See Also:
Constant Field Values

BLUETOOTH_GID

public static final int BLUETOOTH_GID
Defines a secondary group id for access to the bluetooth hardware.

See Also:
Constant Field Values

THREAD_PRIORITY_DEFAULT

public static final int THREAD_PRIORITY_DEFAULT
Standard priority of application threads. Use with setThreadPriority(int) and setThreadPriority(int, int), not with the normal Thread class.

See Also:
Constant Field Values

THREAD_PRIORITY_LOWEST

public static final int THREAD_PRIORITY_LOWEST
Lowest available thread priority. Only for those who really, really don't want to run if anything else is happening. Use with setThreadPriority(int) and setThreadPriority(int, int), not with the normal Thread class.

See Also:
Constant Field Values

THREAD_PRIORITY_BACKGROUND

public static final int THREAD_PRIORITY_BACKGROUND
Standard priority background threads. This gives your thread a slightly lower than normal priority, so that it will have less chance of impacting the responsiveness of the user interface. Use with setThreadPriority(int) and setThreadPriority(int, int), not with the normal Thread class.

See Also:
Constant Field Values

THREAD_PRIORITY_FOREGROUND

public static final int THREAD_PRIORITY_FOREGROUND
Standard priority of threads that are currently running a user interface that the user is interacting with. Applications can not normally change to this priority; the system will automatically adjust your application threads as the user moves through the UI. Use with setThreadPriority(int) and setThreadPriority(int, int), not with the normal Thread class.

See Also:
Constant Field Values

THREAD_PRIORITY_DISPLAY

public static final int THREAD_PRIORITY_DISPLAY
Standard priority of system display threads, involved in updating the user interface. Applications can not normally change to this priority. Use with setThreadPriority(int) and setThreadPriority(int, int), not with the normal Thread class.

See Also:
Constant Field Values

THREAD_PRIORITY_URGENT_DISPLAY

public static final int THREAD_PRIORITY_URGENT_DISPLAY
Standard priority of the most important display threads, for compositing the screen and retrieving input events. Applications can not normally change to this priority. Use with setThreadPriority(int) and setThreadPriority(int, int), not with the normal Thread class.

See Also:
Constant Field Values

THREAD_PRIORITY_AUDIO

public static final int THREAD_PRIORITY_AUDIO
Standard priority of audio threads. Applications can not normally change to this priority. Use with setThreadPriority(int) and setThreadPriority(int, int), not with the normal Thread class.

See Also:
Constant Field Values

THREAD_PRIORITY_URGENT_AUDIO

public static final int THREAD_PRIORITY_URGENT_AUDIO
Standard priority of the most important audio threads. Applications can not normally change to this priority. Use with setThreadPriority(int) and setThreadPriority(int, int), not with the normal Thread class.

See Also:
Constant Field Values

THREAD_PRIORITY_MORE_FAVORABLE

public static final int THREAD_PRIORITY_MORE_FAVORABLE
Minimum increment to make a priority more favorable.

See Also:
Constant Field Values

THREAD_PRIORITY_LESS_FAVORABLE

public static final int THREAD_PRIORITY_LESS_FAVORABLE
Minimum increment to make a priority less favorable.

See Also:
Constant Field Values

SIGNAL_QUIT

public static final int SIGNAL_QUIT
See Also:
Constant Field Values

SIGNAL_KILL

public static final int SIGNAL_KILL
See Also:
Constant Field Values

SIGNAL_USR1

public static final int SIGNAL_USR1
See Also:
Constant Field Values

sZygoteSocket

static LocalSocket sZygoteSocket

sZygoteInputStream

static DataInputStream sZygoteInputStream

sZygoteWriter

static BufferedWriter sZygoteWriter

sPreviousZygoteOpenFailed

static boolean sPreviousZygoteOpenFailed
true if previous zygote open failed


ZYGOTE_RETRY_MILLIS

static final int ZYGOTE_RETRY_MILLIS
retry interval for opening a zygote socket

See Also:
Constant Field Values

PROC_TERM_MASK

public static final int PROC_TERM_MASK
See Also:
Constant Field Values

PROC_ZERO_TERM

public static final int PROC_ZERO_TERM
See Also:
Constant Field Values

PROC_SPACE_TERM

public static final int PROC_SPACE_TERM
See Also:
Constant Field Values

PROC_COMBINE

public static final int PROC_COMBINE
See Also:
Constant Field Values

PROC_PARENS

public static final int PROC_PARENS
See Also:
Constant Field Values

PROC_OUT_STRING

public static final int PROC_OUT_STRING
See Also:
Constant Field Values

PROC_OUT_LONG

public static final int PROC_OUT_LONG
See Also:
Constant Field Values

PROC_OUT_FLOAT

public static final int PROC_OUT_FLOAT
See Also:
Constant Field Values
Constructor Detail

Process

public Process()
Method Detail

start

public static final int start(String processClass,
                              String niceName,
                              int uid,
                              int gid,
                              int[] gids,
                              boolean enableDebugger,
                              String[] zygoteArgs)
Start a new process.

If processes are enabled, a new process is created and the static main() function of a processClass is executed there. The process will continue running after this function returns.

If processes are not enabled, a new thread in the caller's process is created and main() of processClass called there.

The niceName parameter, if not an empty string, is a custom name to give to the process instead of using processClass. This allows you to make easily identifyable processes even if you are using the same base processClass to start them.

Parameters:
processClass - The class to use as the process's main entry point.
niceName - A more readable name to use for the process.
uid - The user-id under which the process will run.
gid - The group-id under which the process will run.
gids - Additional group-ids associated with the process.
enableDebugger - True if debugging should be enabled for this process.
zygoteArgs - Additional arguments to supply to the zygote process.
Returns:
int If > 0 the pid of the new process; if 0 the process is being emulated by a thread
Throws:
RuntimeException - on fatal start failure

start

public static final int start(String processClass,
                              int uid,
                              int gid,
                              int[] gids,
                              boolean enableDebugger,
                              String[] zygoteArgs)
Start a new process. Don't supply a custom nice name.


getElapsedCpuTime

public static final long getElapsedCpuTime()
Returns elapsed milliseconds of the time this process has run.

Returns:
Returns the number of milliseconds this process has return.

myPid

public static final int myPid()
Returns the identifier of this process, which can be used with killProcess(int) and sendSignal(int, int).


myTid

public static final int myTid()
Returns the identifier of the calling thread, which be used with setThreadPriority(int, int).


getUidForName

public static final int getUidForName(String name)
Returns the UID assigned to a partlicular user name, or -1 if there is none. If the given string consists of only numbers, it is converted directly to a uid.


getGidForName

public static final int getGidForName(String name)
Returns the GID assigned to a particular user name, or -1 if there is none. If the given string consists of only numbers, it is converted directly to a gid.


setThreadPriority

public static final void setThreadPriority(int tid,
                                           int priority)
                                    throws IllegalArgumentException,
                                           SecurityException
Set the priority of a thread, based on Linux priorities.

Parameters:
tid - The identifier of the thread/process to change.
priority - A Linux priority level, from -20 for highest scheduling priority to 19 for lowest scheduling priority.
Throws:
IllegalArgumentException - Throws IllegalArgumentException if tid does not exist.
SecurityException - Throws SecurityException if your process does not have permission to modify the given thread, or to use the given priority.

setThreadPriority

public static final void setThreadPriority(int priority)
                                    throws IllegalArgumentException,
                                           SecurityException
Set the priority of the calling thread, based on Linux priorities. See setThreadPriority(int, int) for more information.

Parameters:
priority - A Linux priority level, from -20 for highest scheduling priority to 19 for lowest scheduling priority.
Throws:
IllegalArgumentException - Throws IllegalArgumentException if tid does not exist.
SecurityException - Throws SecurityException if your process does not have permission to modify the given thread, or to use the given priority.
See Also:
setThreadPriority(int, int)

getThreadPriority

public static final int getThreadPriority(int tid)
                                   throws IllegalArgumentException
Return the current priority of a thread, based on Linux priorities.

Parameters:
tid - The identifier of the thread/process to change.
Returns:
Returns the current priority, as a Linux priority level, from -20 for highest scheduling priority to 19 for lowest scheduling priority.
Throws:
IllegalArgumentException - Throws IllegalArgumentException if tid does not exist.

supportsProcesses

public static final boolean supportsProcesses()
Determine whether the current environment supports multiple processes.

Returns:
Returns true if the system can run in multiple processes, else false if everything is running in a single process.

setOomAdj

public static final boolean setOomAdj(int pid,
                                      int amt)
Set the out-of-memory badness adjustment for a process.

Parameters:
pid - The process identifier to set.
amt - Adjustment value -- linux allows -16 to +15.
Returns:
Returns true if the underlying system supports this feature, else false.

setArgV0

public static final void setArgV0(String text)
Change this process's argv[0] parameter. This can be useful to show more descriptive information in things like the 'ps' command.

Parameters:
text - The new name of this process.

killProcess

public static final void killProcess(int pid)
Kill the process with the given PID. Note that, though this API allows us to request to kill any process based on its PID, the kernel will still impose standard restrictions on which PIDs you are actually able to kill. Typically this means only the process running the caller's packages/application and any additional processes created by that app; packages sharing a common UID will also be able to kill each other's processes.


setUid

public static final int setUid(int uid)

setGid

public static final int setGid(int uid)

sendSignal

public static final void sendSignal(int pid,
                                    int signal)
Send a signal to the given process.

Parameters:
pid - The pid of the target process.
signal - The signal to send.

getFreeMemory

public static final int getFreeMemory()

readProcLines

public static final void readProcLines(String path,
                                       String[] reqFields,
                                       long[] outSizes)

getPids

public static final int[] getPids(String path,
                                  int[] lastArray)

readProcFile

public static final boolean readProcFile(String file,
                                         int[] format,
                                         String[] outStrings,
                                         long[] outLongs,
                                         float[] outFloats)

getPss

public static final long getPss(int pid)
Gets the total Pss value for a given process, in bytes.

Parameters:
pid - the process to the Pss for
Returns:
the total Pss value for the given process in bytes, or -1 if the value cannot be determined

Build 1.0_r1(from source)

Please submit a feedback, bug or feature