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 a 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, which is used to register a function with the process, executes the registered function when exiting, and is called several times by registration;


2. Command-line parameters and environment table:

extern char **environ; Each program has an environment table, and the environment table, like the parameter table, is also an array of character pointers, where each pointer ends with a 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;}

Execution Result:

================ARGV pram===================
argc[0]=./main


=============environment pram==============
hostname=150
Selinux_role_requested=
Term=xterm
Shell=/bin/bash
histsize=1000
ssh_client=192.168.0.88 12069 22

(......)

3. Typical storage space for C programs

The typical storage space for C programs is as follows:


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

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



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

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.