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===================
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
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)