《unix操作系统设计》英文版习题答案1
unix课后习题

unix课后习题第1章操作系统概述1、什么是操作系统?答:控制其他程序运⾏,管理系统资源并为⽤户提供操作界⾯的系统软件的集合。
2、操作系统有哪三种类型,他们之间有什么区别?答:单⽤户单进程、单⽤户多进程、多⽤户多进程。
第⼀个是操作系统在同⼀时间允许⼀个⽤户,同⼀时间只能运⾏⼀个进程。
3、对分时系统,给出⼀个清晰⽽准确的描述?答:多个⽤户分享使⽤⼀台JSJ,多个程序分时共享硬件和软件资源。
多路性、独占性、交互性和及时性。
4、⽬前典型操作系统的主要功能是什么?这些功能的基本⽤途是什么?答:功能,执⾏程序,程序的输⼊和输出操作进程间的通信,错误检测与报告,不同类型的⽂件操作,⽤户和安全管理。
5、分别列出字符⽤户界⾯和图形⽤户界⾯的⼀个优点和⼀个缺点?答:CUI执⾏效率⾼,外观不美观;GUI 便于使⽤,缺乏可扩展性。
6、分别列出字符⽤户界⾯和图形⽤户界⾯有什么不同?⽬前,在UNIX系统中最流⾏的图形⽤户界⾯是什么?它是由谁开发的?答:CUI通过输⼊命令来完成相关操作,GUI通过输⼊设备(如⿏标)来完成相关操作。
7、应⽤程序程序员接⼝(API)和应⽤程序⽤户接⼝(AUI)分别包括那些内容?答:AUI通过语⾔库和系统调⽤接⼝与操作系统内核联系在⼀起,应⽤软件构成了AUI,系统调⽤接⼝由⼀组为完成特定任务⽽执⾏内核代码的函数构成,语⾔库和系统调⽤接⼝构成API。
8、列出UNIX家族中常见的5种操作系统。
你现在使⽤的是哪⼀个UNIX系统?答:UNIX版本:AIX、BSD、FreeBSD、LINUX、system V。
第2章UNIX操作系统简史2、如果由你来设计POSIX标准,将包含那些内容?答:⽀持程序和命令互相兼容,易⽤性。
3、UNIX系统的前⾝是什么?UNIX及其前⾝最初在哪⾥,由谁开发的?答:前⾝是MULTICS,由Dennis Ritchie 和Ken Thompson在AT&T中研制。
第3章UNIX起步1、主存的作⽤是什么?答:主存⽤来存储正在运⾏的程序或进程。
Unix面试题(英文 附答案)1

Unix面试题(英文附答案)1问题:Unix面试题(英文附答案)1-8 回答:101. You install Linux and reboot your machine and you see only L instead of the expected LILO. What is wrong :The first stage boot loader loaded but not the second stage.102. 某用户在上机过程中启动了很多进程,下面哪一条命令能够找出名为shi 的进程。
:ps | find shi find | ps shi ps | grep shi103. What program allows you to acess SMB shares using ftp-like commmandsA. mountB. smbftpC. smbclientD. smbmountE. sambaExplain -p1:Explanation: The smbclient program allows you to acess SMB shares using commands similar to FTP.104. 在Linux下按键会重新启动计算机,这是因为:在inittab中有这样的指令。
105. What does the -N option do for the dhcpcd program :If the dhcpcd server is already running then it sends it an ALRM signal to get it to renew its lease.106. How many primary partitions can exist on an IDE hard drive :4107. 使用SAMBA服务器,一般来说,可以提供:文件服务打印服务108. 脚本/etc/rc.d/rc.local,通常运行在启动运行等级____ ____之后。
操作系统UNIX系统及答案

UNIX系统练习题(一)单项选择题1.由于与系统的绝大局部程序都用c语言写成,因此它具有( )的特点。
A有效简练 B.易移植 c.可扩大 D.开放性2.使命令的执行结果不在屏幕上显示,而是写到另一个文件中去,这种功能称为 A.脱机输出 B.管道 c联机输出 D.输出重定向3.能把第一条命令的输出作为第二条命令的输入的功能是由( )机制实现的。
A链接 B.批处理 c.管道 D.输出重定向4.由父进程执行系统调用fork创建一个子进程,那个子进程的初始状态为( )。
A.创建状态 B.睡眠状态 c.就绪状态 D.僵死状态5.UNIX System v系统中,存储管理主要采用( )。
A.对换技术 B.页式虚拟存储 c段式存储管理 D段页式虚拟存储6.UNIX系统中在磁盘上开辟对换区作为内存的逻辑扩大,在治理对换空间时采纳了( )。
A.空闲区表 B.位示图 c.块表 D.映射图7.特别文件是指与( )有关的文件。
A.文本 B.图像 c.外围设备 D二进制代码8 UNIX对磁盘中索引节点区进展治理时,把索引节点区空闲块的块号放至( )。
A.引导块 B.超级块 c.索引节点区 D.文件存储区9 UNIX系统中把设备也当作文件对待,所有设备文件都放在( )目录中。
A./bin B./lib C./dev d./usr10.在块设备管理时,由( )为设备驱动程序提供信息. A空闲缓冲区队列 B.设备缓冲区队列 c.设备开关表 D.设备I/O请求队列(二)填空题1.UNIX是一个交互式的______操作系统,采用以全局变量为中心的______构造。
2.UNIX的系统构造可分成______和______两局部。
3.内核层是UNIX系统的核心,它实现存储治理、______ 、设备治理和______等功能,并为外壳层提供系统挪用。
4 外壳层由______、高级语言的编译和说明程序、______和系统库组成。
(完整word版)操作系统英文版课后习题答案整理(word文档良心出品)

