一、linux程序存储结构与进程结构
1.1 linux可执行文件结构
1.2 linux进程结构
1.3 栈和堆的区别
1.4 查看进程中各数据的存储位置
二、ANSI C内存管理api函数
2.1 申请、释放函数
2.2 内存管理函数
三、linux进程环境及系统限制
3.1 进程与命令参数
平时使用命令行参数时,如果有多个参数,参数的顺序是随意的。在linux中,提供了getopt(识别短参数)、getlongopt(识别长参数)识别命令行参数。
(1) extern int getopt(int argc, char *const*argv, const char *shortopts);//返回选项,并设置一些全局变量
//argc 命令参数的个数;
//argv 指向这些参数的字符串数组
//shortopts 所有可能的参数字符串
(2) extern int get_long(int argc, char *const *argv, const char *shortopts,const struct option * longopts, int *longind);//返回选项
//argc 命令参数的个数;
//argv 指向这些参数的字符串数组
//shortopts 所有可能的短参数字符串
//struct option 表示所有长参数的对应关系
//longind 一般设置成NULL
3.2 进程与环境变量
在shell终端可通过命令env、set查看当前系统环境信息。还可以通过如下函数获取、修改、删除某环境变量的值。
(1) extern char *getenv(const char *name);//获取name对应的环境变量的值
(2)extern int putenv(char *string);//添加环境变量值,格式为“NAME=VALUE”
(3)extern int setenv(const char *name, const char *value, int replace);
//name为欲设置的环境变量名;value为设置的值;replace=0,保留原值;replace!=0覆盖原值
(4)extern int unsetenv(const char *name);//删除指定环境变量的值
3.3 进程与命令参数
Char 8bit
Short int 16bit
Int 32bit
Long int 大小等于宏__WORDSIZE
Linux中进程的资源都是有限制的,可以使用函数来获取、修改这些限制。
extern int getrlimit(_rlimit_resource_t resource, struct rlimit *rlimits);// resource为限制项,rlimits用来存储获取的限制值
extern int setrlimit(_rlimit_resource_t resource, struct rlimit *rlimits);// resource为限制项,rlimits用来设置的限制值
3.4 linux时间管理
编程应用中,常需要读取系统时间、进程运行的时间等等。
extern clock_t clock(void);//返回当前时钟的计数值(user time + system time),转换为秒result/CLOCK_PER_SECOND
extern time_t time(time_t *timer);//返回自1970年来经历的秒数
extern char *ctime(cosnt time_t *timer);//返回当前时间字符串
extern struct tm* gmtime(cosnt time_t *timer); //返回UTC时间
extern struct tm* localtime(cosnt time_t *timer); //返回本地时间
extern char* asctime(cosnt struct tm *tp);//将tm结构体转换成时间字符串
extern size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *tp);//提取struct tm中的某一项