版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、操作系统设计与实现,Email:,主讲教师:袁国斌,Textbook,The MINIX Book: “Operating Systems: Design and Implementation” by Andrew Tanenbaum and Albert Woodhull, second edition. (required) The Unix System Call Books: “Advanced Unix Programming” by Marc J. Rochkind. (optional) “Advanced Programming in the Unix Environment”
2、 by W. Richard Stevens. (optional) 中文版: 操作系统设计与实现(第二版) (电子工业出版社),Prerequisites,Programming Languages: C (C+) and assembly Data Structure and basic Computer Architecture,CONTENTS INTRODUCTION PROCESSES INPUT/OUTPUT MEMORY MANAGEMENT FILE SYSTEMS,操作系统的功能: 管理系统软硬件资源 扩展计算机的功能 向用户提供服务,INTRODUCTION,1.1 WH
3、AT IS AN OPERATING SYSTEM? 1.2 HISTORY OF OPERATING SYSTEMS 1.3 OPERATING SYSTEM CONCEPTS 1.4 SYSTEM CALLS 1.5 OPERATING SYSTEM STRUCTURE,Review and ,What is “OS”? What is “Process”? What is “System Call”? What is “Kernel”? .,Applications.,Hardware: CPU/Memory/HD/DVD/Wireless,OS,.where applications
4、meet Hardware!,Kernel of SVR2 of AT 但在此要说明一下,只是运行chmod 的用户对此文件有w的权限才能重新设置文件权限。root可设置任何文件的权限.,How to use mount(挂装),/mnt/floppy /mnt/cdrom it is the default directory for mount floppy and cd-rom, its folder, and in some linux systems, the default is empty, we can add files there, but once the real dr
5、iver is mounted, the original files wont be visit,when we change our floppy, we have to unmount the disk, and remount the new one.,Special file of minix,In linux ,in order to make the I/O devices looks more like file, the special appeared. block special file disk character special file printer, mode
6、m 由于设备文件就代表了整个设备,就可以使用标准命令直接操作设备文件,从而直接访问硬件设备。利用这种方式,能完成很多有用的工作,但是这种方式也非常危险,例如对硬盘设备文件的操作失误会破坏整个硬盘的数据。幸好大部分直接访问设备的操作都为读取相应数据的操作,而不需要写入磁盘设备。 当某个设备不可使用,则其对应的设备文件也不能正常访问,因此直接访问设备文件可以判断对应的设备是否真正正常。例如,判断连接到第一个串口,ttyd0上的鼠标是否正常工作,使用命令 “cat /dev/ttyd 0” 来查看ttyd0上的输入数据,如果连接的有鼠标且工作正常,那么在移动鼠标的同时屏幕上就会显示出接收到的杂乱数据
7、。如果没有反应,说明鼠标工作不正确。但这也可能是其他程序接管了这个设备.,Pipe,It is a virtual file to connect two processes,More: sometimes, the output of a process is a common file ,sometimes the output is a pipe file, we have to use special system call to distinguish them.,1.3.3 Shell,Editors、compilers assemblers linkers interpreter
8、s not belong to OS, but from them ,we could familiar with the OS. #/bin/sh Shell-a command interpreter many command there, we will familiar with them later. Eg: Sh XXX.sh change its property, and run it,1.4 System Call,系统调用是操作系统提供给软件开发人员的唯一接口,开发人员可利用它使用系统功能。OS核心中都有一组实现系统功能的过程(子程序),系统调用就是对上述过程的调用。 Fo
9、r computers different type, the system call are different, and almost all the basic functions are programmed by assembler language.,Eg: Call read function in C language. count=read ( file, buffer, nbytes ); file: the file we are operate on; buffer: the buffer area we are using; nbytes: the bytes we
10、will read. (sometimes, the count may less then nbytes) System Call of Minix-Six Parts .Process management.Signals .File management.Directory argv1=“file1”argv2=“file2” envp-include some info related to this command, eg: terminal type, $HOME of user etc if (fork()!=0) /* Parent code.*/ waitpid(-1, ,M
11、ore info: *waitpid(-1, *-1: means any child process will be ok * it is changed by sys call when it is needed; To stack segment, it grows with the execution of program automatically, so, the point_data have to less than the pointer of stack segment, but it can larger than the data segments end addres
12、s or less than it (the data segment is changing).,*getpid when use fork ,only the father process can get the child process pid, if child process want it ,it have to use getpid ; *getgid get group id *setsid call to start a new session, and set the process groups pid to the callers.,1.4.2 System Call
13、s for signaling,*Signal just cancel *Sigaction a process is ready to accept some signals two address: one address to store current condition, another one is the address of the signal handling procedure. The sigaction call sigreturn to let the pre work to continue.,1.4.3 System Calls for File Managem
14、ent,dup - duplicates file descriptor for an open file. We will learn these info later,1.4.4 System Calls for Directory Management,Mkdir: create a directory Rmdir: remove a directory Link: it allow the same file to appear with two different names(share a file is different to give a copy to anybody wh
15、o want it) link: the change will be got by anyone, copy: the change only belongs to oneself. Eg: link(“/usr/jim/memo”, “/usr/ast/note”) memo is the original file ,note is a link of memo;,In Minx:,Any file has an only id to identify it, and any file has an i-node, it tell us who owns the file, and wh
16、ere the disk blocks are. The directory is a file ,it stored the i-node and filename, now back to our link:,After we use link,/usr/ast,/usr/jim,Mount:,mount (“/dev/fd0”, “/mnt/”,0),Cache,To make the file could be visited more quickly, almost all the OS design a cache, similar with the cache of our CP
17、U. Advantage: improve its speed. Disadvantage: may lead to crash. resaon: how to avoid the prob:,Common calls relate to directories,Chdir:chdir(“/usr/ast/test”) Chroot:change the roots root directory More: In Linux, almost all the users directory stored in /home, but only the roots directory is spec
18、ial , it is in /root, It make the root more safe than other users. But the root still can use chroot to change his home directory.,1.4.5 System Calls for Protection,*Learn to use chmod to protect your file To use setgid and setuid:02000 04000 only the root can create special file, in a process, we n
19、eed to let the user to create his special file, then we will use setuid, now the code will be 04755=04000+0755,then the user can create the file and his right is still limited. while, till now the real uid is not the root, but if we want to know the real uid ,we have to use getuid to reach it. And g
20、id is the same.,umask,Eg:Umask(022); Create (“file”,0777); now the right code wont be 0777,but 0755,when shell run unmask, the during the login time ,all the processes in the session will avoid many wrong operation, because the all the operation will be limited by unmask. Whats more, the use of 0755
21、,the real right of the user,it will help the system to make the file be well protected.,1.4.6 System Calls for Time Management,time: return the current time correspond to Jan.1.1970 (in seconds) stime: set the system time (only root can do this) utime: change the time of some files (the time is stor
22、ed in the file) times: return the time that the process had takes.,1.5 Operating System Structure,By analysis the system call of operating system, we had familiar with the basic function of the operating system, now we will come to the inner structures of operating system. We will touch four structu
23、res here: * Monolithic systems(整体结构) * Layered systems(分层结构) * Virtual machines(虚拟机) * Client-server model(客户-服务器结构),1.5 1 Monolithic Systems,整个操作系统是一组函数的集合,其中每个函数在需要的时候可以去调用任何其他函数。 In this technique: each procedure in this system has a well-defined interface in terms of parameters and results. each
24、 one is free to call any other one. How to realize this: compiles all the individual procedures, and then binds them together to a single object. Each procedure is visible to all others.,User program run in user mode,Operating system run in kernel mode,How it works,1. User program traps to the kerne
25、l use an kernel call or supervisor call(访管程序调用) 2. Operating system determines service number required from the parameters to check the service number 3.Operating system calls service procedure check dispatch table ,ensured the sys call 4.Control is returned to user program back to user mode, return
26、 the values,Simplify-What we need when design an OS?,*A main program invokes the requested service procedure;(3) *A set of service procedures carry out the system calls;(2) *A set of utility procedures help the service procedures.,1.5 2 Layered Systems,Compare with the pre pic ,it looks like a simpl
27、ified layered system, each layer serves for its upper level, and if we add more details there, we will got the THE. Dijkstra and his students designed the system for Electrologica X8 -1968 The THE is of six layers, each layer charge of its work ,and serve for upper layers. When in this layer, we nee
28、dnt care more detail of other layers.,Layers of THE,Layer0: provided the basic multiprogramming of the CPU; Layer1: did the memory management; Layer2: handled communication between each process and operation console; Layer3: Input/Output management Layer4: User programs Layer5: The operator But ! !
29、! All these layers just the design aid, in fact, all the parts are ultimately linked together into a single object program.,In MULTICS Layers is replaced by concentric rings, and each ring did different to the others, so it is more popular, and system call has more strict check on their parameters.,1.5 3 Virtual Machine,Virtual Machine in Java: To different machine, different Operating System Original Virtual Machine: (to any user, it looks like woking for himself) Time-Sharing Machine IBM OS/360
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 废渣外运施工方案(3篇)
- 拆迁高层施工方案(3篇)
- 飞机安全员培训课件
- 飞机原理科普
- 2026福建省水利投资开发集团有限公司招聘1人备考考试题库及答案解析
- 2026山东临沂市教育局部分事业单位招聘综合类岗位工作人员3人备考考试试题及答案解析
- 2026山东事业单位统考烟台市莱山区招聘4人考试参考题库及答案解析
- 2026国家税务总局山东省税务局招聘事业单位工作人员考试参考试题及答案解析
- 2026山东临沂市罗庄区部分事业单位公开招聘综合类岗位工作人员17人考试参考试题及答案解析
- 2026江西赣州交控数智能源有限责任公司招聘加油员岗3人参考考试题库及答案解析
- 新疆乌鲁木齐市2024-2025学年八年级(上)期末语文试卷(解析版)
- 2025年包头钢铁职业技术学院单招职业技能考试题库完整
- 苹果电脑macOS效率手册
- T-CHAS 20-3-7-1-2023 医疗机构药事管理与药学服务 第3-7-1 部分:药学保障服务 重点药品管理 高警示药品
- 2022年版 义务教育《数学》课程标准
- 供货保障方案及应急措施
- TOC基本课程讲义学员版-王仕斌
- 初中语文新课程标准与解读课件
- 中建通风与空调施工方案
- GB/T 3683-2023橡胶软管及软管组合件油基或水基流体适用的钢丝编织增强液压型规范
- 高考语言运用题型之长短句变换 学案(含答案)
评论
0/150
提交评论