Pre-process Startup routines: Initializing the Environment table
struct extern points to environment variables
externChar* * environ home// home directory PATH // environment variable Shell // start Shell user // start users int main (int argc ,char*argv[],*envp[]) Each process has a separate environment table for the initial environment table integration parent Process
Get Environment Table information
#include <unistd.h>#include<stdio.h>#include<string.h>intMainintargcChar*argv[],Char*envp[]) { intI=0; Char*env; while((Env=envp[i])! =NULL) {printf ("%s\n", env); I++; } return 0;}
Compile execution
Xdg_session_id=1 Term=Xtermshell=/bin/bashssh_client=192.168.1.103 49792 Aoldpwd=/mnt/Sharessh_tty=/dev/pts/8USER=pxgls_colors=rs=0:d i= on; the: ln= on; $: mh=xx:p i= +; -: so= on; *: Do= on; *: bd= +; -; on: cd= +; -; on: or= +; to; on: mi=xx: su=Panax Notoginseng; A: sg= -; +: ca= -; A: tw= -; the: ow= the; the: st=Panax Notoginseng; -: ex= on; +:*. tar= on; to:*. tgz= on; to:*. arc= on; to:*. arj= on; to:*. taz= on; to:*. lha= on; to:*. lz4= on; to:*. lzh= on; to:*. lzma= on; to:*. tlz= on; to:*. txz= on; to:*. tzo= on; to:*. t7z= on; to:*. zip= on; to:*. z= on; to:*. z= on; to:*. dz= on; to:*. gz= on; to:*. lrz= on; to:*. lz= on; to:*. lzo= on; to:*. xz= on; to:*. bz2= on; to:*. bz= on; to:*. tbz= on; to:*. tbz2= on; to:*. tz= on; to:*. deb= on; to:*. rpm= on; to:*. jar= on; to:*. war= on; to:*. ear= on; to:*. sar= on; to:*. rar= on; to:*. alz= on; to:*. ace= on; to:*. zoo= on; to:*. cpio= on; to:*. 7z= on; to:*. rz= on; to:*. cab= on; to:*. jpg= on; *:*. jpeg= on; *:*. gif= on; *:*. bmp= on; *:*. pbm= on; *:*. pgm= on; *:*. ppm= on; *:*. tga= on; *:*. xbm= on; *:*. xpm= on; *:*. tif= on; *:*. tiff= on; *:*. png= on; *:*. svg= on; *:*. svgz= on; *:*. mng= on; *:*. pcx= on; *:*. mov= on; *:*. mpg= on; *:*. mpeg= on; *:*. m2v= on; *:*. mkv= on; *:*. webm= on; *:*. ogm= on; *:*. mp4= on; *:*. m4v= on; *:*. mp4v= on; *:*. vob= on; *:*. qt= on; *:*. nuv= on; *:*. wmv= on; *:*. asf= on; *:*. rm= on; *:*. rmvb= on; *:*. flc= on; *:*. avi= on; *:*. fli= on; *:*. flv= on; *:*. gl= on; *:*. dl= on; *:*. xcf= on; *:*. xwd= on; *:*. yuv= on; *:*. cgm= on; *:*. emf= on; *:*. ogv= on; *:*. ogx= on; *:*. aac=xx; $:*. au=xx; $:*. flac=xx; $:*. m4a=xx; $:*. mid=xx; $:*. midi=xx; $:*. mka=xx; $:*. mp3=xx; $:*. mpc=xx; $:*. ogg=xx; $:*. ra=xx; $:*. wav=xx; $:*. oga=xx; $:*. opus=xx; $:*. spx=xx; $:*. xspf=xx; $: MAIL=/var/mail/Pxgpath=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local /php/bin:/usr/Includeqt_qpa_platformtheme=appmenu-qt5pwd=/mnt/share/My_clang=en_us. utf-8SHLVL=1HOME=/home/Pxglogname=pxgssh_connection=192.168.1.103 49792 192.168.1.180 ALessopen=| /usr/bin/lesspipe%Sxdg_runtime_dir=/run/user/ +Lessclose=/usr/bin/lesspipe%s%S_=./extern
Environment variable Operation function
#include <stdlib.h>Char*getenv (Const Char*name);//Get Environment VariablesintPutenvChar*STR);//Set environment variable putenv ("City=shanghai")intSetenvConst Char* Name,Const Char*value,intrewrite) Set the environment variable setenv (" City","Shanghai",1)intUnsetenv (Const Char*name);//Delete Environment Variables
Cases
#include <stdlib.h>#include<string.h>#include<unistd.h>#include<stdio.h>extern Char**environ;voidshow_env () {intI=0; Char*env; while((Env=environ[i])! =NULL) {printf ("%s\n", env); I++; }}intMainintargcChar*argv[]) {show_env (); printf ("-----------------------------\ n"); Putenv ("City=shanghai"); Show_env (); printf ("-------------------------------\ n"); Setenv (" Age","1",1); Show_env (); printf ("-------------------------------\ n"); Unsetenv (" City"); Show_env (); return 0;}
The environment table of process and signal