Android Process Command View

Source: Internet
Author: User

? Process

Refers to a dynamic running process of a program with independent function on a data set, which is the smallest unit of the system for resource allocation and scheduling.

? A process can have multiple threads. Each thread must have a parent process.

? Process features: concurrency, dynamic, interactive, standalone, and asynchronous.

The life cycle of a process

Five states of the process

? Execution (task_running)

The process is being run by the CPU or is ready to be run by the scheduler at any time

? Zombie (Task_zombie)

When a process has stopped executing, but its parent process has not called wait () to inquire about its state, the process is said to be in a zombie state.

? Stop (task_stopped)

When a process receives a signal SIGSTOP,sigtstp,sigttin , or Sigttou , it enters a paused state. You can send a sigcont signal to it to allow the process to transition to an executable state.

? Sleep State

Assuming that the process needs to wait for a resource on the system while it is running in the kernel state, the process calls sleep_on () or interruptible_sleep_on () to voluntarily abandon the use of the CPU. And let the scheduler run other processes. It is said to be in a sleep-waiting state.

interruptible (task_interruptible)

The process is in that state. The system does not schedule the process to run.

When the system generates an interrupt.

Or frees the resources that the process is waiting for,

Or the process receives a signal.

Is able to wake the process to a ready state (it can execute the state).

Non-disruptive (task_uninterruptible)

Except that it will not be awakened by receiving a signal. This state is similar to the interruptible sleep state. But the process in that State has only been using the WAKE_UP () function to understand the ability to switch to an executable ready state when awakened. This state is usually used when the process has to wait for it to be interrupted or if the event is waiting to occur very quickly.

Process context

? Each process has its own process address space that does not interfere with each other. The address space is a linear virtual space of 4GB in size, and the virtual address that the user sees and touches is not able to see the actual physical memory address. Using such a virtual address will not only protect the operating system (the user cannot access the physical address directly), and, more importantly. The user program can use a larger address space than the actual physical memory.

? The 4GB process address space is divided into two parts: User space and kernel space.

? The user address space is from 0 to 3GB (0xC0000000),

? The kernel address space occupies 3GB to 4GB.

? The user process typically only has access to the virtual address of the user space and cannot access the virtual address of the kernel space.

? Only the real user process can access the kernel space by using system calls (on behalf of the user process running in the kernel state).

? Each time the process switches, the user space changes;

? Kernel space is mapped by the kernel, and it does not follow a process change. is fixed.

? The kernel space address has its own corresponding page table, and the user process has a different page table.

? The user space for each process is completely independent and irrelevant.

? BSS segment: In the architecture that uses the segment-memory management. BSS (BSS segment) generally refers to an area of memory that is used to store uninitialized global variables in the program.

BSS is the abbreviation for English block Started by symbol. BSS segments belong to static memory allocations.

? Data segment: In the architecture of segment memory management, the data segment generally refers to a piece of memory area that is used to hold the initialized global variables in the program.

The data segment belongs to static memory allocation.

? BSS segment: In the architecture of segment memory management, the BSS segment (BSS segment) generally refers to an area of memory that is used to store uninitialized global variables in the program. BSS is the abbreviation for English block Started by symbol.

BSS segments belong to static memory allocations.

? Data segment: In the architecture that uses segment memory management. Data segment generally refers to a piece of memory that is used to hold the initialized global variables in the program. The data segment belongs to static memory allocation.

? Code snippets: In a schema that uses segment memory management, code Segment/text segment generally refers to a piece of memory area that is used to store program execution code. The size of this part of the area is determined before the program executes, and the memory area is usually read-only, and some schemas agree that the code snippet is writable. Consent to the self-modification process.

In the code snippet, it is also possible to include some read-only constant variables, such as String constants.

? Stack is a special form of data structure in computer science, which is unique in that it can only be agreed on one end of the list (called the top of the stack). English as top) for join and delete operations. In addition, the implementation of the stack data structure can be completed through the array. A stack stack is a memory area that stores local variables in the program. Another stack stack is used to hold the field of the function call. Stack stacks are assigned voluntarily by the system itself. Users do not need to be concerned about their distribution and release.

? A heap is a piece of memory that is used by a program ape when the program executes. Dynamically allocates memory for process execution. The heap size is not fixed. Dynamic changes can be performed according to the program.

Controlled by New/delete in the program.

Fork Method

? The fork () function is used to create a new process from a process that already exists, a new process called a child process, and the original process is called the parent process.

? The child process that is obtained by using the fork () function is a replica of the parent process that inherits the address space of the entire process from the parent process, including the process context, code snippet, process stack, memory information, open file descriptor, signal control setting, process priority, process group number, current working folder, root folder, Resource constraints and control terminals, and the child process alone has its process number, resource usage and timers.

? Distinguish a parent-child process: Because the child process is almost completely replicated by the parent process, the parent-child process executes the same program. This requires a way to differentiate them and make them perform accordingly. The return value in the parent process is the process number of the child process, and 0 is returned in the child process.

Therefore, it is possible to determine whether the process is a parent or child process by a return value.

? Overhead: The cost of using the fork () function is very large, replicating most of the code snippets, data segments, and stack segments in the parent process, making the fork () function more expensive and running at a speed page that is not very fast.

exec method

? The EXEC function family provides a way to start and run a program in a process.

? It can find the executable file according to the specified file name or folder name, and use it to replace the data segment, code snippet, and stack segment of the original calling process, after running, the contents of the original calling process are replaced by the new process except for the process.

? A running file can be a binary file. It can also be a script file that runs under Linux, no matter what.

? When to use exec

? When the process feels that it can no longer make any contribution to the system and the user, it can invoke a random function in the EXEC function family to regenerate itself.

