Process.java revision cd0e839a2448deea50f79bddeba782c546b33893
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.os; 18 19import android.net.LocalSocketAddress; 20import android.net.LocalSocket; 21import android.util.Log; 22import dalvik.system.Zygote; 23 24import java.io.BufferedWriter; 25import java.io.DataInputStream; 26import java.io.IOException; 27import java.io.OutputStreamWriter; 28import java.util.ArrayList; 29 30/*package*/ class ZygoteStartFailedEx extends Exception { 31 /** 32 * Something prevented the zygote process startup from happening normally 33 */ 34 35 ZygoteStartFailedEx() {}; 36 ZygoteStartFailedEx(String s) {super(s);} 37 ZygoteStartFailedEx(Throwable cause) {super(cause);} 38} 39 40/** 41 * Tools for managing OS processes. 42 */ 43public class Process { 44 private static final String LOG_TAG = "Process"; 45 46 private static final String ZYGOTE_SOCKET = "zygote"; 47 48 /** 49 * Name of a process for running the platform's media services. 50 * {@hide} 51 */ 52 public static final String ANDROID_SHARED_MEDIA = "com.android.process.media"; 53 54 /** 55 * Name of the process that Google content providers can share. 56 * {@hide} 57 */ 58 public static final String GOOGLE_SHARED_APP_CONTENT = "com.google.process.content"; 59 60 /** 61 * Defines the UID/GID under which system code runs. 62 */ 63 public static final int SYSTEM_UID = 1000; 64 65 /** 66 * Defines the UID/GID under which the telephony code runs. 67 */ 68 public static final int PHONE_UID = 1001; 69 70 /** 71 * Defines the UID/GID for the user shell. 72 * @hide 73 */ 74 public static final int SHELL_UID = 2000; 75 76 /** 77 * Defines the UID/GID for the log group. 78 * @hide 79 */ 80 public static final int LOG_UID = 1007; 81 82 /** 83 * Defines the UID/GID for the WIFI supplicant process. 84 * @hide 85 */ 86 public static final int WIFI_UID = 1010; 87 88 /** 89 * Defines the GID for the group that allows write access to the SD card. 90 * @hide 91 */ 92 public static final int SDCARD_RW_GID = 1015; 93 94 /** 95 * Defines the UID/GID for the NFC service process. 96 * @hide 97 */ 98 public static final int NFC_UID = 1022; 99 100 /** 101 * Defines the start of a range of UIDs (and GIDs), going from this 102 * number to {@link #LAST_APPLICATION_UID} that are reserved for assigning 103 * to applications. 104 */ 105 public static final int FIRST_APPLICATION_UID = 10000; 106 /** 107 * Last of application-specific UIDs starting at 108 * {@link #FIRST_APPLICATION_UID}. 109 */ 110 public static final int LAST_APPLICATION_UID = 99999; 111 112 /** 113 * Defines a secondary group id for access to the bluetooth hardware. 114 */ 115 public static final int BLUETOOTH_GID = 2000; 116 117 /** 118 * Standard priority of application threads. 119 * Use with {@link #setThreadPriority(int)} and 120 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal 121 * {@link java.lang.Thread} class. 122 */ 123 public static final int THREAD_PRIORITY_DEFAULT = 0; 124 125 /* 126 * *************************************** 127 * ** Keep in sync with utils/threads.h ** 128 * *************************************** 129 */ 130 131 /** 132 * Lowest available thread priority. Only for those who really, really 133 * don't want to run if anything else is happening. 134 * Use with {@link #setThreadPriority(int)} and 135 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal 136 * {@link java.lang.Thread} class. 137 */ 138 public static final int THREAD_PRIORITY_LOWEST = 19; 139 140 /** 141 * Standard priority background threads. This gives your thread a slightly 142 * lower than normal priority, so that it will have less chance of impacting 143 * the responsiveness of the user interface. 144 * Use with {@link #setThreadPriority(int)} and 145 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal 146 * {@link java.lang.Thread} class. 147 */ 148 public static final int THREAD_PRIORITY_BACKGROUND = 10; 149 150 /** 151 * Standard priority of threads that are currently running a user interface 152 * that the user is interacting with. Applications can not normally 153 * change to this priority; the system will automatically adjust your 154 * application threads as the user moves through the UI. 155 * Use with {@link #setThreadPriority(int)} and 156 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal 157 * {@link java.lang.Thread} class. 158 */ 159 public static final int THREAD_PRIORITY_FOREGROUND = -2; 160 161 /** 162 * Standard priority of system display threads, involved in updating 163 * the user interface. Applications can not 164 * normally change to this priority. 165 * Use with {@link #setThreadPriority(int)} and 166 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal 167 * {@link java.lang.Thread} class. 168 */ 169 public static final int THREAD_PRIORITY_DISPLAY = -4; 170 171 /** 172 * Standard priority of the most important display threads, for compositing 173 * the screen and retrieving input events. Applications can not normally 174 * change to this priority. 175 * Use with {@link #setThreadPriority(int)} and 176 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal 177 * {@link java.lang.Thread} class. 178 */ 179 public static final int THREAD_PRIORITY_URGENT_DISPLAY = -8; 180 181 /** 182 * Standard priority of audio threads. Applications can not normally 183 * change to this priority. 184 * Use with {@link #setThreadPriority(int)} and 185 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal 186 * {@link java.lang.Thread} class. 187 */ 188 public static final int THREAD_PRIORITY_AUDIO = -16; 189 190 /** 191 * Standard priority of the most important audio threads. 192 * Applications can not normally change to this priority. 193 * Use with {@link #setThreadPriority(int)} and 194 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal 195 * {@link java.lang.Thread} class. 196 */ 197 public static final int THREAD_PRIORITY_URGENT_AUDIO = -19; 198 199 /** 200 * Minimum increment to make a priority more favorable. 201 */ 202 public static final int THREAD_PRIORITY_MORE_FAVORABLE = -1; 203 204 /** 205 * Minimum increment to make a priority less favorable. 206 */ 207 public static final int THREAD_PRIORITY_LESS_FAVORABLE = +1; 208 209 /** 210 * Default thread group - gets a 'normal' share of the CPU 211 * @hide 212 */ 213 public static final int THREAD_GROUP_DEFAULT = 0; 214 215 /** 216 * Background non-interactive thread group - All threads in 217 * this group are scheduled with a reduced share of the CPU. 218 * @hide 219 */ 220 public static final int THREAD_GROUP_BG_NONINTERACTIVE = 1; 221 222 /** 223 * Foreground 'boost' thread group - All threads in 224 * this group are scheduled with an increased share of the CPU 225 * @hide 226 **/ 227 public static final int THREAD_GROUP_FG_BOOST = 2; 228 229 public static final int SIGNAL_QUIT = 3; 230 public static final int SIGNAL_KILL = 9; 231 public static final int SIGNAL_USR1 = 10; 232 233 // State for communicating with zygote process 234 235 static LocalSocket sZygoteSocket; 236 static DataInputStream sZygoteInputStream; 237 static BufferedWriter sZygoteWriter; 238 239 /** true if previous zygote open failed */ 240 static boolean sPreviousZygoteOpenFailed; 241 242 /** 243 * Start a new process. 244 * 245 * <p>If processes are enabled, a new process is created and the 246 * static main() function of a <var>processClass</var> is executed there. 247 * The process will continue running after this function returns. 248 * 249 * <p>If processes are not enabled, a new thread in the caller's 250 * process is created and main() of <var>processClass</var> called there. 251 * 252 * <p>The niceName parameter, if not an empty string, is a custom name to 253 * give to the process instead of using processClass. This allows you to 254 * make easily identifyable processes even if you are using the same base 255 * <var>processClass</var> to start them. 256 * 257 * @param processClass The class to use as the process's main entry 258 * point. 259 * @param niceName A more readable name to use for the process. 260 * @param uid The user-id under which the process will run. 261 * @param gid The group-id under which the process will run. 262 * @param gids Additional group-ids associated with the process. 263 * @param enableDebugger True if debugging should be enabled for this process. 264 * @param zygoteArgs Additional arguments to supply to the zygote process. 265 * 266 * @return int If > 0 the pid of the new process; if 0 the process is 267 * being emulated by a thread 268 * @throws RuntimeException on fatal start failure 269 * 270 * {@hide} 271 */ 272 public static final int start(final String processClass, 273 final String niceName, 274 int uid, int gid, int[] gids, 275 int debugFlags, 276 String[] zygoteArgs) 277 { 278 if (supportsProcesses()) { 279 try { 280 return startViaZygote(processClass, niceName, uid, gid, gids, 281 debugFlags, zygoteArgs); 282 } catch (ZygoteStartFailedEx ex) { 283 Log.e(LOG_TAG, 284 "Starting VM process through Zygote failed"); 285 throw new RuntimeException( 286 "Starting VM process through Zygote failed", ex); 287 } 288 } else { 289 // Running in single-process mode 290 291 Runnable runnable = new Runnable() { 292 public void run() { 293 Process.invokeStaticMain(processClass); 294 } 295 }; 296 297 // Thread constructors must not be called with null names (see spec). 298 if (niceName != null) { 299 new Thread(runnable, niceName).start(); 300 } else { 301 new Thread(runnable).start(); 302 } 303 304 return 0; 305 } 306 } 307 308 /** 309 * Start a new process. Don't supply a custom nice name. 310 * {@hide} 311 */ 312 public static final int start(String processClass, int uid, int gid, 313 int[] gids, int debugFlags, String[] zygoteArgs) { 314 return start(processClass, "", uid, gid, gids, 315 debugFlags, zygoteArgs); 316 } 317 318 private static void invokeStaticMain(String className) { 319 Class cl; 320 Object args[] = new Object[1]; 321 322 args[0] = new String[0]; //this is argv 323 324 try { 325 cl = Class.forName(className); 326 cl.getMethod("main", new Class[] { String[].class }) 327 .invoke(null, args); 328 } catch (Exception ex) { 329 // can be: ClassNotFoundException, 330 // NoSuchMethodException, SecurityException, 331 // IllegalAccessException, IllegalArgumentException 332 // InvocationTargetException 333 // or uncaught exception from main() 334 335 Log.e(LOG_TAG, "Exception invoking static main on " 336 + className, ex); 337 338 throw new RuntimeException(ex); 339 } 340 341 } 342 343 /** retry interval for opening a zygote socket */ 344 static final int ZYGOTE_RETRY_MILLIS = 500; 345 346 /** 347 * Tries to open socket to Zygote process if not already open. If 348 * already open, does nothing. May block and retry. 349 */ 350 private static void openZygoteSocketIfNeeded() 351 throws ZygoteStartFailedEx { 352 353 int retryCount; 354 355 if (sPreviousZygoteOpenFailed) { 356 /* 357 * If we've failed before, expect that we'll fail again and 358 * don't pause for retries. 359 */ 360 retryCount = 0; 361 } else { 362 retryCount = 10; 363 } 364 365 /* 366 * See bug #811181: Sometimes runtime can make it up before zygote. 367 * Really, we'd like to do something better to avoid this condition, 368 * but for now just wait a bit... 369 */ 370 for (int retry = 0 371 ; (sZygoteSocket == null) && (retry < (retryCount + 1)) 372 ; retry++ ) { 373 374 if (retry > 0) { 375 try { 376 Log.i("Zygote", "Zygote not up yet, sleeping..."); 377 Thread.sleep(ZYGOTE_RETRY_MILLIS); 378 } catch (InterruptedException ex) { 379 // should never happen 380 } 381 } 382 383 try { 384 sZygoteSocket = new LocalSocket(); 385 386 sZygoteSocket.connect(new LocalSocketAddress(ZYGOTE_SOCKET, 387 LocalSocketAddress.Namespace.RESERVED)); 388 389 sZygoteInputStream 390 = new DataInputStream(sZygoteSocket.getInputStream()); 391 392 sZygoteWriter = 393 new BufferedWriter( 394 new OutputStreamWriter( 395 sZygoteSocket.getOutputStream()), 396 256); 397 398 Log.i("Zygote", "Process: zygote socket opened"); 399 400 sPreviousZygoteOpenFailed = false; 401 break; 402 } catch (IOException ex) { 403 if (sZygoteSocket != null) { 404 try { 405 sZygoteSocket.close(); 406 } catch (IOException ex2) { 407 Log.e(LOG_TAG,"I/O exception on close after exception", 408 ex2); 409 } 410 } 411 412 sZygoteSocket = null; 413 } 414 } 415 416 if (sZygoteSocket == null) { 417 sPreviousZygoteOpenFailed = true; 418 throw new ZygoteStartFailedEx("connect failed"); 419 } 420 } 421 422 /** 423 * Sends an argument list to the zygote process, which starts a new child 424 * and returns the child's pid. Please note: the present implementation 425 * replaces newlines in the argument list with spaces. 426 * @param args argument list 427 * @return PID of new child process 428 * @throws ZygoteStartFailedEx if process start failed for any reason 429 */ 430 private static int zygoteSendArgsAndGetPid(ArrayList<String> args) 431 throws ZygoteStartFailedEx { 432 433 int pid; 434 435 openZygoteSocketIfNeeded(); 436 437 try { 438 /** 439 * See com.android.internal.os.ZygoteInit.readArgumentList() 440 * Presently the wire format to the zygote process is: 441 * a) a count of arguments (argc, in essence) 442 * b) a number of newline-separated argument strings equal to count 443 * 444 * After the zygote process reads these it will write the pid of 445 * the child or -1 on failure. 446 */ 447 448 sZygoteWriter.write(Integer.toString(args.size())); 449 sZygoteWriter.newLine(); 450 451 int sz = args.size(); 452 for (int i = 0; i < sz; i++) { 453 String arg = args.get(i); 454 if (arg.indexOf('\n') >= 0) { 455 throw new ZygoteStartFailedEx( 456 "embedded newlines not allowed"); 457 } 458 sZygoteWriter.write(arg); 459 sZygoteWriter.newLine(); 460 } 461 462 sZygoteWriter.flush(); 463 464 // Should there be a timeout on this? 465 pid = sZygoteInputStream.readInt(); 466 467 if (pid < 0) { 468 throw new ZygoteStartFailedEx("fork() failed"); 469 } 470 } catch (IOException ex) { 471 try { 472 if (sZygoteSocket != null) { 473 sZygoteSocket.close(); 474 } 475 } catch (IOException ex2) { 476 // we're going to fail anyway 477 Log.e(LOG_TAG,"I/O exception on routine close", ex2); 478 } 479 480 sZygoteSocket = null; 481 482 throw new ZygoteStartFailedEx(ex); 483 } 484 485 return pid; 486 } 487 488 /** 489 * Starts a new process via the zygote mechanism. 490 * 491 * @param processClass Class name whose static main() to run 492 * @param niceName 'nice' process name to appear in ps 493 * @param uid a POSIX uid that the new process should setuid() to 494 * @param gid a POSIX gid that the new process shuold setgid() to 495 * @param gids null-ok; a list of supplementary group IDs that the 496 * new process should setgroup() to. 497 * @param enableDebugger True if debugging should be enabled for this process. 498 * @param extraArgs Additional arguments to supply to the zygote process. 499 * @return PID 500 * @throws ZygoteStartFailedEx if process start failed for any reason 501 */ 502 private static int startViaZygote(final String processClass, 503 final String niceName, 504 final int uid, final int gid, 505 final int[] gids, 506 int debugFlags, 507 String[] extraArgs) 508 throws ZygoteStartFailedEx { 509 int pid; 510 511 synchronized(Process.class) { 512 ArrayList<String> argsForZygote = new ArrayList<String>(); 513 514 // --runtime-init, --setuid=, --setgid=, 515 // and --setgroups= must go first 516 argsForZygote.add("--runtime-init"); 517 argsForZygote.add("--setuid=" + uid); 518 argsForZygote.add("--setgid=" + gid); 519 if ((debugFlags & Zygote.DEBUG_ENABLE_SAFEMODE) != 0) { 520 argsForZygote.add("--enable-safemode"); 521 } 522 if ((debugFlags & Zygote.DEBUG_ENABLE_DEBUGGER) != 0) { 523 argsForZygote.add("--enable-debugger"); 524 } 525 if ((debugFlags & Zygote.DEBUG_ENABLE_CHECKJNI) != 0) { 526 argsForZygote.add("--enable-checkjni"); 527 } 528 if ((debugFlags & Zygote.DEBUG_ENABLE_ASSERT) != 0) { 529 argsForZygote.add("--enable-assert"); 530 } 531 532 //TODO optionally enable debuger 533 //argsForZygote.add("--enable-debugger"); 534 535 // --setgroups is a comma-separated list 536 if (gids != null && gids.length > 0) { 537 StringBuilder sb = new StringBuilder(); 538 sb.append("--setgroups="); 539 540 int sz = gids.length; 541 for (int i = 0; i < sz; i++) { 542 if (i != 0) { 543 sb.append(','); 544 } 545 sb.append(gids[i]); 546 } 547 548 argsForZygote.add(sb.toString()); 549 } 550 551 if (niceName != null) { 552 argsForZygote.add("--nice-name=" + niceName); 553 } 554 555 argsForZygote.add(processClass); 556 557 if (extraArgs != null) { 558 for (String arg : extraArgs) { 559 argsForZygote.add(arg); 560 } 561 } 562 563 pid = zygoteSendArgsAndGetPid(argsForZygote); 564 } 565 566 if (pid <= 0) { 567 throw new ZygoteStartFailedEx("zygote start failed:" + pid); 568 } 569 570 return pid; 571 } 572 573 /** 574 * Returns elapsed milliseconds of the time this process has run. 575 * @return Returns the number of milliseconds this process has return. 576 */ 577 public static final native long getElapsedCpuTime(); 578 579 /** 580 * Returns the identifier of this process, which can be used with 581 * {@link #killProcess} and {@link #sendSignal}. 582 */ 583 public static final native int myPid(); 584 585 /** 586 * Returns the identifier of the calling thread, which be used with 587 * {@link #setThreadPriority(int, int)}. 588 */ 589 public static final native int myTid(); 590 591 /** 592 * Returns the identifier of this process's user. 593 */ 594 public static final native int myUid(); 595 596 /** 597 * Returns the UID assigned to a particular user name, or -1 if there is 598 * none. If the given string consists of only numbers, it is converted 599 * directly to a uid. 600 */ 601 public static final native int getUidForName(String name); 602 603 /** 604 * Returns the GID assigned to a particular user name, or -1 if there is 605 * none. If the given string consists of only numbers, it is converted 606 * directly to a gid. 607 */ 608 public static final native int getGidForName(String name); 609 610 /** 611 * Returns a uid for a currently running process. 612 * @param pid the process id 613 * @return the uid of the process, or -1 if the process is not running. 614 * @hide pending API council review 615 */ 616 public static final int getUidForPid(int pid) { 617 String[] procStatusLabels = { "Uid:" }; 618 long[] procStatusValues = new long[1]; 619 procStatusValues[0] = -1; 620 Process.readProcLines("/proc/" + pid + "/status", procStatusLabels, procStatusValues); 621 return (int) procStatusValues[0]; 622 } 623 624 /** 625 * Set the priority of a thread, based on Linux priorities. 626 * 627 * @param tid The identifier of the thread/process to change. 628 * @param priority A Linux priority level, from -20 for highest scheduling 629 * priority to 19 for lowest scheduling priority. 630 * 631 * @throws IllegalArgumentException Throws IllegalArgumentException if 632 * <var>tid</var> does not exist. 633 * @throws SecurityException Throws SecurityException if your process does 634 * not have permission to modify the given thread, or to use the given 635 * priority. 636 */ 637 public static final native void setThreadPriority(int tid, int priority) 638 throws IllegalArgumentException, SecurityException; 639 640 /** 641 * Call with 'false' to cause future calls to {@link #setThreadPriority(int)} to 642 * throw an exception if passed a background-level thread priority. This is only 643 * effective if the JNI layer is built with GUARD_THREAD_PRIORITY defined to 1. 644 * 645 * @hide 646 */ 647 public static final native void setCanSelfBackground(boolean backgroundOk); 648 649 /** 650 * Sets the scheduling group for a thread. 651 * @hide 652 * @param tid The indentifier of the thread/process to change. 653 * @param group The target group for this thread/process. 654 * 655 * @throws IllegalArgumentException Throws IllegalArgumentException if 656 * <var>tid</var> does not exist. 657 * @throws SecurityException Throws SecurityException if your process does 658 * not have permission to modify the given thread, or to use the given 659 * priority. 660 */ 661 public static final native void setThreadGroup(int tid, int group) 662 throws IllegalArgumentException, SecurityException; 663 /** 664 * Sets the scheduling group for a process and all child threads 665 * @hide 666 * @param pid The indentifier of the process to change. 667 * @param group The target group for this process. 668 * 669 * @throws IllegalArgumentException Throws IllegalArgumentException if 670 * <var>tid</var> does not exist. 671 * @throws SecurityException Throws SecurityException if your process does 672 * not have permission to modify the given thread, or to use the given 673 * priority. 674 */ 675 public static final native void setProcessGroup(int pid, int group) 676 throws IllegalArgumentException, SecurityException; 677 678 /** 679 * Set the priority of the calling thread, based on Linux priorities. See 680 * {@link #setThreadPriority(int, int)} for more information. 681 * 682 * @param priority A Linux priority level, from -20 for highest scheduling 683 * priority to 19 for lowest scheduling priority. 684 * 685 * @throws IllegalArgumentException Throws IllegalArgumentException if 686 * <var>tid</var> does not exist. 687 * @throws SecurityException Throws SecurityException if your process does 688 * not have permission to modify the given thread, or to use the given 689 * priority. 690 * 691 * @see #setThreadPriority(int, int) 692 */ 693 public static final native void setThreadPriority(int priority) 694 throws IllegalArgumentException, SecurityException; 695 696 /** 697 * Return the current priority of a thread, based on Linux priorities. 698 * 699 * @param tid The identifier of the thread/process to change. 700 * 701 * @return Returns the current priority, as a Linux priority level, 702 * from -20 for highest scheduling priority to 19 for lowest scheduling 703 * priority. 704 * 705 * @throws IllegalArgumentException Throws IllegalArgumentException if 706 * <var>tid</var> does not exist. 707 */ 708 public static final native int getThreadPriority(int tid) 709 throws IllegalArgumentException; 710 711 /** 712 * Determine whether the current environment supports multiple processes. 713 * 714 * @return Returns true if the system can run in multiple processes, else 715 * false if everything is running in a single process. 716 */ 717 public static final native boolean supportsProcesses(); 718 719 /** 720 * Set the out-of-memory badness adjustment for a process. 721 * 722 * @param pid The process identifier to set. 723 * @param amt Adjustment value -- linux allows -16 to +15. 724 * 725 * @return Returns true if the underlying system supports this 726 * feature, else false. 727 * 728 * {@hide} 729 */ 730 public static final native boolean setOomAdj(int pid, int amt); 731 732 /** 733 * Change this process's argv[0] parameter. This can be useful to show 734 * more descriptive information in things like the 'ps' command. 735 * 736 * @param text The new name of this process. 737 * 738 * {@hide} 739 */ 740 public static final native void setArgV0(String text); 741 742 /** 743 * Kill the process with the given PID. 744 * Note that, though this API allows us to request to 745 * kill any process based on its PID, the kernel will 746 * still impose standard restrictions on which PIDs you 747 * are actually able to kill. Typically this means only 748 * the process running the caller's packages/application 749 * and any additional processes created by that app; packages 750 * sharing a common UID will also be able to kill each 751 * other's processes. 752 */ 753 public static final void killProcess(int pid) { 754 sendSignal(pid, SIGNAL_KILL); 755 } 756 757 /** @hide */ 758 public static final native int setUid(int uid); 759 760 /** @hide */ 761 public static final native int setGid(int uid); 762 763 /** 764 * Send a signal to the given process. 765 * 766 * @param pid The pid of the target process. 767 * @param signal The signal to send. 768 */ 769 public static final native void sendSignal(int pid, int signal); 770 771 /** 772 * @hide 773 * Private impl for avoiding a log message... DO NOT USE without doing 774 * your own log, or the Android Illuminati will find you some night and 775 * beat you up. 776 */ 777 public static final void killProcessQuiet(int pid) { 778 sendSignalQuiet(pid, SIGNAL_KILL); 779 } 780 781 /** 782 * @hide 783 * Private impl for avoiding a log message... DO NOT USE without doing 784 * your own log, or the Android Illuminati will find you some night and 785 * beat you up. 786 */ 787 public static final native void sendSignalQuiet(int pid, int signal); 788 789 /** @hide */ 790 public static final native long getFreeMemory(); 791 792 /** @hide */ 793 public static final native void readProcLines(String path, 794 String[] reqFields, long[] outSizes); 795 796 /** @hide */ 797 public static final native int[] getPids(String path, int[] lastArray); 798 799 /** @hide */ 800 public static final int PROC_TERM_MASK = 0xff; 801 /** @hide */ 802 public static final int PROC_ZERO_TERM = 0; 803 /** @hide */ 804 public static final int PROC_SPACE_TERM = (int)' '; 805 /** @hide */ 806 public static final int PROC_TAB_TERM = (int)'\t'; 807 /** @hide */ 808 public static final int PROC_COMBINE = 0x100; 809 /** @hide */ 810 public static final int PROC_PARENS = 0x200; 811 /** @hide */ 812 public static final int PROC_OUT_STRING = 0x1000; 813 /** @hide */ 814 public static final int PROC_OUT_LONG = 0x2000; 815 /** @hide */ 816 public static final int PROC_OUT_FLOAT = 0x4000; 817 818 /** @hide */ 819 public static final native boolean readProcFile(String file, int[] format, 820 String[] outStrings, long[] outLongs, float[] outFloats); 821 822 /** @hide */ 823 public static final native boolean parseProcLine(byte[] buffer, int startIndex, 824 int endIndex, int[] format, String[] outStrings, long[] outLongs, float[] outFloats); 825 826 /** 827 * Gets the total Pss value for a given process, in bytes. 828 * 829 * @param pid the process to the Pss for 830 * @return the total Pss value for the given process in bytes, 831 * or -1 if the value cannot be determined 832 * @hide 833 */ 834 public static final native long getPss(int pid); 835} 836