APUE,TLPI Reading notes--linux process __linux

Source: Internet
Author: User
Process Space layout:

Text segment: A machine instruction that contains the running of a process

Initiallized Data Segment (initialization segment): Global and static variables containing explicit initialization

Uninitiallized Data Segment (uninitialized segment): Global and static variables that are not explicitly initialized

Stack (stack): Dynamic growth and contraction, made up of stack frames (stack frames)

Heap (heap): Dynamic allocation at runtime, heap top for program break


Virtual memory management (space locality, time locality):

Divides the memory into page (pages).

Each program has only partial paging residing in physical memory, constituting the resident set (resident set). Unused pages are saved in swap area.

The swap area is a disk-reserved area that is loaded with physical memory when required. The page that the process accesses is no longer physically memory, sends the page fault, the kernel suspends the process, and loads the page from the disk.

The kernel maintains a page table for each process (page tables)

Command-Line arguments (ARGC,ARGV) command line arguments
Environment list environment, load user or system set variables when program executes


SETJMP,LONGJMP: Jump will be at this time of the environment (at this time stack position, PC, register and other data saved) Save (action similar to the function of the stack, but pressed into a special position, jump to a special position), jump to other positions, and in the jump back to restore.


Memory allocation:

To adjust the program break:

int brk (void *end_data_segment);//program break set to End_data_segment

void* sbrk (intptr_t increment); program Break increase increment


malloc (), free (), calloc (), realloc (),

Memalign (), Posix_memalign (),//allocated aligned memory

Alloca () allocated on the stack

Memory leaks may also occur on memory allocations, so you can use the GLIBC malloc Debugging Tools and debug Libraries Valgrind, and so on

Memory fragmentation may also occur on memory allocations, which can be used for programs using different allocation policies (such as a multi-tier allocation policy for C + +)



Process Control:


Fork (),//returned two times, once in the child process returned 0, once in the parent process to return the subprocess PID;

Process fork, child processes and their shared pages, where code snippets are readable and cannot be modified, and the remainder cow (write-time copy)

Vfork ()//Patch Process Copy page table, virtual memory page, share the parent process until successful exec (), _exit () exit, suspend the parent process before the subprocess exec () or _exit ()


_exit (status);//Terminate after defining termination state

Exit (status),//Call exit handler, refresh stdio stream buffer, call _exit ()

Exit handler: Atexit (); registration, GLIBC provides exit processing with parameters On_exit ();

Where the exit handler is executed in the reverse order of the call


Wait (int * status);//block to child process termination, return the termination information to the shape variable that the status points to

Waitpid (PID, int* status, int option);//Depending on the PID, the identity waits for a different child process.

Also, use a set of macros to determine status. See Wait for details

Waitid ();//linux2.6.9 Join

Wait3 (); Wait4 ();//

Orphan process: When the parent process terminates, the parent process of the child process becomes the INIT process with ID 1;

Zombie Process: The child process terminates before the parent process calls wait (), and the subprocess has not been cleaned up as a zombie process (releasing most of the resources);

SIGCHLD the signal sent by the parent process to terminate the child process


Execve (): See Man for details

After exec (), the file descriptor retains

The system () function executes the shell command

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.