? Suppose a process wants to run and there is a program. Then it is able to call the fork () function to create a new process. Then call an arbitrary function in the EXEC function family. This looks like a new process created by running the application

? Look up: The first 4 functions in table 1 are found in the full file folder path, and the last two functions (i.e. two functions ending in P) can only give the file name, the system will voluntarily follow the environment variable "$PATH" the path specified by the search.

? How to pass the number of parameters: The EXEC function family has two kinds of parameters: one is enumerated each way. The other is to pass all the parameters of the overall construction pointer array.

Here it is distinguished by the 5th letter of the function name, and the letter "L" (list) is a way of enumerating the parameters. Its syntax is Constchar *arg, and the letter "V" (vector) conveys all the parameters of the overall construction pointer array, whose syntax is Char *const argv[]. The parameters here are actually all the command options strings that the user needs to use this executable file (including the executable command itself).

It is important to note that these parameters must end with null.

? Environment variables: The EXEC function family can default the system's environment variables, and can also pass in the specified environment variables. Here, the two functions execle () and Execve () ending with "e" (environment) are able to specify the environment variables used by the current process in envp[].

Exit method

? The terminate process uses the exit () and _exit () functions. When the process executes to the exit () or _exit () function. The process will unconditionally stop all remaining operations and clear the various data structures. and to terminate the implementation of this process.

? The _exit () function does this by simply stopping the process from executing, clearing the memory space it uses, and clearing its various data structures in the kernel, while the exit () function makes some wrappers on these bases, adding several operations before exiting.

? The most significant difference between the exit () function and the _exit () function is that the exit () function checks which files the process has opened before terminating the current process, and writes the contents of the file buffer back to the file, which is the "clean I/O buffer" item in Figure 1.

? In the standard library of Linux, there is an operation called "Buffered I/O (buffered I/O)", which is characterized by each open file. There is a buffer in memory.

? Each time a file is read, a number of records will be read sequentially, so that the next time you read the file will be able to read directly from the memory buffer, the same, each time the file is written, but also write in memory buffer, and so on to meet certain conditions (such as a certain number or encountered a certain character). The most typical is what we use in Vim: the W command), and then write the contents of the buffer once to the file.

? This technology has greatly added the speed of file read and write, but also brought some trouble to our programming. For example, some data you think have been written into the file, in fact, because the specific conditions are not met, they are only stored in the buffer, then use the _exit () function directly to shut down the process, the data in the buffer is lost.

Therefore, if you want to ensure the integrity of the data, it is best to use the exit () function.

?

CMD command-line related process command

? PS-View the status of processes in the system

? User indicates the START process users

? PID indicates the process flag number

? %CPU represents the percentage of time that the process consumes the CPU and the total execution time of the process

? %mem represents the proportion of memory and total memory that the process consumes

? VSZ indicates the amount of virtual memory consumed, in kilobytes

? RSS is the physical memory value that the process occupies, in kilobytes

? The TTY indicates that the process was established at the corresponding terminal, assuming that the "? "Indicates that the terminal is not occupied

? Start for process start time

? Time is run

? command is the corresponding name

? Stat is the execution state of the process

?  D. Non-disruptive sleep

?  R. Ready (in the executable queue)

? S, sleeping

? T, being traced or stopped

?  Z. Terminate (Zombie) process

? W, there is not enough memory paging to allocate

? <, high-priority processes

? N, low-priority processes

? L, memory paging is allocated and locked in memory (real-time system or I/O)

? +, foreground process

? S. An information header

? L, multithreading

? Introduction to the number of references:

-A: Displays information about all processes in the system.

-E: Displays information about all processes.

-F: Displaying the tree structure with ASCII characters and expressing the relationship between the programs

-L: Displays process information in long format.

-R: Shows only the process being executed.

-U: Displays user-facing formats (including information such as username, CPU, and memory usage).

-X: Displays process information on all non-control terminals.

-P: Displays information for the process specified by the process ID.

-T: Displays information about processes on the specified terminal.

-H: Displays the tree structure. Representing inter-program relationships

? top-Displays the current process status of the system

? The first line represents the current time, the system startup time, the current number of system logon users, and the average load.

? The second line shows all started, now executing, suspended (sleeping), and Zombie (Zombie) processes.

? The third line shows the current CPU usage, including the ratio of system occupancy, user usage, idle (idle) ratio.

? Row four shows the use of physical memory, which contains the total amount of memory that can be used, memory used, spare memory, and memory consumed by the buffer.

? Row five shows the usage of the swap partition, including the total swap partition, The used, spare, and the swap partition for the fast cache.

? PID (Process ID): progress flag number. Non-0 positive integers

? User: The username of all the people in the process

? PR: Priority level of the process

? NI: Number of priority levels for the process

? VIRT: Virtual memory value for process consumption

? RES: The physical memory value that the process occupies

? SHR: Shared memory value used by the process

? STAT: The status of the process. where S is dormant, R is executing, z is Zombie, n indicates the process precedence value is negative

? %CPU: CPU usage consumed by this process

? %MEM: The percentage of physical memory and total memory that the process occupies

? Time: Total CPU elapsed After the process was started

? Command: Start command name for process startup

? Introduction of references

? D: Specifies the interval of the update, in seconds.

? Q: There is no delay in any updates.

Assuming the user has a superuser, the top command will run with the highest precedence.

? C: Displays the full path and name of the process.

? S: Cumulative mode, which accumulates the CPU time of the completed or disappeared child process.

? S: Safe mode.

? I: Do not show any idle (idle) or zombie (Zombie) processes.

? N: Displays the number of updates that will exit top when finished.

Android Process Command View

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.