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)