Process Learning (1) address space of a process

Source: Internet
Author: User

One afternoon many years ago, when the sun was shining, it was youth. I met TA for the first time that day. -- Process

1. What is a process?

Running is a dynamic execution process of the Program (dynamic, and periodic)

Processes are the basic units for independent resources (what resources) and execution.

2. What is a process in a computer?

A process is a data structure with a property of p_id, which is the ID of the process. ppid is the parent ID of the process and the status of the process. Run? Blocking, botnets (z), etc.

3. How to view processes?

Windows Task Manager, Linux ps, and other commands.

4linux. How are processes organized?

There is a tree structure and parent-child relationship between processes. Use pstree, as shown below

init─┬─NetworkManager─┬─dhclient     │                └─2*[{NetworkManager}]     ├─accounts-daemon───{accounts-daemon}     ├─acpid     ├─apache2─┬─apache2     │         └─2*[apache2───26*[{apache2}]]     ├─at-spi-bus-laun───2*[{at-spi-bus-laun}]     ├─atd     ├─avahi-daemon───avahi-daemon     ├─bluetoothd     ├─colord───2*[{colord}]     

We can see that the INIT process is the ancestor of all processes, and later orphan processes and botnets will say.

Just now, you said that the resources owned by the process refer to memory resources, that is, address space. Each process has its own address space. What is the address space? (Classic example of C language) http://soft.chinabyte.com/ OS /51/12324551.shtml (reference)

A program execution process is a process. Write a C program and run it. We will find multiple processes. Note that all of the following are virtual address spaces.

1. Text: the name indicates the text segment, and C indicates the code segment. In this case, machine commands are stored.

2. Initialization segment: the initialization variable is stored. If int A = 5 is in the code, a is initialized.

2. uninitialized segment: int A [100], defined, but not initialized, will be initialized to 0;

3. The heap and stack are very important. Let's talk about them carefully (what is the heap and stack in Java ?)

1. first look at the figure. The stack grows up and down.

2. We know that the object created in new must be deleted (What about Java ?), Ta is allocated to the heap. To put it bluntly, the memory allocated by programmers should be released by themselves, so they can not recycle garbage.

3. the stack is managed by the program itself, such as local variables and temporary variables. The process ends and all are automatically released. (What is the relationship between this stack and the stack in the data structure? If I have time, I will write how the program is called and the implementation principle of recursion will be implemented ).

Well, what is the address space of a common process?

In fact, they are similar.

Http://blog.csdn.net/wangxiaolong_china/article/details/6844325 (reference)

 

 

Void print (char * STR, INTP) {char * S1 = "ABCDE"; // ABCDE is in the constant area, and S1 is in the stack char * S2 = "ABCDE "; // ABCDE in the constant area, S2 on the stack s2-s1 = 6 may be equal to 0, the compiler optimized the same constant, only one copy is saved in the memory. // & S1> & S2 char S3 [] = "abcdeee"; // abcdeee is in the constant area, and S3 is on the stack, the array is saved as a copy of abcdeee long int * S4 [100]; char * S5 = "ABCDE"; int A = 5; int B = 6; int C; int D; // a, B, c, d are all on the stack, & A> & B> & C> & D address reverse growth char * q = STR; // int M = P; // char * r = (char *) malloc (1); char * w = (char *) malloc (1); // R <W Heap positive growth printf ("S1 = % P S2 = % P S3 = % P S4 = % P S5 = % p na = % p B = % Pc = % P d = % pn STR = % PQ = % p m = % p r = % P w = % PN ", s1, S2, S3, S4, S5, & A, & B, & C, & D, & STR, Q, & P, & M, R, W );} /* the stack and heap are dynamically allocated when the program is running, and local variables are allocated on the stack. The stack increases in reverse direction and the address decreases. The allocated memory space such as malloc is in the heap space. The heap is growing positively and the address is increasing progressively. R, W variables on the stack (then & R> & W), R, W content in the heap (that is, r <W ). */

 

The following will mainly look at Java Memory Allocation

 

 

 

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: [email protected] 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.