1.1What are the three main purposes of an operat ing system?⑴ In terface betwee n the hardware and user;(2) man age the resource of hardware and software;(3) abstracti on of resource;Answer;•Tb provide an environment ksr a computer user to execute programs on computer h日rchvare in n convenient and efficient manner.•Tb allocate the separate resources of the computer as needed to st)ke the problem given.The allcxation prtxzess should b? as fair and efficient as possible.•Asa control program it serves two major functions; (1) supervision of the execution 由user programs to prevent errors and improper use of the computer, and (2) management of the operatioji and control of I/O devices.1.2 List the four steps that are necessary to run a program on a completely dedicated machine. Preprocessing > Process ing > Linking > Executi ng.Answer:乩Reserxe machine time*b* Manually load program into memory.u Load starting address and begin exe匚Lition.cL Monitor and control execution of program fr(im console.b. In teractivec. Time shar ingd. Real timee. Networkf. DistributedAnswera” Batch, Jobs w计h similar reeds are batched together and run through the computer as a group by ^r\operator or automatic jc)b s^quenc^r. [^rformanct? i$ incr^a^ed by atteiTipting to keep CPU 3nd I/O devices busv 311 timesi through buffering, off-line operation^ spooling, and multiprogramming. Batch is good for executing 】arge jobs thjit need little interacticm; it can be submitted and piuked up later.b. Interactive. This system is cumpofied of m^nv short transactions where the results of thenext transactiiin may be unpredictablen Respond time needs tn be short (sectwids) since the user submits and waik for the result.u Time sharing. This systems u 船呂匚Pl sch<*duling ^nd multi programming to pmvidu eConoiniCcil interactive use of 蛊system. The CPL switches rapidly iri>m one user tn another Instead of having a job defined by spcxiled card images^ each program readsits next control card from the terminab and output is normally printed immediately to the screen.(_L Real time. Often tisvci in a dedicated application, this system reads information from sensors and must respond within a fixed amount of time to ensure correct performance.work.f.Distributed .This system distributes computation among several physical processors” TheprtKessors do not share menion- or a clock. Instead, each pnxzessor has its own kxzalmemory. They communicate with each other through various communication lines f such asa high-speed bus or telephone line.1.7 Wehave stressed the need for an operating system to make efficient use of the computing hardware. When is it appropriate for the operating system to forsake this principle and to waste ” resources? Why is such a system not really wasteful?Answer Single-user systems should maximize use of the system for the user A GUImight "xvastc * GPL' cycles, but it optimizes the user T s interaction with the system.2.2 How does the distinction between monitor mode and user mode function as a rudimentary form of protecti on (security) system?Answer: By establishing a set of privileged instructions that can be executed only when in tlie m(snitnr mt)de f the tiperating system is assured of controlling the entire system at all times.2.3 What are the differences between a trap and an interrupt? What is the use of eachfun cti on?Answer An interrupt is a ha rd \ v a re-^en era ted change-of-flow within the system. An interrupt handler is summoried to deal with the cause oF the interrupt; control is then re turned to the interrupted context and instruction. A trap is a software-j;enerated interrupt. An interrupt can be uwd to signal the compJrtio n “f an I/O obviate the nevd for polling. A trap can be used ti> call operating svstem routines or to catch arithmetic errors.2.5 Which of the follow ing in structi ons should be privileged?a. Set value of timer.b. Read the clock.c. Clear memory.d. Turn off interrupts.e. Switch from user to monitor mode.3OS Exercise BookClass No. NameAnswer: The following instructions should be privileged:Set value of timer,b.Clear memory.Jc.Turn off interrupts.d.Switch from user to monitor mode*2.8 Protecting the operating system is crucial to ensuring that the computer system operates correctly. Provision of this protection is the reason behind dual-mode operation, memory protection, and the timer. To allow maximum flexibility, however, we would also like to place mini mal con stra ints on the user.The following is a list of operations that are normally protected. What is the minimal setof in structi ons that must be protected?a. Change to user mode.b. Change to mon itor mode.c. Read from mon itor memory.d. Write into mon itor memory.e. Fetch an instruction from monitor memory.f. Tur n on timer in terrupt.g. Turn off timer interrupt.Answer: The minimal 5et of instructions that must be protected are:a.Change to monitor mtxle.b.Read from moni tor memory*c.Write into monitor me mor v.Jd.Turn off timer interrupt3.6 List five services provided by an operat ing system. Explain how each provides convenience to the users. Explain also in which cases it would be impossible for user-level programs to provide these services.Answer;«Program execution. The operating system loads thv contents (or sections) of a file into menidry and begins its execution. A user-level program could not be trusted to properly allocate CPU time.•I/O operations. Disks, tapes, serial lines;and other devices must be communicated with ata very low level. The user need only specify the dev ice and the operation to perform (in it,while the system converts that request into <ie\r ict^ or contr<i11er-spec i fit commands.User-level pnjgrams cannot be trusted to only access devices they should have access to and to only access them when they otherwise unused.«File-system manipulation, fhere are manv details in file creation, deletion/ alkKation, and naming that users should not have to perform. Blocks of disk space are used by files and must be tracked, deleting a file requires remo\ ing the name file information and freeing the <ilkx:ated blocky I^ratections must also be checked to assure proper file access. User prc^grams could neither ensure adherence to protect]on methcxis nor be trusted to allocate only free block吕and deallocate bkxzks on file deletion.J•Communications. Message passing between systems requires messages be turned into packets of information, sent to the network controller, trannmitted across a community tk>ns medium, and reassembled by the destination system.卩acket ordering and data correction must take place. Again, user program吕might not c(sordinate ac cess to the network dev ice, or they might receive packets destined tor other processes^»Error detection. Error detection (occurs at both the hardware and soFtwart? levels. At tlie hardware level, all data transfers must be inspected to ensure that data hax e not beencorrupted in transit All data on media must be checked to be sure they have not changed since they uritten to the media. At the software level, media must bechecked for data ccnsistencj^; for instance, do the number of allocated and unallocated blocks of storage match the total number on the device. There, errors are frequently pnxzess-independent (for instance, the 匚omiption of data on a disk)5 sc there must be a global program (the operating system) that handles all h pes of errors. Also, by having errors pmc essed by the operating system, processes need not contain code to catch and ccjrrect all the ernjrs possible on a system.3.7 What is the purpose of system calls?Answer; Sv>ttn'. dlltnv ustr-levtl lu request str\ ices nt 11 it? uperating svs-tem.3.10 What is the purpose of system programs?J V USWCE Svstcm programs can be thought of as bundle!ti of useful system oils. Thev r provide bcisic functidcaliU users and sci users do not need to wnte their cwn programs to s<>k r e comnicMi problems,4.1 MS-DOS provided no means of con curre nt process ing. Discuss three major complicati onsthat con curre nt process ing adds to an operat ing system.5OS Exercise BookClass No. NameAnswer:*A method of time sharing must be implemented to allow each of several prcxzesses to have access to the system. This method involves the preemption of processes that do notvoluntarily give up the CPU (by using a system ca1]r for instance) and the kernel being reentrant (so more than one prtxzess may be executing kernel code concurrently).・[Vocesses and system resources must have protections and must be protected from each other. Any given process must be limited in the amount of memory it can use and tlie ope Mt ions 让can perform on devices like di^ks.•Care must be taken in the kernel to prevent deadkxzks between prucesses, so processesaren*t waiting for each other's allocated rest>urces,4.6 The correct producer —consumer algorithm in Section 4.4 allows only n-1 buffers to befull at any one time. Modify the algorithm to allow all buffers to be utilized fully.Answer: No answer.5.1 Provide two program ming examples of multithread ing givi ng improve performa nee overa sin gle-threaded soluti on.Answer (1) A Web server that services each request in a separate Lliread. (2) A parallelized application such as matrix multiplication where different parts of the matrix may be worked on in parallel. (3) An intEivictin GUI program such as a debugger where a thread is used to monitor user input, another thread represents the running application, and a third thread monitors performance.5.3 What are two differences between user-level threads and kernel-level threads? Underwhat circumsta nces is one type better tha n the other?Answer: Context switching between user threads is quite sinniliir to switching between kernel threads, although it is dependent on the threads library and how it maps user threads to kernel threads. In general, context switching between user threads involves taking a user thread of its LWP and replacing it with another thread. This act typically involves saving and restoring the stttte of the registers.6.3 Consider the following set of processes, with the length of the CPU-burst time given inmillisec on ds:Process Burst Time PriorityP1103P211P323F414P552The processes are assumed to have arrived in the order P l, F2, F3, F4, P5, all at time 0.a.Draw four Gantt charts illustrati ng the executi on of these processes using FCFS, SJF, a non preemptive priority (a smaller priority n umber implies a higher priority), and RR (qua ntum = 1) scheduli ng.b.What is the turnaround time of each process for each of the scheduling algorithms in part a?c.What is the waiting time of each process for each of the scheduling algorithms in part a?d.Which of the schedules in part a results in the minimal average waiting time (over all processes)?An swer:Answer;a.The four Gantt charts areb.Turnaround timeFCFS RR SJF Priority101919 16112 1 113 741814421919149 6 匚Waiting time (turnaround time minus burst time)FCFS RR SJF Priority卩】0996Pz10100心115216P*133118Ps14941d. Shortest Job First6.4 Suppose that the following processes arrive for execution at the times indicated. Eachprocess will run the listed amou nt of time. In an sweri ng the questi ons, use non preemptive scheduling and base all decisions on the information you have at the time the decisionmust be made.PtXKCSS Ai ri\ al Time Burst Time0.087OS Exercise BookClass No. NameP20.44l.D1a. What is the average turnaround time for these processes with the FCFS scheduling algorithm?b. What is the average turnaround time for these processes with the SJF scheduling algorithm?c. The SJF algorithm is supposed to improve performa nee, but no tice that we chose to run process P1 at time0 because we did not know that two shorter processes would arrive soon. Compute what the average turnaround time will be if the CPU is leftidle for the first 1 un it and the n SJF scheduli ng is used. Remember that processes P1 and P2 are wait ing dur ing this idle time, so their wait ing time may in crease. Thisalgorithm could be known as future-k no wledge scheduli ng.Answera.10.53b.9.53c.6,86Remember that turnaround time LS finishing time minus arrival time, so have to subtract the arrival tinier to compute thu turnaround times. FCFS is 11 if you forget to subtract arrival time.6.10 Explain the differences in the degree to which the following scheduling algorithms discrim in ate in favor of short processes:a.FCFSb.RRc.Multilevel feedback queuesAnswer:a.FCFS—discriminates against short jobs since any short jobs arriving after long jobs willhave a longer waiting time.b.RR一treats all jobs equally (giving them equal bursts of CPU time) so short jobs will beable to leave the system faster since they will finish first.c.Multilevel feedback queues—work similar to the RR algorithm—thev discriminatefa^r i>rably toward slusrt jobs.7.7 Show that, if the wait and sig nal operati ons are not executed atomically,then mutual exclusi on may be violated.Answer No answer.7.8 The Sleepi ng-Barber Problem. A barbershop con sists of a wait ing room with n chairs and the barber room containing the barber chair. If there are no customers to be served,the barber goes to sleep. If a customer en ters the barbershop and all chairs are occupied,then the customer leaves the shop .If the barber is busy but chairs are available, the nthe customer sits in one of the free chairs. If the barber is asleep, the customer wakes up the barber. Write a program to coord in ate the barber and the customers.Answer: Please refer to the support ing Web s its for source code solution,8.2 Is it possible to have a deadlock involving only one single process? Explain your answer.Answer Ncx I'his folknvs directly from the hold-and-wait condition.8.4 Con sider the traffic deadlock depicted in Figure 8.11.a. Show that the four n ecessary con diti ons for deadlock in deed hold in this example.b. State a simple rule that will avoid deadlocks in this system.Answer No answer.8.13 Con sider the follow ing sn apshot of a system:Allocati on Max AvailableA B C D A B C D A B C DP00 0 1 20 0 1 2 1 5 2 0P1 1 0 0 0 1 7 5 0P2 1 3 5 4 2 3 5 6P30 6 3 20 6 5 2P40 0 1 40 6 5 6An swer the follow ing questi ons using th e ban ker s algorithm:a.What is the content of the matrix Need?b.Is the system in a safe state?c.If a request from process P1 arrives for (0,4,2,0), can the request be gran tedimmediately?Answer;A. Deadlcx^k cannot ixrcur because preemption exists,b. Yes. A process may never acquire all the resources 让needs if they are continuouslypreempted by a series of requests such as those of process C.9.5 Given memory partitions of 100K, 500K, 200K, 300K, and 600K (in order), how would each of the First-fit, Best-fit, and Worst-fit algorithms place processes of 212K, 417K, 112K,and 426K (in order)? Which algorithm makes the most efficie nt use of memory?Answer:a. First-fit:b* 212K is put in 500K partitionc. 417K is put in 600K partitiond* 112K is put in 288K partition (new partition 288K = 500K - 212K)e.426K must waitf.Best-fit:g.212K is put in 300K partition9OS Exercise BookClass No. Nameh.417K is put in 500K partitioni.112K is put in 200K partitionj.426K is put in 600K partitionk.Worst-fit:L 212K is put in 600K partitionm. 417K is put in 500K partitionn. 112K is put in 388K partitionc 426K must waitIn this example, Best-fit turns out to be the bE%t*9.8 Con sider a logical address space of eight pages of 1024 words each, mapped onto a physicalmemory of 32 frames.a. How many bits are there in the logical address?b. How many bits are there in the physical address?Answera,l.ogica) address: 13 bitsb.Physical address: 15 bitsJ9.16 Con sider the follow ing segme nt table:Segme nt Base Len gth02196001230014290100313275804195296What are the physical addresses for the follow ing logical addresses?a. 0,430b. 1,10c. 2,500d. 3,400e. 4,112Answer:a.219 + 430 = 649b.2300 + 10 = 2510u ill亡月ed reference, trap ki operating systemd.1327 -b 400 = 1727e.illegal reference, trap to operating system10.2 Assume that you have a page referenee string for a process with m frames (initiallyall empty). The page refere nee stri ng has len gth p with n disti net page n umbers occur init. For any page-replacement algorithms,a. What is a lower bou nd on the n umber of page faults?b. What is an upper bou nd on the n umber of page faults?Answer:a* nb»p1, 2, 3, 4, 2, 1,5, 6, 2, 1,2, 3, 7, 6, 3, 2, 1, 2, 3, 6.How many page faults would occur for the following replacement algorithms, assuming one, two, three, four, five, six, or seven frames? Remember all frames are initially empty, so your first unique pages will all cost one fault each.LRU replaceme ntFIFO replaceme ntOptimal replaceme nt11OS Exercise BookClassNo.NameNumbei of frames1 2 3 4 5 6 711.7 Expla in the purpose of the ope n and close operati ons.Answer :» The o[fen operation informs the system that the named file is about to bect>me active^ * Tlie cluse operation informs the system that the named file )s nt> lunger in active use by the user who issued the dose operation.11.9 Give an example of an application in which data in a file should be accessed in the followi ng order: a. Seque ntially b. Ran domlyAnswer :a. Print the 匚 on tent of the file,b. Print the content of record /. This record can be found using hashing or index tech niques.11.12 Con sider a system that supports 5000 users. Suppose that you want to allow 4990 of these users to be able to access one file.a. How would you specify this protection scheme in UNIX?b. Could you suggest ano ther protecti on scheme that can be used more effectively for this purpose tha n the scheme provided by UNIX?Answer:a. There are twc methods for achieving this : L Create an access control list withtlu? names of all 4990 users.ii. Put these 4990 users in one ^roup and set the group access accordingly. This scheme cannot always be implemented since user groups are restricted by the system. b. The universe access information applies to all users unless their name appears in the access-control list with different access permission. With this scheme you simply put the names of the remaining ten users in the access control list but \v 让h no access pri\ ileges allovcexfLRUFIFOOptimal 20 20 20 18 18 15 15 16 11 10 14 8 8 10 7 7 10 7 7 77Answer12.1 Consider a file currently consisting of 100 blocks. Assume that the file control block (andthe index block, in the case of indexed allocation) is already in memory. Calculate howmany disk I/O operations are required for contiguous, linked, and indexed (single-level)allocati on strategies, if, for one block, the follow ing con diti ons hold. In thecon tiguousallocati on case, assume that there is no room to grow in the beg inning, but there is room to grow in the end. Assume that the block in formatio n to be added is stored in memory.a. The block is added at the beg inning.b. The block is added in the middle.c. The block is added at the end.d. The block is removed from the begi nning.e. The block is removed from the middle.f. The block is removed from the end.AnswerLinked Indexeda. 201 1 1b. 1015211 3 1d. 198 1 0e. 9852 0f. 0 100 013.2 Con sider the follow ing I/O sce narios on a sin gle-user PC.a. A mouse used with a graphical user in terfaceb. A tape drive on a multitasking operating system (assume no device preallocation is available)c. A disk drive containing user filesd. A graphics card with direct bus conn ecti on, accessible through memory-mappedI/OFor each of these I/O scenarios, would you design the operating system to use buffering, spooli ng, cachi ng, or a comb in ati on? Would you use polled I/O, or in terrupt-drive n I/O? Give reas ons for your choices.Answer:a. A mouse used with a graphical user interfaceBuffering may be needed to record mouse movement during times when higher- priority operations are taking place. Spooling and caching are inappropriate. Inter rupt driven I/O is most appropriate^b” A tape drive on a multitasking operating system (assume no device preAlkxzation is available)Buffering may be needed to manage throughput d让ferEria? behveen the tape drive and the sounzt? or destination of the I/O, C臼匚hing can be used to hold copies of that resides on the tape, for faster access. Spooling could be used to stage data to the device whenmultiple users desire to read from or write to it” Interrupt driven [/O is likely to allow the best performance.13OS Exercise BookClass No. Name匸* A disk drive containing user tilesBuffering can be used to hold data while in transit from user space to the disk, and visaversa. Caching can be used to hold disk-resident data for improved perfor mance.Spoc^ling is not necessary because disks are shared-access devices. Interrupt- driven T/O is best for devices such as disks that transfer data at slow rates,d. A graphics card w让h direct bus coi^nection, accessible through mem<irv-mapped I/OBuffering may be needed to control multiple access and for performance (doublebuffering can be used to hold the next screen image while displaying the current tme). Caching and spooling are not necessary r due to the fast and shared-access natures of the device. Polling and interrupts are only useful for input and for【/O completion detec tion f neither of which is needed for a mem()r y-ma pped device.14.2 Suppose that a disk drive has 5000 cylinders, numbered 0 to 4999. The drive is currently serving a request at cylinder 143, and the previous request was at cylinder 125. The queue of pending requests, in FIFO order, is86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130Start ing from the curre nt head positi on, what is the total dista nee (in cyli nders) thatthe disk arm moves to satisfy all the pending requests, for each of the follow ingdiskscheduli ngalgorithms?a. FCFSb. SSTFc. SCANd. LOOKe. C-SCANAnswer:乩The FCFS schedule is 143f 86f 1470, 913, 1774, 948, 1509, 1022, 1754), 130. The total seek distance is 7081.b. The SSTF schedule is 143, 130, 86. 913, 948, 1022, 1470, 1509. 1750r 1774. The total seekdistance is 1745.€. The SCAN schedule is 143, 913, 94«f1022f 1470, 1509,1750f 1774, 4999,130, 86. The to怙1 seek distance is 9769.d.The LOOK schedule is 143, 913, 948,1022, 1470,1509,1750,177< 130,86. The total seekdistance is 3319*e.The C-SCAN schedule is 143f 913,948,1022J 470,1509.1750,1774,4999,8& 130. The totalseek distance is 9813.f.(Bonus.) The C-LOOK schedule is 143,913,94& 1022,1470,1509.1750,1774, 86,130. Thetotal seek distance is 3363.1.1 1.62.3 2.53.7 6.3 6。
Unix部分习题解答.doc

12章习题1.答:美国AT&T贝尔实验室的研究员Ken Thompson等科学家。
2.答:Linux的诞生可以追溯到1990年秋天,它是以一种特殊的方式诞生的,然后在互联网上发展和不断壮大起來。
芬兰赫尔辛基大学(University of Helsinki)的学牛.LinusTorvald借鉴Andrew Tanenbaum教授开发的用于教学冃的的Minux操作系统,将之移植到PC机上,开发111一种运行在PC机上的Unix,称其为Linuxo Linux遵守IEEE POSIX」标准,因此属于类Unix操作系统。
3.什么是GNU项目?什么是GPL协议?答:GNU项目是FSF支持下的一个项目,支持了许多可以在Unix系统上运行的工具软件的开发,如Emacs编辑器、gcc编译器、bash 命令解释器、gawk等,为Linux的发展提供了强大的推动力。
GPL是通用许可协议,在遵守该协议的条件下,允许商业软件公司利用发布基于源代码软件Z上的自己的软件而获利,是开源软件的发展步入良性循环的轨道。
Linux以及该平台上的开源软件都接受该协议。
4.答:参见12.2节,因叙述明确详细,在此不再赘述。
5.答:一般的数据、各种应用程序创建的文档、以及程序均以文件的形式出现在文件系统中,存储在磁盘上。
Unix采用树形的多级目录结构来组织磁盘上的文件,整个文件系统就好像是一棵树,树中的节点就是目录和文件。
6.答:绝对路径法每次指明一个位置的时候,起始点都是根目录,然后指明子目录, 以及子目录的子目录,直至目标位置。
例子略。
相对路径法以文件系统中某个位置A为起始位置,利用和等具有特殊意义的位置指示符,指名相对于起始位置A的相对位置B的方法。
例子略。
13章习题1.答:Unix/Linux操作系统的主要人机界面就是Shell程序,它是一个命令解释程序,接收用户发送的命令,进行必耍的检查之后,启动相应的程序完成任务。
电子科技大学14秋《unix操作系统》在线作业1答案

14秋《unix操作系统》在线作业1
一,单选题
1. UNIX系统中显示指定年份日历表的命令是()。
A. last
B. date
C. cat
D. cal
?
正确答案:D
2. UNIX系统对初学者和健忘者提供的帮助有()。
A. or
B. 使用电子手册,即manu命令
C. man/help/info/learn
D. 各种命令及其UNIX在线手册
?
正确答案:C
3. 在UNIX下,进程是一个程序或者任务的()。
A. 编号
B. 执行进度
C. 完成情况
D. 执行过程
?
正确答案:D
4. 当用户退出系统时,()程序终止执行,UNIX系统在终端上启动一个新的getty程序并等待新的用户登录。
A. shell
B. 内核
C. init
D. LILO or GRUB
?
正确答案:A
5. 在UNIX操作系统下,对命令的使用可以是()。
A. 不区分大小写字母
B. 只能识别小写字母
C. 要区分小写或大写字母
D. 只能是大写字母
?
正确答案:B。
《unix操作系统》练习题库参考答案
华中师范大学网络教育学院《UNIX操作系统》练习测试题库参考答案一、单选题1.B2.B3.C4.A5.D6.C7.B8.B9.B10.A11.D12.C13.B14.A15.D16.C17.C18.C19.D20.C21.C22.C23.D24.B25.B26.C27.B28.B29.A30.D31.A32.D33.B34.B35.B36.B37.B38.A39.C40.B二、填空1.learn;help;man2.dd3.lpstat4.unset5.tee6.就绪7.$vi –R f18.crypt9.Shell;内核10.mesg n11.客户/服务器;简易性;无连接性;可靠性12.程序段;数据段;PCB;PCB;程序段13.语言库;系统调用接口层14.$vi f1 f2 f315.umount16.将它后面所带的消息参数显示在显示器上17.Shell命令;流程控制语句18.发送;接收19..Z20.进行命令或脚本查找的目录顺序21.#22.tput23.完全备份;增量备份24.创建原语25.命令名;选项;参数26.<;<<27.定制安装28.GRUB;LILO29.内建模式30.useradd; /etc/passwd; /etc /shadow31.执行;就绪;阻塞32.硬链接;符号(或软)链接33.?shutdown; /shutdown34.mkdir –p XX/ZZ35.routed;routed三、名词解释1.信号量是一种只能进行P操作和V操作的特殊变量。
它是一个确定的二元组(s、q),其中s是一个具有非负初值的整型变量,q是一个初始状态为空的队列。
整型变量s表示系统中某类资源的数目,当其值大于0时,表示系统中当前可用资源的数目;当其值小于0时,其绝对值表示系统中因请求该类资源而被阻塞的进程数目。
除信号量的初值外,信号量的值仅能由P操作和V操作改变,操作系统利用它的状态对进程和资源进行管理。
unix系统设计报告及答案
《UNIX_Linux操作系统内核结构》课程报告1、如果几个进程竞争一个缓冲区,内核保证没有一个进程会永远睡眠等待,但并不保证不会出现一个进程一直等待得不到缓冲区的情况发生。
请重新设计算法getblk 以保证一个进程最终能用上一个缓冲区。
答:getblk 算法输入:文件系统号块号输出:现在能被磁盘块使用的上了锁的缓冲区{While (没找到缓冲区){If (块不在散列队列中){If (空闲表上无缓冲区){Sleep (等候“任何缓冲区变为空闲”事件);Continue;}}}}2、在通常的目录结构中,对目录项的搜索都是线性的。
请设计一种新的目录结构,其中各目录项是按其hash 值以某种方式排列的,对其中目录项的搜索也是按其hash值来查找的。
答:3、一个进程可以用“追加写(APPEND)”方式打开一个文件,这表明每次写操作都是从标识当前文件尾的字节偏移量处开始。
如果一个进程以“追加写”方式打开一个文件,并定位于文件头,会发生什么呢?答:4、设计一个系统调用,该系统调用将一个已存在的文件截为任意给定的大小,并说明实现方法。
答:5、UNIX系统V允许一个路径名分量最长达14个字符。
namei算法把一个路径名分量中多余的字节截掉。
假设保持定长目录项的目录结构,应该怎样设计目录结构和namei算法,才能允许任意长度的目录项名称?答:更改文件系统中SFD中文件名的长度以及加大namei中目录变量的字节即可。
首先,namei 判定搜索路径名是从根目录开始的绝对路径名,还是从当前目录开始的相对路径名。
如果是绝对路径名,则将根目录置为目录变量,否则将当前目录置为目录变量。
其次,namei以目录变量为依据,搜索到该目录变量所对应的内存i节点,并验证存取许可权。
如果该目录文件是可以存取的,则依次将该目录变量所对应的目录文件块读入内存,并且顺序搜索与路径名中目录变量的下一个分量相匹配的文件名。
如果未找到相应的分量,则表明文件系统中不存在相应的文件或路径名有错。
操作系统英文版课后习题答案整理word文档良心出品
l.lWhat are the three main purpo ses of an op erat ing system? ⑴ In terface betwee n the hardware and user; (2) man age the resource of hardware and software; (3) abstracti on of resource;Answer:• To provide an environment k>r a computer user to< execute programs on computtr hardware in a ccnvenient and efficient manner• Tb 吕 lk>cat 特 the 艺t?parattz resources of the compuler as nteded to strive the prtjblem given* The allocation p TOCESS should be as fair and efficient as possible.• Asa ct>ntroJ p a>gram it serves two major functions : (1) sup ervision of the execution of user programs to p re vent errors and improper use of the computer, and (2) manage ment of the «p erat it) JI and control of [/O devices.1.2 List the four steps that are necessary to run a program on a completely dedicated machine. Prep rocess ing > Process ing > Linking > Executi ng.Answer乩 Reserve machine time*b. Manually load program into memory.c. Load starting address and begin execution.d.Monitor and control execution of program fnim ct>nsoie.1.6 Define the esse ntial prop erties of the follow ing types of op erat ing systems: a. Batch b. In teractive c. Time shari ng d. Real time e. Network f. DistributedAnswerBatch. Jobs with similar needs are batched together and run through the computer as a grcup by anoperator or automatic job st^quencer.[咆jrformHrk :电 is increased by atteiTipting to keep CPU andI/O devices busv 試 all times throughoff-lineoperation, Kptx?ling, and multiprogramming* Batch is good for executing large jobs that netxlinteraction; it can be siubmilted and picked up laterInteractive. Thkin J of many short transactiorifd where the results ofthe next transaction may be unpredictable. Response rirne needs to be short (seconds] since the user submils and w^iih For the result.Time sharing. This systems u&es 匚n scheduling and mLiltiprt)gramming toprtividt* economical interactive of a system. The CP 匚 占w 让 chem rap idly fn>nn one user to another Instead of havinga job defined by spooled card images^ each program re^dsa” b. c.its next control card from the terminal, and output is normally printed immediately to the screen. Real time. Often usvd in a dedicated application, tliis system reads information fram sensors and mustrespond within a fixed amount of time to ensure correct performance- Network.Distributed .This system distributes computation arntmg se¥t?ral physical prtxzesKors, Theprt>cesst>rs do not share memory or a cltKk. Instead, each prixessor has its t>wn kxzal memory. They communicate with each other through various communicatitm lines, such as a high-speed bus or telephone line.1.7 hardware. When is it approp riate for the op erat ing system to forsake this principle and to waste " resources? Why is such a system not really wasteful?Answer Single*user systems shtiuId maximize use of the systenn for the user. A GUI might “waste" CPU cy<les, but it optimizes the user's interaction with the system.2.2 How does the distinction between monitor mode and user mode function as a rudimentary form of p rotecti on (security) system?亠 ■ ■Answer; By establishing a set of privileged instructions that can be executed only when in the mt>niu)r mode, the operating system is assured of ct^ntrolling the entire system at all times.2.3 What are the differe nces betwee n a tra p and an in terru pt? What is the use of each fun cti on?Answer An interrupt is a ha rd w a re-genera ted change-of-flow within the system. An interrupt handler is summoned to deal with the c<iuse oF the interrupt; control is then re*turned to the interrupted context and instruction. A trap is a sof t wa re-genera ted in terru p 匕 An interrupt can bv usvd to signal the coiTipJctk*n of an [/O to obviate the need fnr du\ icy poiling. A trap can be used to call operating system routines or to catch arithmetic errors.2.5 Which of the follow ing in structi ons should be p rivileged? a. Set value of timer. b. Read the clock. c. Clear memory.d. Turn off i nterru pts.e. Switch from user to mon itor mode.d. Wehave stressed the n eed for an op erat ing system to make efficie ntuse of the comp ut ing3OS Exercise BookClass No. NameAnswer: The following instructions should be privileged: a. Set value of timer. b. Clear memory. c. Turn off interruptacL Switch from user to monitor mode.2.8 Protect ing the op erati ng system is crucial to en suri ng that the comp uter system op erates correctly. P rovisi on of this p rotecti on is the reas on beh ind dual-mode op erati on, memory pr otecti on, and the timer. To allow maximum flexibility, however, we would also like to p lace mini mal con stra ints on the user. The followi ngis a list of op erati ons thatof in structi ons that must be p rotected? a. Change to user mode. b. Change to mon itor mode. c. Read from mon itor memory. d. Write into mon itor memory.e. Fetch an in structi on from mon itor memory.f. Tur n on timer in terru pt.g. Turn off timer in terru pt.Answen The minimal set of instructions that must be protected are:Read from monitor memory* Write into monitor me mor v.*Turn off timer interrupt.3.6 List five services p rovided by an op erat ing system. Exp lain how each p rovides convenience to the users. Explainalso in which cases it would be impossible for user-levelpr ograms to p rovide these services.Answer:are no rmally p rotected.What is the minimal seta. Change to monitor mod 匕b. c.Program execution. The operating system loads the contents (or sections) of a file into memory and begins its execution. A user-level pm呂ram could not be trusted to properly allocate CPU time.I/O' op e rat ions. Disks, tapes, serial lines^ and other devices must be communicated with at a \ ery low level. The user need only specify the device and the operation to perform on it, while the system converts that request into device- or controller-specific commands. User-level programs cannot be trusted to only access devices they should have access to nnd to only access them when they art otherwise unused.File-system manipulation. There arv many details in file creation, deletion, alkKation, and naming that users should not have to perform. Blocks of disk spact? are used by files and must be tracked.Deleting a file requires removing the name file information and freeing the 说[located bk>cks.[Protections must also be checked to assure prtiper file access. User prt^grams could neither ensure adherence tct protection methexJs nor be trusted to allocate only free blocks and deallocate blocks on file deletion.Communications. Message passing between systems requires messages be turned into packets of information, sent to the network contnUlei; transmitted across a communications medium, and reassembled by the destination system. Packet ordering and data correction must take place. Again, user programs might not coordinate access to the network device, or they might reevi^T packets destined for other processes. • Error detection. Error detection occurs at both the hardware and sofirware levels. At the hardware le\-el, all data transfers must be inspected to ensure that data have not been c(>rrupted in transit AU data on media must bi checked to be sure they have not changed since they were written to the media. At the software level, media must be checked for data consistency;for instance, do the number of allt>cated and unallocated blocks of storage match the total number on the device. There, errors are frequently prexzess-independent (for instance, the corruption of data on a disk), so there must be a global program (ttiE op erating system) that handles all type 吕 of errors. Also, by having errors processed by the operating system, p rocesses need not contain code to catch and correct all thE errors possible on a syst Em.3.7What is the purpose of system calls?Answer System ualls(J1U>W user-lewl lii request ices uf tl咤uperdting sv;»-tem.3.10 What is the purpose of system programs?jVnswcr: Evstem p rograms can be thought of bundlcz^ uf useful systctu oils. Tbevprovide basic functicrahty to users and so users de not need to write their own programs to sol、忙common problems.4.1MS-DOS pr ovided no means of con curre nt pr ocess ing. Discuss three major comp licati ons that con curre nt p rocess ing adds to an op erat ing system.5OS Exercise BookClass No. NameAnswer:A method of time sharing must be implemented to allow each of several processes to have access to the systen'i. This method inxoJvcs the prompt ion of processes that do not voluntarily giA-e up the CPU (by using A system cal], for instance) <ind the kernel being reentrant (so more than one prtxzess may be executing kernel code concurrently).Processes and system resources must hav E protections and must be prciteck?d frtiTn each other Any given process must be limited in the amount of memory it can use and the operations it can perform on devices like disks.Care must be taken in the kernel to pre\ ent deadkxzks between processe 鬲 so prcicesses aren't waiting for each other's allcxated rest>urces.4.6full at any one time. Modify the algorithm to allow all buffers to be utilized fully.Answer No answer.5.1 P rovide two p rogram ming exa mp les of multithread ing givi ng imp rove p erforma nee over a sin gle-threaded soluti on.Answer (1) A server that services each request in a sep a rate thread. (2) A paral* lelized application such as matrix multi plication where different p arts of the matrix may be worked on in parallel. (3) An interactive GUI program such as a dibugger where a thread is used to monitor user input, another thread represents the running flppHcation, and a third thread monitors performance.5.3 What are two differences between user-level threads and kernel-level threads? Under what circumsta nces is one type better tha n the other?r■Answer Context switching between user tlireads is quite similar tG switching between kernel threads, although it is dependent on the threads library and how it maps user threads to kernel threads. In general, context switching between user threads involves taking a user thread of its LWP and replacing it with another thread. This act typically involves saving and restoring the st^te of the registers.6.3 Con sider the follow ing set of p rocesses, with the len gth of the CPU-burst time give n in millisec on ds: P rocessP1 P2 P3 F4 P5The p rocessesare assumed to have arrived in the orderThe correct p roducer— con sumer algorithm in Secti on 4.4 allows only n-1 buffers to beBurst 10 1 2 1 5Time P riority 3 1 3 4 2P1, P2, P3, P4, P5, all at time 0.a.Draw four Gantt charts illustrati ng the executi on of these p rocesses using FCFS, SJF, a nonpreemp tive p riority (a smaller p riority n umber imp lies a higher p riority), and RR (qua ntum = 1) scheduli ng.b.What is the tur narou nd time of each pr ocess for each of the scheduli ng algorithms in part a?c.What is the wait ing time of each p rocess for each of the scheduli ng algorithms in p art a?d.Which of the schedules in p art a results in the mini mal average wait ing time (over all pr ocesses)?An swer:AnswerThe four Gantt charts area.b- Turnaround timeFCFS円101113卩414 卩519RR■19274SJF191 ^riority18196Waiting time (turnaround time minus burst time)FCFS RR卩210Ih11卩413卩514 SJF214Prit^ritv•J61618d. Shortest Job First6.4 Suppose that the followingpr ocess will run the listed amou nt of time. In an sweri ng the questi ons, use nonpreemp tivescheduli ng and base all decisi ons on the in formati on you have at the time the decisi onp rocesses arrive for execution at the times in dicated. Each70.110.4a. What is the average tur narou nd time for these p rocesses with the FCFS scheduli ng algorithm?b. What is the average turnaround time for these processes with the SJF scheduling algorithm?c. The SJF algorithm is supp osed to impr ove p erforma nee, but no tice that we chose to run p rocessP1 at time 0 because we did not know that two shorter p rocesses wouldarrive soon. Comp ute what the average turn arou nd time will be if the CPU is left idle for the first 1 un it and the n SJF scheduli ng is used. Remember that p rocesses and P2 are wait ing duri ng this idle time, so their wait ing time may in crease. This algorithm could be known as future-k no wledge scheduli ng.Answer; a. 10,53b. 9.53c. 6.86Remember that turnaround time LS finishing time minus arrival time^ so you have h) subtract the arrival times to compute the turnaround times. F 匚FS is 11 if yw forget subtract arrival time.6.10 Explain the differe nces in the degree to which the follow ing scheduli ng algorithms discrim in ate in favor of short p rocesses: a. FCFS b. RRc. Multilevel feedback queuesAnswen孔 FCFS —discriminates against sliort jobs since any short jobs arriving after long jobs will have a kmger waiting time.b. RR 一treats all jobs equally (giving them eqiiaL bursts of CPU time) so short Qbm will be able toleave the system faster since they will finish first.c. Multilevel feedback queues —work similar to the RR algorithm —they discriminate favorably towardshort jt>bs.7.7 Show that, if the wait and sig nal op erati ons are not executed atomically, then mutual exclusi on may be violated.Answer No answer,must be made.ClassOS Exercise BookNo.NameAi rhal rimeBuist 1 i[uvPi7.8 The Slee pin g-Barber Pr oblem. A barbersho p con sists of a wait ing room with n chairsand the barber room containing the barber chair. If there are no customers to be served,the barber goes to slee p. If a customer en ters thebarbersho p and all chairs are occu pi ed,then the customer leaves the sho p.lf the barber is busy but chairs are available, the nthe customer sits in one of the free chairs. If the barber is aslee p, the customer wakes up the barber. Write a p rogram to coord in ate the barber and the customers.Answer: Please refer to the supporting Web site for source code solution.8.2 Is it possible to have a deadlock involving only one single process? Explain your answer.Answer No. This follows directly from the hold-and-wait condition.8.4 Con sider the traffic deadlock dep icted in Figure 8.11.a. Show that the four n ecessary con diti ons for deadlock in deed hold in this exa mple.b. State a sim pie rule that will avoid deadlocks in this system.Answer No answerCon Sider the follow ing snap shot of a system:Allocati onMax AvailableA B C DA B C D A B C D P0 0 0 1 2 0 0 1 2 1 5 2 0P1 1 0 0 0 1 7 5 0 P2 13 54 2 35 6P 3 0 6 3 2 0 6 5 2P40 0 1 40 6 5 6An swer the follow ing questi ons using th e ban kera. What is the content of the matrix Need?b. Is the system in a safe state?c. If a request from p rocess immediately?Answer:A. Deadlock cannot occur because preempticin exists.b. Yes. A process may never acquire all the resources 让 needs if they are continuously preempted by aseries of reqviests such as those of process C.9.5 Given memory partitions of 100K, 500K, 200K, 300K, and 600K (in order), how would each of the First-fit, Best-fit, and Worst-fit algorithms place processes of 212K, 417K, 112K,and 426K (in order)? Which algorithm makes the most efficie nt use of memory?8.13 s algorithm:P1 arrives for (0,4,2,0), can the request be gran ted9OS Exercise BookClassNo. NameAnswer:212K is put in 500K partition 417K is put in BOOK partidon112K is put in 288K partition (new partition 288K = 500K = 212K) e. 426 K must wa 让212K 仏 put in 300K partidon 417K is put in 500K partition1I2K is put in 2nOK parti tin n 426K put in 600K partidon212K is put in 600K partition417K is put in 500K partitio 口 112K is put in 388K partidon 426K must waitIn this example. Best-fit turns out to be the best9.8 Con Sider a logical address sp ace of eight p ages of 1024 words each, mapped onto a physical memory of 32 frames.a. How many bits are there in the logical address?b. How many bits are there in the p hysical address?Answera. Logical addrej^s: 13 bitsb.卩hvsical address: 15 bits9.16 Con Sider the follow ing segme nt table: Segme nt Base Len gtha. First-fit:d ・ f. Best-fit:8- h* k. Worst-fit:m. n.600 14 100 580 96What are the p hysical addresses for the follow ing logical addresses? a. 0,430 b. 1,10 c. 2,500 d. 3,400 e. 4,112Answena. 219 + 43(1-649illegal reference, trap ki Dpvra ting systemillegal reference, trap tu op grating system10.2 Assume that you have a page referenee string for a process with m frames (initiallyall emp ty). The p age refere nee stri ng has len gth p with n disti net p age n umbers occur init. For any p age-re pl aceme nt algorithms,a. What is a lower bou nd on the n umber of p age faults?b. What is an upper bou nd on the n umber of p age faults?Answer a. tr b.卩10.11 Con Sider the follow ing p age refere nee stri ng: 1, Z 3, 4, 2,1,5, 6, Z 1,2, 3, 7, 6, 3, Z 1, Z 3, 6.How many p age faults would occur for the follow ing repl aceme nt algorithms, assum ing one, two, three, four, five, six, or seve n frames? Remember all frames are in itially emp ty, so your first uni que p ages will all cost one fault each.LRU rep laceme nt FIFO rep laceme nt Op timal rep laceme nt0 1 2 3 4219 2300 90 1327 1952 b. 2300 + 10 = 2310c. d. 1327 + 400= 17271111.7 Explain the purp ose of the openAnswer :■ The open operatit>n informs the system that the named file is about to become active^* Tlie cloiie «peration informs the system that tlie named file is no longer in active use by the user who issued the 匚lose operation.11.9 Give an example of an application in which data in a file should be accessed in the followi ng order: a. Seque ntially b. Ran domlyAnsiver :Print the content of the file.Print the content of record /. This record can be found using hashing or index techniques.11.12 theseusers to be able to access one file.a. How would you sp ecify this p rotecti on scheme in UNIX?b. Could you suggest ano ther pr otecti on scheme that can be used more effectively for this purpose tha n the scheme p rovided by UNIX?Answera. There are two methods for achieving this:Answer:ClassOS Exercise BookNo.NameNumber of framesLRU FIFO Optimal12 3 48-5 00 8 6 4and close op erati ons.a. b. Con sider a system that supports 5000 users. Suppose that you want to allow 4990 ofi. Create an access list with the names of all 4990ii. Put these 4990 users in one group and set the group access accordingly. This scheme cannot alwaysbe implemented since user groups are restricted by th# system.b. The univErse access information applies to all users unless their name appears in the access-controlHst with different access permission. With this scheme you simply put the names of the remaining ten users in the access control list but no access privileges alh)wcd.■r2Tl _Consider _a filecurrently consisting of 100 blocks.__Assume that _the file control block(ande in dex block, in the case of i ndexed allocati on) is already in memory. Calculate how any disk I/O op erati ons are required for con tiguous, li nked, and in dexed (sin gle-level) locati on strategies, if, for one block, the follow ing con diti ons hold. In thecase, assume that there is no room to grow in the beg inning, but there to be added is stored inAnswer198 9813.2 Con Sider the follow ing I/O see narios on a sin gle-user PC.a. A mouse used with a grap hieal user in terfaeeb. A tape drive on a multitask ing op erat ing system (assume no device p realloeati on is available) e. A disk drive containing user filesd. A gra phics eard with direet bus conn eeti on, aeeessible through memory-ma pped I/OFor each of these I/O see narios, would you desig n the op erat ing system to use bufferi ng, spo oli ng, eaehi ng, or a comb in ati on? Would you use p olled I/O, or in terru pt-drive n I/O? Give reas ons for your choices.teon tiguousalloeati onis room to grow in the end. Assume that the block in formatio nmemory.a. The block is added at the beg inning.b. The block is added in the middle. e. The block is added at the end.d. The block is removed from the begi nning.e. The block is removed from the middle.f. T he block is removed from the end.ContiffljQus LinkedIndexeda. b.201 101 52 3 52 10013OS Exercise BookClass No. NameAnswenA mouse used with a graphical user interfaceBuffering may bt? needed to record mouse movement during times when higher- priority op erations aretaking place. Spooling and caching are inap propriat 巳 Interrupt driven I/O is m 〔>st appropriate^ A t 日pe drive on a multitasking operating system (assume no device preallocation is availabl £) Buffering may be needed to manage through put difference behveen the tape drive and the souro? or destination of the I/O, C 白匚hing can bv used to hold copies of daU that resides on the tape, for faster access. Spooling could be used to stage data to the device when multiple users desire to read from or write to it. Interrupt driven I/G is likely to allow the best performance. A disk drive containing user filesBuffering can be used to hold data while in transit from user space to the disk, and visa versa. Caching can be used to hold disk-resident data for impmvtd performance. Spociling is not necessary because disks are shared-access devices. Interrupt- driven I/O is best for devices such as disks that transfer data at slow rates-A graphics card with direct bus connection, accessible through memory-rnapped I/O 'Buffering may be needed to control multiple access and for performance (doublebuffering can be used to hold the next screen image while displaying the current one). Caching and 5pooling are not necessary^ due to IH E fast and shared-access natures of the device. Folling and in term pts are only useful for input and for I/O completion detection, neither of which is needed for a memory^mapped device.14.2Suppose that a disk drive has 5000 cylinders,numbered 0 to 4999. The drive is currentlyserving a request at cylinder 143, and the previous request was at cylinder 125. The queue of pending requests, in FIFO order, is86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130Start ing from the curre nt head p ositi on, what is the total dista nee (in cyli nders) that the disk arm moves to satisfy all the pending requests, for each of the follow ing diskscheduli ng algorithms? a. FCFS b. SSTF c. SCAN d. LOOK e. C-SCANa. b.d.Answer:a. The FCFS schedule bi 143, 86, 1470, 913, 1774, 94S, 1509, 1022, 1750, 130. The tntal seekdistance is 7081.b. The SSTF schedule is 143, 130, 86, 913, 948, 1D22, 1470, 1509, 1750, 1774. The total seekdistance is 1745.c. The SCAN schedule is 143, 913, 94«, 1022,1470, 1509, 1750, 1774, 4999,130, 86. The total seekdistance is 9769.The LCX)K scheduJe is 143, 913, 94H, 1022, 1470, 1509, 1750, 1774, 130, H6. The total seekdistance is 3319.e. The C-SCAN schedule is 143,913,948,1022,1470,1509.1750,1774,4999;130. Thetotal seek distance is 9813.{Bonus.} The C-LOOK schedule is 143” 913,94& 1022,1470,1509,1750,1774,86,130. The tohal seek distance is 3363.1.1 1.62.3 2.53.7 6.3 6。
Unix面试题(英文 附答案)18
Unix面试题(英文附答案)1问题:Unix面试题(英文附答案)1-1 回答:1. unix 的at 命令的功能是A作业调度2. 在Linux环境下lilo是:D引导程序。
3. root 用户在/usr/bin 目录下执行命令chmod +s * 会对系统造成的最可能的伤害是:系统会立刻崩溃4. Which files are used to configure TCP WrappersA. /etc/tcpwrapper and /etc/access.confB. /etc/hosts.allow and /etc/hosts.denyC. /etc/tcpwrapper.conf and /etc/xinetd.confD. /etc/access.conf and /etc/xinetd.confE. /etc/tcpwrapper and /etc/access.confExplain -p46:Explanation: TCP Wrappers are configured in the /etc/hosts.allow and /etc/hosts.deny files.5. How do you enable quotas on a partition in /etc/fstabA: Add the enforcequotas option.B: You don t. Quotas are turned on automatically when you install the quota rpm.C: Add the quota option.D: Add the usrquota and grpquota options.E: You put a 1 in the last column.Explain -p20:Explanation: T o enable quotas on a partition you put the userquota and groupquota option in the options section for the partition in /etc/fstab.6. If you want to allow X-Windows programs from hostB to run on the display on hostA what would you need to doA. run xhost +hostB on hostA.B. run xhost +hostA on hostB.C. run xhost + on hostA.D. run xhost + on hostB.E. just set the DISPLAY environment variable and it will work.Explain -p40:Explanation: You want programs from hostB to display on hostA. So you must tell hostA to allow Xclients from hostB. Hence A is correct. The xhost + command is too broad and allows anyone to connect to your X-server.7. How can you turn off interface eth1A. service network stopB. service netork stop eth1C. ifstop eth1D. ifdown eth1E. ps -aux |grep eth1| kill `awk -f $1 `Explain -p42:Explanation: The ifdown eth1 command will turn off the eth1 interface. the service network stop command will stop all networking which is not what you want. The ifstop command does not exist. The last command is just nonsense.8. What command do you use to edit quotas edquota9. 系统管理员对于磁盘的管理任务主要包括:格式化磁盘硬盘分区建立合适的文件系统安装成文件目录10. UNIX系统具有以下特点:ABCDA: 多用户B: 多进程C: 多处理机D: 多线程11. What program allows you to acess SMB shares using ftp-like commmandsA. Mount Smbftp Smbclient SmbmountExplain -p1:Explanation: The smbclient program allows you to acess SMB shares using commands similar to FTP.12. What does the -N option do for the dhcpcd programA. Sets the hostname of the machine to the name provided by DHCP.B. If the dhcpcd server is already running then it sends it an ALRM signal to get it to renew its lease.C. Passes the machine name to DHCP as part of the DHCP request.D. Only tries to get a new ip address if the current one is older than a certain number of hours.Explain -p53:Explanation: The -N option will an ALRM signal to dhcpcd,if it is already running, to cause it to attempt to renew it s lease.使用SAMBA服务器,一般来说,可以提供:文件服务打印服务13. You have a text file named nytextfile . How would you sort the lines of the file in reverse alphabetical order :C sort -r mytextfile14. 在smb.conf文件中有如下的表达%U,该表达的含义是:sambar的一个宏替换当前会话使用的用户名15. You have created a /home/projectfoo directory. How can you change its group ownership to the projectfoo groupA. chmod g+rwx projectfoo /home/projectfooB. chown projectfoo /home/projectfooC. chgrp projectfoo /home/projectfooD. newgrp projectfoo /home/projectfooExplain -p7:Explanation: The chgrp command sets the group ownership of a file or directory.。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
S.1Uni x Internals (Apri l/May-2012, Set-1) JNTU-AnantapurB.T ech. III-Year II-Sem.( JNTU-Anantapur)Code No.: 9A05602/R09B.Tech. III Year II Semester Regular ExaminationsApril/May - 2012UNIX INTERNALS( Computer Science and Engineering )Time: 3 HoursMax. Marks: 70Answer any FIVE Questions All Questions carry equal marks- - -1.(a)Draw and explain the architecture of UNIX systems. (Unit-I, Topic No. 1.5.1)(b)Discuss in detail the sleep and wakeup procedures. (Unit-V, Topic No. 5.6)2.(a)If several processes contend for a buffer, the kernel guarantees that none of them sleep forever, but it does not guarantee that a process will not be starved out from use of a buffer. Redesign getblk so that a process is guaranteed eventual use of a buffer. (Unit-II, Topic No. 2.2)(b)What are the advantages of buffer cache? (Unit-II, Topic No. 2.5)3.(a)Give brief description about the accessing of inodes. (Unit-III, Topic No. 3.1)(b)Explain in detail the continuous file allocation system. (Unit-III, Topic No. 3.7)4.(a)What is the purpose of link system call? Write and explain the algorithm for the same. (Unit-IV, Topic No. 4.12)(b)Write short notes on maintenance of the file system. (Unit-IV, Topic No. 4.15)5.(a)What are regions? Explain their role in the creation of processes. (Unit-V, Topic No. 5.2)(b)Describe in detail about the context of a process. (Unit-V, Topic No. 5.3)6.(a)Explain the security problems that exists if a setuid program is not write protected. (Unit-VI, Topic No. 6.6)(b)Write a program that a parent and child shares a file access. (Unit-VI, Topic No. 6.1)7.(a)Discuss in detail about the scheduling parameters. (Unit-VII, Topic No. 7.1)(b)What is profiling? Explain it in detail. (Unit-VII, Topic No. 7.3)8.(a)Explain clists in detail. (Unit-VIII, Topic No. 8.3)(b)Write a program for reading data from risk by using block and raw interfaces.(Unit-VIII, Topic No. 8.3)S.2Spectrum ALL-IN-ONE Journal for Engineering Students, 2013B.T ech. III-Year II-Sem.( JNTU-Anantapur)(a)Draw and explain the architecture of UNIX systems.Answer :April/May-12, Set-1, Q1(a)For answer refer Unit-I, Q10.(b)Discuss in detail the sleep and wakeupprocedures.Answer :April/May-12, Set-1, Q1(b)For answer refer Unit-V , Q17.(a)If several processes contend for a buffer,the kernel guarantees that none of them sleep forever, but it does not guarantee that a process will not be starved out from use of a buffer. Redesign getblk so that a process is guaranteed eventual use of a buffer.Answer :April/May-12, Set-1, Q2(a)Algorithm getblkInput: file system numberblock numberOutput: locked buffer that can now be used for block {While (buffer not found){If (block is not in hash queue)If (there are no buffers on free list){sleep (event any buffer becomes free);continue;}}}}(b)What are the advantages of buffercache?Answer :April/May-12, Set-1, Q2(b)For answer refer Unit-II, Q12, Topic: Advantages of Buffer Cache.(b)Explain in detail the continuous file allocation system.Answer :April/May-12, Set-1, Q3(b)Note: In given question, the word contiguous is misprinted as continous.In a contiguous allocation method all the files are arranged in a sequential blocks of memory. Therefore,according to this technique, if a file size is k blocks and it starts from a block s then it spans till stk-1 block numbers.With this approach file access is much faster as all files occupy contiguous blocks. For sequential access of files the physical address of the last referred block is noted, so that file access can start from the next block to avoid repeated accesse of the previous blocks. Direct access is also supported since only the starting address and the block numbers are required.Though access time is minimal, contiguous allocation does not make efficient use of the disk space. This means that the allocation of space for a new file should be efficient enough so that disk space is not wasted.01234567891011IMP 1213141516171819USER 2021222324252627CHAT28293031DISKFOO DirectoryFilename Starting locationSize Foo Imp User Chat0614263764S.3Uni x Internals (Apri l/May-2012, Set-1) JNTU-AnantapurB.T ech. III-Year II-Sem.( JNTU-Anantapur)common strategies used for this purposes are best fit, worst fit and first fit. First fit is considered to usually be faster than other two strategies. However, best fit is also considered to be efficient than worse fit in terms of both time and disk space utilization.Even if any of these strategies are used all of them suffer with external fragmentation. External fragmentation occurs when a request for a new file cannot be satisfied because the largest available continous chunk of blocks is not sufficient enough for the file. Therefore, even though there is enough space available for the file, but it is not utilized because it is not contiguous.External fragmentation can be resolved with the help of a scheme called “compaction”. Compaction involves rearranging all free memory locations in a sequential order so that contiguous disk space can be allocated for new files instead of space getting wasted. Compaction is carried out in both off line and online modes. In offline mode, all operations are suspended and the file system is unmounted and finally compaction is performed. In this strategy a lot of time is wasted and hence it is avoided. In online mode,compaction is performed alongwith other system operations,but it effects business performance and reduces time wastages.However, contiguous allocation scheme also requires to know the size of the new file for storage allocation. This requirement looks simple but it might be difficult to determine the size of an output file after its execution. Also if the size of the file is determined in advance and the file takes a lot of time to reach its final size, then a lot of space is wasted when the file has not reached its final size. Therefore, a modified contiguous allocation scheme is used that allocates some fixed amount of space for the first time and if the file requires more space then another chunk of contiguous blocks is allocated. The chunks of free blocks allocated after the first allocation is called “infant” and these two chunks of contiguous blocks are linked to one another.Q4.(a)What is the purpose of link system call?Write and explain the algorithm for the same.Answer :April/May-12, Set-1, Q4(a)Link ( ) System CallLink system call creates a new directory for an inode that already exists. It does this by linking a file to a new name in the file system directory. It has the following syntax,Link (existing filename, new filename)The file system consists of pathnames for each link.Processes use the pathnames to access files. All the filenames are given equal priorities since the Kernel is unaware of the original filename.Figure: Files Linked in the File System Tree After executing the system callsLink(“/usr/foo/sys/src”,“/usr/lib/src'');Link(“/usr/lib/file3.h” ,“/usr/Foo/src/file2h”);The paths–“/usr/Foo/sys/file2.h”,“/usr/lib/file 3.h” and “/usr/lib/src/file2-h” belong to the same file.The Kernel gives the authority of linking directories only to the superuses. This makes the coding part easy for the program that traverses the file system tree. Superusers have to be careful enough while linking directories. The ability of linking directories must be supported on early versions of the system. This is because, the mkdir command used for creating new directories depends on the ability of linking directories. Algorithm of link system call, the following algorithm shows the linking of files.1.Obtain the inode for existing filename using the“namei” algorithm.2.If there are many links on file/linking directorywithout superuser permission.(a)Release the inode using “iput” algorithm.(b)Return error.3.Increment the link count.4.Update the disk copy of inode.5.Unlock inode.6.Obtain the parent for the new filename inodeusing “namei” algorithm.7.If the new file already exists,(a)Undo the update done in step (4)(b)Return error.8.Make a new directory in the parent directory ofthe new filename.9.Add the new filename and the inode number ofthe existing filename.10.Release parent directory inode using “iput”algorithm.11.Release the inode of the existing file using “iput”algorithm.S.4Spectrum ALL-IN-ONE Journal for Engineering Students, 2013 The Kernel uses “namei” algorithm to look up for the inode for the source file. It increments the link count and updates the disk copy of the inode. Then it unlocks the inode and searches for the target file. The “Link” call will fail if the file is not available. The Kernel decrements the link count which was previously incremented. If the file is not available then it finds a free slot in the parent directory of the target file. It writes the name of the target file and inode number of the source file into it. Using the “iput” algorithm, it releases the inode of the target file parent directory. The target file did not exist in actual. Hence no more inodes are there to be released.Finally, the Kernel releases the source file inode which is accessed by another file in the file system. The link count increases by 1. It keeps track of the count of directory entries belonging to the file. This differentiates it from the inode reference count. If the file is not accessed by any other process then inode reference count of the file becomes 0 and the link count will be atleast 2.(b)Write short notes on maintenance of the file system.Answer :April/May-12, Set-1, Q4(b) For answer refer Unit-IV, Q17.Q5.(a)What are regions? Explain their role in the creation of processes.Answer :April/May-12, Set-1, Q5(a) For answer refer Unit-V, Q3, Topic: Regions.(b)Describe in detail about the context of a process.Answer :April/May-12, Set-1, Q5(b) For answer refer Unit-V, Q7.Q6.(a)Explain the security problems that exists if a setuid program is not write protected. Answer :April/May-12, Set-1, Q6(a) The security problems that exists if a setuid program is not write protected are as follows,1.The first problem is associated with executing a sequence of commands defined by the attacker.2.The second problem is associated with substituting data of the attacker’s choosing for data created by aprogram.In the first problem, an attacker takes advantage of the setuid program’s running with special privileges to force it to execute whatever commands the attacker needs. For instance, assume that an attacker found a copy of the Bourne shell that was setuid to root. The attacker could then execute the shell since, the shell is setuid to root these commands would be executed as though root had typed them. Hence, the attacker could do anything he wants, since root is the most highly privileged user on the system. Even if the shell were changed to read from a command file rather than accept commands interactively, the attacker could file simply create his own script and run the shell using it. This situation must be avoided and it is easy to avoid but it occurs frequently.Several problems are possible with world-writable files. Occasionally programs will use temporary files for various purposes, the function of the program depending on what is in the file. If the program closes the temporary file at any point and then reopens it later, an attacker can replace the temporary file with a file with other data that will cause the program to act as the attacker desires. If the replacement file has the same owner and group as the temporary file, it can be very difficult for the program to determine if it is being spoofed.(b)Write a program that a parent and child shares a file access.Answer :April/May-12, Set-1, Q6(b) For answer refer Unit-VI, Q3.Q7.(a)Discuss in detail about the scheduling parameters.Answer :April/May-12, Set-1, Q7(a) Scheduling parameters are used for process scheduling each entry in the process table contains a priority field that can be used for process scheduling.For remaining answer refer Unit-VII, Q2.B.T ech. III-Year II-Sem.( JNTU-Anantapur)S.5Uni x Internals (Apri l/May-2012, Set-1) JNTU-AnantapurB.T ech. III-Year II-Sem.( JNTU-Anantapur)(b)What is profiling? Explain it in detail.Answer :April/May-12, Set-1, Q7(b)For answer refer Unit-VII, Q10.Q8.(a)Explain clists in detail.Answer :April/May-12, Set-1, Q8(a)For answer refer Unit-VIII, Q11.(b)Write a program for reading data from risk by using block and raw interfaces.Answer :April/May-12, Set-1, Q8(b)#include “Fcntl.h”main ( ){char buffer1 [4096], buffer2 [4096];int Fd1, Fd2, i ;if (((Fd1 = open(“/dev/dsk5”, 0_RDONLY))= = –1)|| ((Fd2 = open(“/dev/rdsk5”, 0_RDONLY))= = –1))){printf (“read operation failed\n”);exit( );}for (i = 0; i < size of (buffer1); i + +)if (buffer 1[i]! = buffer2 [i]){printf(''different at offset %d\n'', i);exit ( );}printf(“reads successfully matched\n”);}。