Android system Development (8)--linx process Basic concepts

Source: Internet
Author: User

Proc File system in the traditional sense of the file system is used for the storage of information on block devices,/proc This directory is a virtual file system, it puts the data are in memory, so this directory itself does not occupy any hard disk space. Mainly includes the following system Information: memory management system process characteristics data File System device driver system bus power management Terminal system control parameters

Users and applications can get system information through proc, and can change certain parameters of the kernel. Because the information of the system, such as the process, is dynamically changed, so when the user or application reads the proc file, the proc file system dynamically reads the required information from the system kernel and submits it. These files or subfolders listed below are not always present in your system, depending on your kernel configuration and the modules that are loaded. In addition, there are three important directories under/proc: NET,SCSI and Sys. The SYS directory is writable and can be used to access or modify kernel parameters, while net and SCSI depend on the kernel configuration. For example, if the system does not support SCSI, the SCSI directory does not exist.

In addition to the above, there are a number of directories named, they are the process directory. Each process currently running in the system has a corresponding directory under/proc, with the PID number of the process as the directory name, which is the interface to read the process information. The self directory is the information interface of the read process itself and is a link.

Ii. What is a process process is typically defined as a running instance of a program that consists of two parts: one component is the operating system used tothe kernel object that manages the program. Kernel objects are places that the system uses to hold information about the process. The other component is the address space, which contains code and data for all executable modules or DLL modules. It also contains the space for dynamic memory allocations. such as thread stacks and stack allocation space. The process is actually the process of loading (mapping) The binary file of the disk into the memory space, and directing the CPU to go into memory and then compute, and return (I/O). Can think of such a problem, now we have three files on the hard disk xxx.exe,xxx.apk,xxx, how the operating system know which files are executables? The operating system recognizes executables in two ways, one in the system kernel (such as Linux and Windows) and the other in the internal library layer using virtual machines. The use of virtual machines is very convenient, we can modify and extend the virtual machine without modifying the kernel can be implemented across platforms. Third, the process of the running Process 1, the program loaded into memory (the instantiation of the program) 32-bit binary system The maximum addressable capacity is 2^32 = 2^10 * 2^2 = 1G * 4 = 4G, so we can use the maximum physical memory 4G. If we play the movie at the same time in 100 processes, we can still broadcast it normally. Put, what is this for? In fact, in addition to physical memory, there is a virtual memory virtual storage is an abstract concept, it provides an illusion for each process, each process is exclusive use of main memory (hard disk) virtual address space as follows: (note: The figure is from the "in-depth understanding of the computer system") The code and data for the user process definition are stored at the bottom of the address space, and for all processes, the code starts at the same fixed address. Next is the global variables and corresponding data locations, heaps, shared libraries, stacks. The top is the kernel virtual memory, the kernel always resides in memory, is part of the operating system, the area at the top of the address space is reserved for the kernel, does not allow the application to read or write the contents of this area or directly call the kernel code defined functions. 2, read the contents of the program section in memory, assign space to the variable, the process of addressing the operation process when calling the process is actually to map the binary file of the disk into the memory space and instruct the CPU to go to the memory address, then calculate and return (I/O).
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. int main () {
  5. printf ("Hello pid:%d\n", getpid ());
  6. printf ("Hello ppid:%d\n", getppid ());
  7. Char *p;
  8. scanf ("%s", p);
  9. return 0;
  10. }
Start this program (process) can see the ID of this process is 1634, the process's parent ID is 1617, below we use the command Ps-aux to look at the current process, the process's parent process is the shell process. First the binary program Getpid is recognized by the Linux system, the binary file is put into memory, the processor addresses and allocates memory space for the variables (the functions and variables are placed in different regions), and the result is output. Iv. two features in process operation 1, multitasking, multi-process "Concurrent our Linux is multi-tasking, time-sharing, a separate logic control flow, as if our program exclusive use of the processor, the following is the CPU process scheduling diagram. Process 1,2,3,4,5,6 ... when the CPU allocates a time fragment during the run, the processor is like a turntable, and when it points to a process, it assigns a time slice to the process, starting to execute the process, and so forth. 2, independent of each other, the memory is isolated using virtual memory, each process has a private address space, as if our program exclusive and use of memory. V. Process life cycle for a program, the process has three states: run, Hang, die. 1, set up a task (create a process) 2, ready to run (waiting for the CPU to allocate time slices) 3, is running (in the actual running state, if not allocated to the actual CPU chip, continue to wait) 4, suspended (divided into intrusive and non-intrusive), such as scanf waiting for user input is interrupted interrupt. 5. Extinction (when the task terminates or is reclaimed by the parent process)

Android system Development (8)--linx process Basic concepts

Related Article

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.