当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

中国科学技术大学:《Linux操作系统分析》课程教学资源(课件讲义)程序的执行

资源类别:文库,文档格式:PDF,文档页数:32,文件大小:243.61KB,团购合买
1. 可执行文件及其格式 2 Linux对可执行文件格式的管理 3 可执行文件的执行
点击下载完整版文档(PDF)

Linux操作系统分析 Chapter9-2 Linux中程序的执行 陈香兰(xlanchend@ustc.edu.cn) 计算机应用教研室。计算机学院 嵌入式系统实验室苏州研究院 中国科学技术大学 Fa112014 November 4,2014 4口4四是4P在刀0C 陈香兰(xlanchenoustc,edu,cn)(升界丸应Limx操作系统分折0 hapter-2 Linux中花开 Nove0er4.20141/21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linux操作系统分析 Chapter 9-2 Linux中程序的执行 陈香兰(xlanchen@ustc.edu.cn) 计算机应用教研室@计算机学院 嵌入式系统实验室@苏州研究院 中国科学技术大学 Fall 2014 November 4, 2014 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9-2 Linux中程序的执行 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 1 / 21

Outline 可执行文件及其格式 Linux对可执行文件格式的管理 可执行文件的执行 小结和作业 1口t4四是42刀00 陈香兰(xlanchenoustc,edu,cn)(升界丸应Limx操作系统分折0 hapter-2 Linux中花开 November 4.2014 2 21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Outline 1. 可执行文件及其格式 .2 Linux对可执行文件格式的管理 .3 可执行文件的执行 4. 小结和作业 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9-2 Linux中程序的执行 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 2 / 21

操作系统是如何通过可执行文件的内容 建立进程的执行上下文的? ·可执行文件的格式 ·程序以可执行文件的形式存放在磁盘上 ●库 ·可供很多程序使用的一些例程的集合 静态库VS共享库 ●命令行参数、环境变量等 She11提示符下输入 ·从she11继承而来,用户可修改 1口4四是42,刀00 陈香兰(xlanchenoustc,edu,cn)(升界丸应Limx操作系统分折0 hapter-2Lnux中花开 Nore0er4,20143/21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 操作系统是如何通过可执行文件的内容 建立进程的执行上下文的? 可执行文件的格式 ▶ 程序以可执行文件的形式存放在磁盘上 库 ▶ 可供很多程序使用的一些例程的集合 ▶ 静态库 vs 共享库 命令行参数、环境变量等 ▶ Shell提示符下输入 ▶ 从shell继承而来,用户可修改 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9-2 Linux中程序的执行 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 3 / 21

Outline 可执行文件及其格式 Liux对可执行文件格式的管理 可执行文件的执行 @小结和作业 1口t4四是42刀00 陈香兰(xlanchenoustc,ed加,cn)(计异款应Lim操作系统分折0 hapter9-2Lnug中花开 Novem0er4.20144/21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Outline . 1. 可执行文件及其格式 .2 Linux对可执行文件格式的管理 .3 可执行文件的执行 4. 小结和作业 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9-2 Linux中程序的执行 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 4 / 21

可执行文件 ·可执行文件是一个普通的文件,它描述了如何初始化 一个新的进程上下文 ●Linux中:Fork+execve ·例如:she11程序中执行一个命令 1口+4四是42在刀0C 陈香兰(xlanchenoustc,edu,cn)(升界丸应Limx操作系统分折0 hapter-2 Linux中花开 Nore0er4.20145/21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 可执行文件 可执行文件是一个普通的文件,它描述了如何初始化 一个新的进程上下文 Linux中:Fork + execve ▶ 例如:shell程序中执行一个命令 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9-2 Linux中程序的执行 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 5 / 21

可执行文件的格式 ●Linux标准的可执行格式 ELF Executable and Linking Format 查看ELF格式可执行文件xxx的头部信息: readelf-h xxx ·旧版的可执行文件格式 a.out Assembler OUT put format 目前,Linux中a.out被ELF取代 测试:可以使用readelf-h查看a.out可执行文件的header信息 ●其他 ·MS-DOS的exe文件 NIX BSD的COFF文件 1口4四1是42在月0C 陈香兰(x1 anchenoustc,ed加,cn)(升界丸应Limx操作系统分折0 hapter-2Lnux中枉开 November4,20146/21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 可执行文件的格式 Linux标准的可执行格式 ▶ ELF:Executable and Linking Format 查看ELF格式可执行文件xxx的头部信息: readelf − h xxx ▶ 旧版的可执行文件格式 ⋆ a.out:Assembler OUT put format 目前,Linux中a.out被ELF取代 测试:可以使用readelf -h查看a.out可执行文件的header信息 其他 ▶ MS-DOS的exe文件 ▶ UNIX BSD的COFF文件 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9-2 Linux中程序的执行 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 6 / 21

ELF文件格式 linkable executable sections segments ELF header (optional, program header describes ignored) table segments sections segments describes section header (optional, sections table ignored) 4口4四是42刀00 陈香兰(x1 anchenoustc,edu,cn)(升界轧应Limx特系纯分折0 hapter-2 Linux中花开 November 4.2014 7 21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ELF文件格式 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9-2 Linux中程序的执行 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 7 / 21

查看ELF格式可执行文件的头部信息 ●以“void main(void)}”为例: ubuntu-14.04:readelf -h hello ELF头: Magic:7f454c46010101000000000000000000 Class: ELF32 Data: 2's complement,little endian Version: 1 (current) OS/ABI: UNIX System V ABI Version: 0 Type: EXEC(可执行文件) Machine: Inte180386 Version: 0x1 入口点地址: 0x80482f0 程序头起点: 52(bytes into fi1e) Start of section headers: 4424 (bytes into file) 标志: 0x0 本头的大小: 52(字节) 程序头大小: 32(字节) Number of program headers: 9 节头大小: 40(字节) 节头数量: 30 字符串表索引节头: 27 陈香兰(x1 anchenoustc,edu.cn)(计界轧应Lmx操作系钝分折0 hapter9-2Lnug中轻开 Novem0er4.20148/21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 查看ELF格式可执行文件的头部信息 以“void main(void){}”为例: . ubuntu-14.04:readelf -h hello . . ELF 头: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2’s complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (可执行文件) Machine: Intel 80386 Version: 0x1 入口点地址: 0x80482f0 程序头起点: 52 (bytes into file) Start of section headers: 4424 (bytes into file) 标志: 0x0 本头的大小: 52 (字节) 程序头大小: 32 (字节) Number of program headers: 9 节头大小: 40 (字节) 节头数量: 30 字符串表索引节头: 27 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9-2 Linux中程序的执行 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 8 / 21

Outline 可执行文件及其格式 Linux对可执行文件格式的管理 可执行文件的执行 @小结和作业 1口t4四是42刀00 陈香兰(xlanchenoustc,ed加,cn)(计异款应Lim操作系统分折0 hapter9-2Lnug中花开 Novem0er4.20149/21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Outline . 1. 可执行文件及其格式 .2 Linux对可执行文件格式的管理 .3 可执行文件的执行 4. 小结和作业 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9-2 Linux中程序的执行 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 9 / 21

Linux对可执行文件格式的管理 。可执行文件格式的描述符:linux binfmt This structure defines the functions that are used to load the binary formats that ◆linux accepts. */ struct linux_binfmt{ struct list_head Ih; struct module "module; int(t1 oad_binary)(struct linux_binprm◆,struct pt_regs◆regs): int(1 oad_shlib)(struct file◆): int (*core_dump)(1ong signr,struct pt_regs *regs, struct file *file,unsigned long limit); unsigned long min_coredump;minimal dump size int hasvdso: ,load_binary:通过读取存放在可执行文件中的信息为当前进程 建立一个新的进程上下文 ~1 oad_sh1ib:动态的把一个共享库绑定到一个已经在运行的进程 ,core_dump:把当前进程的上下文保存到名为core的文件中 陈香兰(x1 anchenoustc.edu.cn)(升异款应Limx#作系纯分折0 hapter-2 Linux中径开 November 4.2014 10/21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linux对可执行文件格式的管理 可执行文件格式的描述符:linux_binfmt . . /* * This structure defines the functions that are used to load the binary formats that * linux accepts. */ struct linux_binfmt { struct list_head lh; struct module *module; int (*load_binary)(struct linux_binprm *, struct pt_regs * regs); int (*load_shlib)(struct file *); int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit); unsigned long min_coredump; /* minimal dump size */ int hasvdso; }; ▶ load_binary: 通过读取存放在可执行文件中的信息为当前进程 建立一个新的进程上下文 ▶ load_shlib: 动态的把一个共享库绑定到一个已经在运行的进程 ▶ core_dump:把当前进程的上下文保存到名为core的文件中 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9-2 Linux中程序的执行 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 10 / 21

点击下载完整版文档(PDF)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共32页,可试读12页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有