Linux system Programming _6_ process environment (typical storage space for C programs)

Source: Internet
Author: User

1. Eight ways to end the Linux process:

Five Normal termination modes:

The main function returns;

Call exit;

Call _exit or _exit

The last thread returns from its startup routine

The last thread calls Pthread_exit

Three kinds of abnormal termination methods:

Call abort.

Received a signal to terminate;

The last thread responds to the cancellation request.

The difference between the Exit function and the _exit _exit function is that the Exit function invokes various termination handlers before ending the process, shutting down all IO streams, which causes the data in all buffers to be flushed (written to the disk file);

The Atexit (void (*fun) void) function is used to register the process function. Functions that are registered will run when exiting. The register will be called several times.

2. Command-line parameters and environment table:

extern char **environ; Each program will have an environment table, and the environment table is also an array of character pointers, with each pointer ending with null (/).

The global variable environ points to the first address of the environment table;

#include <stdio.h>int main (int argc, char **argv, char **env) {    int i;    printf ("================argv pram===================\n");    for (i=0; i<argc; i++)    {        printf ("argc[%d]=%s\n", I, Argv[i]);    }    printf ("\n=============environment pram==============\n");    for (; *env! = NULL; env++)    {        printf ("%s\n", *env);    }    return 0;}

Operation Result:

================ARGV pram===================

=============environment pram==============
ssh_client= 12069 22


3. Typical storage space for C programs

Typical storage spaces for C programs are as follows:

For Linux on X86 processors, the body segment starts with the 0x08048000 unit and the bottom of the stack starts under 0xc0000000. The unused space between the top of the heap and the bottom of the stack is very large.

Note: Uninitialized BSS segments are not stored in Program files on disk because the kernel sets them to 0 before the program starts, and the segments that need to be stored in the program file have only body segments and initialization data segments.

Linux system Programming _6_ process environment (typical storage space for C programs)

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: 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.