207 135 6MB
English Pages [232]
Table of contents :
Cover
Half Title
Title
Copyright
Preface
Contents
Chapter 1: Introduction
Chapter 2: Operating System Services
Chapter 3: Process Management
Chapter 4: Multithreading and Scheduling
Chapter 5: Process Synchronization
Chapter 6: Memory Management
Chapter 7: File System and Storage
Chapter 8: Input Output Systems and Security
Chapter 9: Signals
Chapter 10: Posix Threads Programming
Chapter 11: Numeric Problems
Chapter 12: Theoretical Questions
Backcover
Cracking the
Operating Systems Skills
Cracking the
Operating Systems Skills Sundaram RMD Software Architect Wipro Technologies Bengaluru, India
Dr. Shriram K Vasudevan
Assistant Professor (Selection Grade) Dept. of Computer Science and Engineering Amrita School of Engineering, Amrita University Coimbatore, Tamil Nadu, India
Abhishek S Nagarajan Data Scientist [24] 7, Inc Bengaluru, Karnataka, India
Dr. B Chella Prabha
Dean – Academics SNS College of Technology Coimbatore
©Copyright 2020 I.K. International Pvt. Ltd., New Delhi-110002. This book may not be duplicated in any way without the express written consent of the publisher, except in the form of brief excerpts or quotations for the purposes of review. The information contained herein is for the personal use of the reader and may not be incorporated in any commercial programs, other books, databases, or any kind of software without written consent of the publisher. Making copies of this book or any portion for any purpose other than your own is a violation of copyright laws. Limits of Liability/disclaimer of Warranty: The author and publisher have used their best efforts in preparing this book. The author make no representation or warranties with respect to the accuracy or completeness of the contents of this book, and specifically disclaim any implied warranties of merchantability or fitness of any particular purpose. There are no warranties which extend beyond the descriptions contained in this paragraph. No warranty may be created or extended by sales representatives or written sales materials. The accuracy and completeness of the information provided herein and the opinions stated herein are not guaranteed or warranted to produce any particulars results, and the advice and strategies contained herein may not be suitable for every individual. Neither Dreamtech Press nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages. Trademarks: All brand names and product names used in this book are trademarks, registered trademarks, or trade names of their respective holders. Dreamtech Press is not associated with any product or vendor mentioned in this book. ISBN: 978-93-89520-96-5 EISBN: 978-93-89872-26-2
Preface
Are You at Crossroads? Are you tired of getting IT interviews but not offers? Are you confused between preparing for different competitive exams? Are you dazed of the competition seen in the computer market? Are you feeling fuzzy about the future in programming world? Are you desperate for a better software job, but can’t figure out what that is or how to get there? If you are under the awe of even any one of the above questions then you have perhaps taken the right decision – of buying this book and preparing for the technical interview! I suggest that you consume the contents from the first chapter to the end, sequentially, and not attempt to skip any section or chapter unless you are very confident of the topic that you want to skip. This is because, this book has been specifically designed to orient you for the technical interview with the Operating System concepts. Please stay with the preface and read it to the end to understand why. After reading the preface you will most likely revise your prep strategy. IT Job Landscape You should take heart if you see the plethora of job openings, and which is growing, in the IT and ITeS space. The scenario looks like this: NASSCOM, the premier trade body for the IT-BPM sector in India has given a latest press release that the Indian IT-BPM sector continues to be one of the largest employers in the country directly employing nearly 3.5 million professionals, adding over 2,30,000 employees. They have also predicted that the future looks very promising as the IT-BPM industry is gearing itself well to the next phase of challenges. Digitization, disruptive technologies and innovation will fuel growth with new opportunities in the years ahead. They have also projected that the Indian IT industry would grow to about $300 billion by 2020, and create different verticals that would focus on specific areas such as the domestic IT market, software products and e-commerce which tells us there are and there will be more job openings in the IT sector. Recruiter’s Perspective As a potential job hunter, your chances of success increase manifold if you understand what your recruiters are looking for. According to a new career builder survey,
vi Preface
overwhelming majority of IT companies say soft skills such as a positive attitude are just as important as hard skills. Positivity comes from within when you are confident on your subjects. The top 10 traits employers seek out in candidates include hardworking, dependable, positive, self-motivated, team-oriented, organized, works well under pressure, effective communication, flexible and confident. If all of these can boil down to one thing, then it is subject matter expertise which will help you attain rest of all the things. Technical Interview Process Recruitment refers to the process of attracting, selecting and appointing suitable candidates for jobs in an organization. From the organization’s perspective, this includes job analysis, sourcing, screening and finally selection. Though every company differs in its own way of selecting the candidates, every company strives towards getting the “right” person for the “right” job. In a technical interview, applicants are likely to be asked questions that • relate to specific skill set that is needed for the company's technical activities; • relate to the basics on the subject matter to resolve any complex problems; • are for rookies, it will be related to the projects completed as part of a degree course; and • requires candidates to solve actual technical problems that they would be likely to face if employed. One of the articles by Forbes, an American business magazine, talks about four supercommon interview questions post-technical interview session which includes “tell me about yourself”, “what is your greatest strengths”, “why should we hire you” and “do you have any questions for us”. Though these are very common questions, giving unexpected and most relevant answers will make the interviewer sit up faster and listen to you. Your Personal SWOT Now that you know your dream job is beckoning you (your opportunity) that you need to outpace only X competitors (your threats), what the recruiters would be looking at while interviewing, make sure you list down your areas of strength, and more importantly weakness. While you would have little control over the opportunities and threats, you can fully devote yourself to take your strengths to newer heights and work on your weaknesses to prevail upon them. Use the SWOT grid given below for planning your prep.
Preface vii
Jobs I love
Strengths
Dream Job
Opportunities Threats
Weaknesses
My Skills
Jobs that Pay
Why Operating System? It has been seen that X% of all the technical interviews have Operating Systems as an extra eye along with C programming at heart. Any device or electronic gadget has an operating system running inside. If you read this book as an eBook through a smart phone or a computer/laptop, you shall be using Android or Windows as the base platform. Even a software like Photoshop or programming software like C or C plus plus shall be ported over the operating system. All the application software are installed over the OS. Why this Book? As I had mentioned earlier in the preface, this book has been specifically designed for a purpose. The purpose is to help you undertake a meticulous and objective prep. The contents have been carefully handpicked from our experience and expertise developed by being either direct witness to the recruitment process, mentoring students in our colleges, myriad discussion with our peers who are placement organizers in colleges, hours of studying discussions on the topics in social media, blogs and dedicated web sites, so that the book is highly focused to the interview prep for Operating System and almost nothing else. We have come to the conclusion that for effective prep everything boils down to multiple choice questions around theory and coding problems. Anyone wishing to sharpen his skills on operating systems or preparing for aptitude tests, competitive examinations should thorough this book which will help them reach the goal. We have combined our technical expertise to develop multiple questions which will help you in strengthening your weaknesses and also in enhancing your strengths. For this we thought that the best way is to grade the problems into levels of difficulties (LoDs). The complexity of the questions have been incremented with more technical challenge from L1 to L3. L1 is guileless which would test the basic concepts and some
viii Preface
syntaxes wherein L3 will test your understanding of the logic and code in-depth with concepts. Each chapter has complexities distributed evenly with focus being given at all levels of difficulty. 1. L1: Tests the basic concepts and syntactical know-how. 2. L2: This is a little thought provoking part where the answers will be simple still. 3. L3: It has the most tricky and easy ones and also unexpected behavioural snippets. Also has the unseen concepts and unknown behaviours. What is this Book all About? Operating Systems Questions and Answers has been aimed with a distinct purpose of assisting students and specialists getting ready for several certification exams and job interviews. This book provides a useful collection of sample interview questions and multiple choice questions and their answers with appropriate explanation. Let’s get started with the preface section! These operating system interview questions and answers have been intended specifically to get you familiar with the nature of questions you may face during your operating systems interview and written examinations. This book was engraved with two groups of readers in mind. The book’s primary audience are the ones who want to learn the basics of operating system through objective type questions and an important second audience who want to master their skills in cracking the interviews. Learning and testing the learnt skills can be carried out through this book. We hope that you will find what follows. LoD (levels of difficulty) will enable the readers to move step by step in testing their understanding. This book reflects the growing complexity with which interviewing is being loomed and we have included the latest topics and questions discussed in top companies today while continuing to maintain the emphasis on basic concepts along with problem solving skills for both students preparing for exams and for interviewees. We made more studentfriendly by eradicating redundant words, materials, and dated models, presenting detailed descriptions, providing fewer lists, and using bold print to call attention to important terms. The book is organized into twelve chapters, covering major subject areas and each chapter covers a number of exercises along with the correct answers. The book requires a basic knowledge of operating systems. As we elucidate later in the book, operating systems conceptual MCQs and problem solving isn’t really suitable for wide-ranging of beginners–though many have succeeded to use it–so the book will presume that the readers of this book have already covered basic concepts with the notions of system calls, file handling, formulae, along with ‘C basics’ and so on. Coverage of the Book Chapter 1 is the engine that drives the rest of the document and has all the basics of operating systems covered in it. The readers will get all the basics re-learnt or revised properly on reading chapter 1.
Preface ix
Chapter 2 covers operating system structure and services in detail. Chapter 3 is all about process management which is an integral part of any modern-day operating system. The process management is the most important area and it is one of the highly looked-in areas in the interview. Process knowledge will really ease the interview process. Readers can observe that more number of questions are given from this area in the book. Chapter 4 discusses multithreading which is the ability of a program or an operating system process to manage its use by more than one user at a time and to even manage multiple requests by the same user without having to have multiple copies of the program running in the computer. This unit also covers scheduling. Threads are smaller units in an OS and they work faster too. Also, context switching is faster as the memory space is shared in threading concepts. Attention has been paid more to technical aspects of threading and questions have been framed based on it. Chapter 5 covers synchronization which is most important in multithreading as there is a need to synchronize the action of multiple threads and make sure that only one thread can access the resource at a given point in time. The major task of an operating system not only stops with process management or peripheral management. It also manages memory which is going to impact the performance of the system in a great way. Chapter 6 is all about memory management which is an act of managing computer memory at the system level. The questions will provoke reader to think about memory management. Anything and everything is file for operating systems. In Chapter 7 we discuss file systems and storage. A file system is a collection of methods and data structures that an operating system uses to keep track of files on a disk or partition; that is, the way the files are organized on the disk. The second half covers storage which is the place where data is held in an electromagnetic or optical form for access by a computer processor. Readers could test their understanding about files and internals when the reading is complete. Subsequently chapter 8 deals with I/O systems and security. I/O is the communication between an information processing system and the outside world. Complete focus in this chapter is on how the communication happens and how information is secured as well. Chapter 9 covers signals in operating system while chapter 10 is all about POSIX threads programming related questions. The last two chapters 11 and 12 are all about numerical problems and theoretical questions that will be useful for anyone facing operating systems related interviews. Chapter 12 is a special chapter and must be read by all as it has the finishing touch for the book. All possible questions which would be asked by an interviewer are covered with answers and would be an excellent recap for the learners.
x Preface
Statistics would suggest that no book in print came even close to adequately covering all these topics with so many possible objective questions and we are happy that this book covers all aspects for a programmer to succeed in interviews as well to learn the intricacies of operating systems. Have a happy learning experience! Constructive critics are welcome and readers can get connected to authors through: [email protected] and [email protected] CHAPTER-WISE BREAKUP OF QUESTIONS Chapter
Details
Number of Questions
1
Introduction
150
2
Operating System Services
130
3
Process Management
160
4
Multithreading and Scheduling
148
5
Synchronization
85
6
Memory Management
35
7
File System and Storage
30
8
Input Output Systems and Security
50
9
Signals
32
10
Posix Threads Programming
30
11
Numeric Problems
96
12
Theoretical Questions
140
Total
1086
A Brief History of Operating Systems Initially, all the work was done by humans. To reduce their task, machines were brought into the picture. At that time, machine was costlier than human labour. The first phase was hand programmed machines (1945 – 1955). It was a single user operating system. It just had some loader along with a set of common subroutines in the form of libraries. The batch process evolved (1955 – 1965). This type of OS has a loader, sequencer and an output processor. Then multiprogramming came into actuality (1965 – 1980). Till date it is making up the big picture. Another feather to the crown was time sharing. This came into life in 1970. Both these concepts go hand in hand and are ruling the automated world till date.
Preface xi
Other Specific Benefits of this Book Though many books are available in the market on operating systems, most of them are theoretical in nature. There are not many books that have a series of technical one liners and problems that can be used to build OS skills. Many people understand the basic semantics but only an objective type book can help hone the skills. It’s quite frustrating that no book in print came even close to adequately covering all different topics in OS with so many possible objective questions and we are happy that this book covers all aspects for a programmer to succeed in interviews as well to learn the nuances of programming. Who Else will Find this Book Useful? Apart from technical interview prep, this book can be gainfully used by developers, software engineers, and aspirants of other competitive examinations like GATE, IES etc. A good software engineer should have a basic level of comfort in operating systems handling and problem solving – be able to comprehend code and write something non-trivial – probably in C language. A modern-day programmer is expected to be proficient in operating systems and is most wanted for the below industries: • Consumer electronics and embedded systems industries needs operating systems to manage it, some problem in handling and controlling them and so on. • Even companies developing applications require some parts to be implemented specific to OS according to its characteristics for the purpose of optimization and performance improvement. • Firmware code is written using C for various electronics, industrial and communications products which use microcontrollers as CPU. But that is also OS dependent and requires the basic knowledge of it. Competitive examinations after graduations also require C programming if you are in the computer science and information technology streams. This includes but is not limited to: • GATE: To score a good rank, you must practice the full syllabus as prescribed from year to year and operating systems and problem solving skill carries extensive weightage in it. • IES – Indian Engineering Services also has questions from operating systems to a wide range from command level to kernel level. • Now various PSU’s like: IOCL, NTPC, CONCOR, GAIL, BPCL, HP, CL, BHEL, PGCIL, BEL, DDA, etc., consider GATE SCORE for their recruitment. They are also conducting their own written exams for their recruitment that includes questions from operating systems. • Many other competitive examinations conducted both within and outside the country test the basic OS skills if you are in the information technology domain. With these words we wish you all the best in your career! Have a happy learning experience!
Contents
Preface
v
1. Introduction
1
2. Operating System Services
22
3. Process Management
41
4. Multithreading and Scheduling
70
5. Process Synchronization
99
6. Memory Management
126
7. File System and Storage
131
8. Input Output Systems and Security
136
9. Signals
143
10. Posix Threads Programming
151
11. Numeric Problems
168
12. Theoretical Questions
195
1
Introduction
This chapter deals with the basics of operating system and also includes some programming questions related to operating system concepts. At the end of the chapter you will be well versed in many operating systems terms. 1. Operating system is a: (L1) (a) Application software (c) Utility software Answer: (b) System software
(b) System software (d) None of the above
2. Which of the following are operating systems: (L1) (a) Single and multitasking (b) Distributed and templated (c) Embedded and RTOS (d) All of the above Answer: (d) All of the above 3. An operating system acts as an intermediary between: (L1) (a) Programs and hardware (b) User and application (c) Different applications (d) Multiple hardware Answer: (a) Programs and hardware 4. Operating systems are found on which of the following devices: (L1) (a) Cellular phones (b) Video game console (c) Web servers and supercomputers (d) All of the above Answer: (d) All of the above 5. Which of the following is not a popular modern operating system: (L1) (a) Android (b) iOS (c) Linux and Windows (d) Microcontroller Answer: (d) Microcontroller 6. A single-tasking system can run ________ program at a time, while a multitasking OS allows ________ program to be running in concurrency. (L1) (a) many, one (b) one, one (c) one, many (d) many, many Answer: (c) one, many
2 Cracking the Operating Systems Skills
7. Multitasking may be characterized in ________ types. (L2) (a) Pre-emptive (b) Cooperative (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 8. Unix like operating systems support: (L3) (a) Pre-emptive multitasking (b) Cooperative multitasking (c) Both a and b (d) Neither a nor b Answer: (a) Pre-emptive multitasking 9. Cooperative multitasking support is present in ________ versions of Microsoft Windows (L2) (a) 32-bit (b) 16-bit (c) 64-bit (d) 128-bit Answer: (b) 16-bit 10. Single user operating systems have ________ facilities to distinguish users, but allow ________ programs to run (L2) (a) No, multiple (b) All, No (c) Many, one (d) No, one Answer: (a) No, multiple 11. ________ user operating system allows multiple users to interact with the system at the same time (L2) (a) Single (b) Two (c) Multi-user (d) No Answer: (c) Multiuser 12. A ________ operating system manages a group of distinct computers and makes them appear to be a single computer (L2) (a) Single (b) Multiuser (c) Unix (d) Distributed Answer: (d) Distributed 13. Distributed computations are carried out on: (L2) (a) Single machine (b) More than one machine (c) Two machines (d) Virtual machines Answer: (b) More than one machine 14. When computers in a group work in ________, they form a distributed system (L2) (a) Non-cooperation (b) Independently (c) Cooperation (d) Virtually Answer: (c) Cooperation 15. Embedded operating systems are designed to be used in: (L2) (a) Small machines like PDAs (b) Supercomputers (c) Laptops (d) All of the above Answer: (a) Small machines like PDAs
Introduction 3
16. A RTOS is an OS that guarantees to process events or data in: (L3) (a) Large amount of time (b) One week time (c) Many years to complete (d) Short amount of time Answer: (d) Short amount of time 17. The earliest electronic digital systems had ________ operating systems: (L1) (a) One (b) No (c) Many (d) Few Answer: (b) No 18. With the aid of the firmware and device drivers, the ___ provides the most basic level of control over all of the hardware devices. (L1) (a) Application (b) Kernel (c) Memory (d) User Answer: (b) Kernel 19. ________ are central to operating systems (L2) (a) Interrupts (b) Kernel (c) Modes Answer: (a) Interrupts 20. The alternatives to interrupts are: (L1) (a) Watchers (c) Other interrupts Answer: (b) Polling
(d) Applications
(b) Polling (d) No alternatives
21. Small stacks uses ________ and large stacks uses ________: (L2) (a) Interrupts, Polling (b) Polling, Polling (c) None, Interrupts (d) Polling, Interrupts Answer: (d) Polling, Interrupts 22. When an interrupt is received, the computer’s hardware: (L1) (a) Continues doing current job (b) Waits for user to suspend current program (c) Automatically suspends current program and jumps to ISR (d) Exit the program and goes to sleep state Answer: (c) Automatically suspends current program and jumps to ISR 23. Interrupts may come from either the (L1) (a) Computer hardware (b) Running program (c) Neither a nor b (d) Either a or b Answer: (d) Either a or b 24. Interrupts are handled by the operating system’s (L1) (a) User (b) Kernel (c) Application (d) Hardware Answer: (b) Kernel
4 Cracking the Operating Systems Skills
25. Modern CPUs support ________ modes of operation (L1) (a) Single (b) Two (c) Multiple (d) No Answer: (c) Multiple 26. Which of the following are valid modes of operation (L1) (a) Protected mode (b) Supervisor mode (c) Application mode (d) Both a and b Answer: (d) Both a and b 27. The ________ mode is used by the operating system’s kernel for low level tasks that need unrestricted access to hardware. (L2) (a) Supervisor (b) Application (c) User (d) Kernel Answer: (a) Supervisor 28. Applications operate within ________ mode, and can only use hardware by communicating with the kernel, which controls everything in supervisor mode. (L3) (a) Supervisor (b) Protected (c) User (d) All of the above Answer: (b) Protected 29. When a computer first starts up, it is automatically running in ___ mode. (L1) (a) No (b) User (c) Supervisor (d) Protected Answer: (c) Supervisor 30. A multiprogramming operating system kernel must be responsible for managing all ________ which is currently in use by programs. (L1) (a) Users (b) Time (c) System Memory (d) Interrupts Answer: (c) System Memory 31. By ________ memory addressing, the OS can use the same memory locations for multiple tasks. (L1) (a) Virtual (b) Real (c) Imaginary (d) Offset Answer: (a) Virtual 32. Virtual memory provides the user with the perception that there is a much larger amount of ________ in the computer than is really there. (L1) (a) ROM (b) Data (c) Tertiary memory (d) RAM Answer: (d) RAM
Introduction 5
33. ________ refers to the running of multiple independent computer programs on the same computer. (L1) (a) Single tasking (b) Multitasking (c) Both a and b (d) Neither a nor b Answer: (b) Multitasking 34. Kernel contains a ________ program which determines how much time each process spends executing and in which order control should be passed to programs. (L1) (a) Application (b) Scheduling (c) User (d) All of the above Answer: (b) Scheduling 35. An early model which governed the allocation of time to programs was called ________ (L1) (a) Cooperative multitasking (b) Scheduling (c) Multithreading (d) None of the above Answer: (a) Cooperative multitasking 36. The so-called passing of control between the kernel and applications is called a ________ (L1) (a) Thread switch (b) Task switch (c) Process switch (d) Context switch Answer: (d) Context switch 37. Context switches are usually ________, and much of the design of operating systems is to optimize the use of context switches. (L1) (a) Long (b) Computationally easy (c) Computationally intensive (d) None of the above Answer: (c) Computationally intensive 38. Potential trigger for a context switch is: (L2) (a) Multitasking (b) Interrupt handling (c) Mode switching (d) all of the above Answer: (d) All of the above 39. Which multitasking can hang the entire system if it enters an infinite loop: (L2) (a) Cooperative (b) Pre-emptive (c) Independent process scheduler (d) All of the above Answer: (a) Cooperative
6 Cracking the Operating Systems Skills
40. Which multitasking ensures that all programs are given regular time on the CPU. (L1) (a) Non pre-emptive (b) Pre-emptive (c) Independent process scheduler (d) All of the above Answer: (b) Pre-emptive 41. What is the output of the code when “i.txt” exists? (L2) void main() { char s[10]; int fd1=open(“i.txt”,O_RDONLY); printf(“hai”); } (a) hai (b) Prints nothing (c) Error (d) None of the above Answer: (a) ‘open’ is a Linux system call that opens the specified file in the mode specified. ‘O_RDONLY’ means read only mode. ‘O_WRONLY’ means write only. And ‘O_RDWR’ means read and write mode. 42. What is the output of the code when “i.txt” exists? (L2) void main() { char s[10]; int fd1=open(“i.txt”,0); printf(“hai”); } (a) hai (b) Prints nothing (c) Error (d) None of the above Answer: (a) ‘0’ means read only mode. ‘1’ means write only and ‘2’ means read and write. 43. What is the output of the code when “i.txt” does not exist? (L2) void main() { char s[10]; int fd1=open(“i.txt”,0); printf(“hai”); } (a) hai (b) Prints nothing (c) Error (d) None of the above Answer: (a) Unlike normal ‘C’ program it doesn’t result in segmentation fault. Here the system call fails, but the print statement works normally without any change. Thus prints ‘hai’. 44. What is the output of the code when “i.txt” exists? (L3) void main() { char s[10];
Introduction 7
int fd1=open(“i.txt”,0); printf(“%d”,fd1); } (a) 3 (b) 1 (c) 2 (d) None of the above Answer: (d) It depends on the time when the process is launched. The integer has the file directory number allocated to the file by the operating system. After opening the booting the system, if this is the first program to be run, then will give 3. Generally, the FD allocated will be greater than 3. 0 is standard input. 1 is standard output. And 2 is standard error. 45. What is the output of the code when “i.txt” does not exists? (L1) void main() { char s[10]; int fd1=open(“i.txt”,O_RDONLY); printf(“%d”,fd1); } (a) 0 (b) 1 (c) 2 (d) None of the above Answer: (d) It gives –1, as the file is not present. 46. State true or false. (L2) i. txt will be created after the program is executed. (assume “i.txt” doesn’t exist before) void main() { char s[10]; int fd1=open(“i.txt”,O_WRONLY); printf(“%d”,fd1); } (a) True (b) False Answer: (b) Unlike normal ‘C’ functions, these system calls doesn’t create any new file. 47. What is the output of the code when “i.txt” does not exist? (L2) void main() { char s[10]; int fd1=open(“i.txt”,O_RDONLY| O_CREAT,0777); printf(“%d”,fd1); } (a) Corresponding FD (b) –1 (c) Error (d) None of the above Answer: (a) There can be multiple flags used with this system call. Here the new flag ‘O_CREAT’ is used to create the file if it is not existing. And the ‘0777’ given in supplement to this flag is used as the access permission for the newly created file.
8 Cracking the Operating Systems Skills
48. What is the output of the code when “i.txt” has “hai hello”? (L2) void main() { char s[10]; int fd1=open(“i.txt”,O_RDONLY| O_CREAT,0777); read(fd1,s,10); printf(“%s”,s); } (a) hai hello (b) Segmentation fault (c) Error (d) None of the above Answer: (a) ‘read’ is a system call that reads the data from the specified file descriptor. The third argument is the number of characters to be read and the second argument is the buffer name. 49. What is the output of the code when “i.txt” has “hai hello”? (L3) void main() { char s[10]; char s1[4]= “bye”; int fd1=open(“i.txt”,O_RDWR); write(fd1,s1,3); read(fd1,s,10); printf(“%s”,s); } (a) bye hello (b) bye hai hello (c) Error (d) None of the above Answer: (d) It will give ‘hello’. ‘RDWR’ means read and write mode. ‘read’ function call reads the specified number of characters only from the current reader position. ‘write’ function call writes the specified characters of buffer data into the specified FD. But as any other function, ‘write’ just overwrites the contents in the file (if they clash). 50. What is the output of the code when “i.txt” exists? (assume fd1 is 3) (L2) void main() { int fd1=open(“i.txt”,O_RDONLY); int fd2=dup(fd1); printf(“%d”,fd2); } (a) 3 (b) 4 (c) Error (d) None of the above Answer: (b) ‘dup()’ is a system call that duplicates a file opened in the corresponding file descriptor. It places the duplicate in the next available FD. So will get 4 only. 51. Computers store data on disks using (L1) (a) Database (b) Computer storage (c) Soft copy (d) Files Answer: (d) Files
Introduction 9
52. The specific way in which files are stored on a disk is called a (L1) (a) Database (b) Storage system (c) File system (d) All of the above Answer: (c) File system 53. Files allow data to be stored in a hierarchy of directories or folders arranged in a (L2) (a) Graph (b) Database (c) Binary tree (d) Directory tree Answer: (d) Directory tree 54. A ________ switch is an abstraction layer on top of a more concrete file system. (L3) (a) Virtual file system (VFS) (b) Regular file system (c) Real file system (d) All of the above Answer: (a) Virtual file system (VFS) 55. The purpose of a VFS is to allow client applications to access different types of concrete file systems in a ________ way. (L2) (a) Distributed (b) Uniform (c) Both uniform and distributed (d) Random Answer: (b) Uniform 56. A connected storage device, such as a hard drive, is accessed through a (L1) (a) User driver (b) Device driver (c) Application driver (d) All of the above Answer: (b) Device driver 57. A device driver is a specific type of computer software developed to allow interaction with (L1) (a) Hybrid devices (b) Software devices (c) Hardware devices (d) None of the above Answer: (c) Hardware devices 58. The key design goal of device drivers is (L1) (a) Virtualise (b) User preference (c) Hardware devices (d) Abstraction Answer: (d) Abstraction 59. The function of the ________ is to translate operating system mandated function calls into device specific calls. (L1) (a) Application driver (b) Device driver (c) User driver (d) All of the above Answer: (b) Device driver
10 Cracking the Operating Systems Skills
60. Computers running dissimilar operating systems can participate in a common ________ for sharing resources (L1) (a) Network (b) Storage (c) Web (d) All of the above Answer: (a) Network 61. Networking allows a program on a computer, called a ________, to connect via a network to another computer, called a ________. (L1) (a) Client, Server (b) User, Application (c) Source, Destination (d) Producer, Consumer Answer: (a) Client, Server 62. A modern operating system provides access to a number of resources and needs (L1) (a) Hardware (b) User (c) Security (d) Application Answer: (c) Security 63. Every computer that is to be operated by an individual requires a (L1) (a) System interface (b) User interface (c) No interface (d) Library interface Answer: (b) User interface 64. The user interface is usually referred to as a ________ and is essential if human interaction is to be supported. (L1) (a) Shell (b) Application (c) Kernel (d) Software Answer: (a) Shell 65. Which of the following are input hardware devices? (L1) (a) Keyboard (b) Mouse (c) Card reader (d) All of the above Answer: (d) All of the above 66. The most common forms of a user interface have historically been the (L1) (a) Command line interface (b) Graphical user interface (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 67. A real-time operating system is an operating system intended for applications with (L1) (a) Fixed deadlines (b) Random deadlines (c) No deadline (d) Multiple deadlines Answer: (a) Fixed deadlines
Introduction 11
68. The CPU can load instructions only from ________, so any programs to run must be stored there. (L1) (a) Keyboard (b) Memory (c) Mouse (d) Monitor Answer: (b) Memory 69. The main requirement for secondary storage is that it should be able to hold large quantity of data (L1) (a) Never erasable thereafter (b) Few seconds (c) Temporarily (d) Permanently Answer: (d) Permanently 70. The goals of the operating system are to (L1) (a) Execute user programs and make solving user problems easier (b) Make the computer system convenient to use (c) Use the computer hardware in an efficient manner (d) All of the above Answer: (d) All of the above 71. Operating system is a: (L1) (a) Resource allocator (c) Both a and b Answer: (c) Both a and b
(b) Control program (d) Neither a nor b
72. I/O devices and the CPU can execute (L1) (a) At different times only (b) Concurrently (c) On sleep state (d) Based on time and space Answer: (b) Concurrently 73. Interrupt transfers control to the interrupt service routine generally, through the (L1) (a) Interrupt vector (b) Scalar (c) Stack (d) Interrupt service routine Answer: (a) Interrupt vector 74. Interrupt architecture must save the ________ of the interrupted instruction (L1) (a) Address (b) Data (c) Control (d) Time Answer: (a) Address 75. A ________ is a software generated interrupt (L1) (a) Mask (b) Router (c) Trap Answer: (c) Trap
(d) Timer
12 Cracking the Operating Systems Skills
76. An operating system is ________ (L1) (a) Data driven (c) Architecture driven Answer: (b) Interrupt driven
(b) Interrupt driven (d) Time driven
77. Main memory is ________ storage device (L1) (a) Data (b) Not (c) Non-volatile (d) Volatile Answer: (d) Volatile 78. A ________ is a computer application for controlling unattended background program execution (L1) (a) Software (b) Job scheduler (c) Task (d) Compiler Answer: (b) Job scheduler 79. Processes are ________ in and out of main memory to the disk (L1) (a) Swapped (b) Maintained (c) Closed (d) Discontinued Answer: (a) Swapped 80. Operating system and the users share ________ resources of the computer system (L1) (a) Firmware (b) Software (c) Hardware (d) Both b and c Answer: (d) Both b and c 81. A bit, called the ________ is added to the hardware of the computer to indicate the current mode: kernel (0) or user (1). (L2) (a) User bit (b) Kernel bit (c) Mode bit (d) Application Answer: (c) Mode bit 82. With the mode bit, we are able to distinguish between a task that is executed on behalf of the ________ and one that is executed on behalf of the ________ (L1) (a) Hardware, Software (b) Operating system, User (c) Kernel, Hardware (d) Application, Thread Answer: (b) Operating system, User 83. A user application requests a service from the operating system via a ________ (L1) (a) System call (b) User call (c) Kernel call (d) Thread call Answer: (a) System call 84. At system boot time, the hardware starts in ________ (L1) (a) Application mode (b) User mode (c) Kernel mode (d) No mode Answer: (c) Kernel mode
Introduction 13
85. Operating system is loaded and starts user applications in ________ mode. (L1) (a) Kernel mode (b) User mode (c) Application mode (d) No mode Answer: (b) User mode 86. The hardware allows privileged instructions to be executed only in ________ (L1) (a) Kernel mode (b) User mode (c) Application mode (d) No mode Answer: (a) Kernel mode 87. The dual mode of operation provides us with the means for ________ the operating system from errant user (L1) (a) Releasing (b) Protecting (c) Exposing (d) Nothing to Answer: (b) Protecting 88. Example of a privileged instruction is ________ (L1) (a) I/O control (b) Timer management (c) Interrupt management (d) All of the above Answer: (d) All of the above 89. When a system call is executed it is treated by the hardware as a ________ (L1) (a) Low priority call (b) Hardware interrupt (c) Software interrupt (d) Thread Answer: (c) Software interrupt 90. Additional information needed for the interrupt request may be passed in ________ (L1) (a) Registers on stack (b) Memory (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 91. ________ has no mode bit and therefore no dual mode. (L2) (a) MS-DOS written for Intel 8088 architecture (b) PC DOS (c) ROM-DOS (d) Free DOS Answer: (a) MS-DOS written for Intel 8088 architecture 92. To accomplish the goal of user program not to get stuck in infinite loop or to fail to call system services and never return control to operating system, we use ________ (L1) (a) Crystal (b) Timer (c) Memory (d) Lock Answer: (b) Timer
14 Cracking the Operating Systems Skills
93. A timer can be set to interrupt the computer after a ________ period. (L1) (a) Thread end (b) Day (c) Specified (d) Variable Answer: (c) Specified 94. A variable timer is generally implemented by a ________ and a ________ (L1) (a) Variable clock, Timer (b) Timer, Counter (c) Watch, Clock (d) Fixed rate clock, Counter Answer: (d) Fixed rate clock, Counter 95. The ________ sets the counter to decrement on every clock tick. (L1) (a) Operating system (b) User application (c) Utility software (d) Hardware Answer: (a) Operating system 96. A process needs ________ resources to accomplish its tasks (L1) (a) CPU time (b) Memory (c) Files and I/O devices (d) All of the above Answer: (d) All of the above 97. Resources are given to the process when it is ________ (L1) (a) Running (b) Created (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 98. When the process terminates, the operating system will ________ any reusable resources. (L1) (a) Create (b) Reclaim (c) Not reclaim (d) Destroy Answer: (b) Reclaim 99. A program is a ________ entity while a process is a ________ entity. (L1) (a) Active, Passive (b) Passive, Active (c) Useless, Useful (d) Negative, Positive Answer: (b) Passive, Active 100. A single threaded process has ________ program counter specifying the next instruction to execute. (L1) (a) One (b) Two (c) Three (d) Many Answer: (a) One 101. The execution of a single threaded process must be ________ (L1) (a) Alternative (b) Random (c) Sequential (d) None of the above Answer: (c) Sequential
Introduction 15
102. As per multithreaded process has ________ program counters, each pointing to the next instruction to execute for a given thread. (L2) (a) Single (b) Multiple (c) Two (d) No Answer: (b) Multiple 103. Which of the following are system processes (L1) (a) Operating system processes (b) User processes (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 104. Operating system processes and system processes can potentially execute (L1) (a) In sequence only (b) In random fashion (c) Concurrently (d) In sleep state Answer: (c) Concurrently 105. In connection with process management, OS is responsible for: (L1) (a) Scheduling processes and threads on the CPUs (b) Creating and deleting both user and system processes (c) Suspending and resuming processes (d) All of the above Answer: (d) All of the above 106. Main memory is a repository of quickly accessible data shared by the(L1) (a) CPU and I/O devices (b) Primary memory and secondary memory (c) Cache and memory (d) None of the above Answer: (a) CPU and I/O devices 107. The computer has single storage system for storing data as well as program to be executed as per ________ architecture. (L1) (a) Harvard (b) Von Neumann (c) Any computer (d) Split cache architecture Answer: (b) Von Neumann 108. ________ is not possible with Von Neumann architecture (L1) (a) Programming (b) Application (c) Sequencing (d) Pipelining Answer: (d) Pipelining
16 Cracking the Operating Systems Skills
109. As per Harvard architecture, computer has two separate memories for storing ________ (L1) (a) Multiple data (b) Many programs (c) Data and program (d) Address and data Answer: (c) Data and program 110. Number of stages in the pipeline is ________ (L1) (a) Fixed (b) Varies from system to system (c) Runtime configurable (d) None of the above Answer: (b) Varies from system to system 111. In connection with file management, OS is responsible for ________ (L1) (a) Creating and deleting files (b) Creating and deleting directories to organize files (c) Mapping files onto secondary storage (d) All of the above Answer: (d) All of the above 112. In connection with disk management, OS is responsible for ________ (L1) (a) Free space management (b) Storage allocation (c) Disk scheduling (d) All of the above Answer: (d) All of the above 113. Information normally kept in some storage system, when used is copied into a faster storage system called ________ (L1) (a) Compact disc (b) Caching (c) Secure digital card (d) RAM Answer: (b) Caching 114. Consistency of shared resource data that ends up stored in multiple local caches is called ________ (L2) (a) Cache coherency (b) Non-caching (c) Memory barrier (d) RAM Answer: (a) Cache coherency 115. Only the ________ knows the peculiarities of the specific device to which it is assigned. (L1) (a) Hardware (b) Cache (c) Device driver (d) Application Answer: (c) Device driver
Introduction 17
116. ________ is any mechanism for controlling the access of processes or users-to the resources defined by a computer system. (L1) (a) Software (b) Hardware (c) Device driver (d) Protection Answer: (d) Protection 117. The job of “security” to defend a system from (L1) (a) Viruses and worms (b) Denial-of-service attacks (c) Identity theft (d) All of the above Answer: (d) All of the above 118. A ________ is a collection of physically separate, possibly heterogeneous, computer systems (L1) (a) Software system (b) Server (c) Distributed system (d) All of the above Answer: (c) Distributed system 119. A ________ in the simplest terms is a communication path between two or more systems. (L1) (a) Application (b) Software (c) Network (d) Kernel Answer: (c) Network 120. Distributed systems depend on ________ for their functionality. (L1) (a) Networking (b) Software (c) Hardware (d) Application Answer: (a) Networking 121. The most common network protocols are: (L1) (a) TCP/IP (b) ARP (c) DHCP Answer: (d) All of the above
(d) All of the above
122. A network that connects computers within a room, a floor or a building is ________ (L1) (a) WAN (b) LAN (c) MAN (d) SAN Answer: (b) LAN 123. A ________ is a telecommunications network or computer network that extends over a large geographical distance. (L1) (a) WAN (b) IAN (c) SAN (d) LAN Answer: (a) WAN
18 Cracking the Operating Systems Skills
124. A ________ is a computer network larger than a LAN, covering an area of a few city blocks to the area of an entire city, possibly also including the surrounding areas. (L1) (a) Big LAN (b) MAN (c) NFC (d) SAN Answer: (b) MAN 125. A storage area network (SAN) is a network that provides access to consolidated ________ (L2) (a) Character devices (b) Cache systems (c) Block level data storage (d) Pseudo-devices Answer: (c) Block level data storage 126. In computing, a ________ is a computer program that operates or controls a particular type of device that is attached to a computer. (L1) (a) Kernel (b) Software (c) Application (d) Device driver Answer: (d) Device driver 127. A driver provides a ________ to hardware devices, enabling operating systems and other computer programs to access hardware functions (L1) (a) Application interface (b) Software interface (c) Hardware interface (d) No interface Answer: (b) Software interface 128. A driver typically communicates with the device through the ___ to which the hardware connects. (L1) (a) Network (b) Application (c) Computer bus (d) Software Answer: (c) Computer bus 129. A ________ provide unbuffered, direct access to the hardware device. (L1) (a) Character device (b) Block device (c) Both a and b (d) Neither a nor b Answer: (a) Character device 130. Block devices provide ________ access to the hardware, such that the hardware characteristics of the device are not visible. (L1) (a) Network (b) Buffered (c) Random (d) Aligned data Answer: (b) Buffered
Introduction 19
131. Nodes are created by ________ system call (L1) (a) Open (b) Exec (c) Mknod Answer: (c) Mknod
(d) Fork
132. Which of the following are character devices? (L1) (a) Serial and parallel ports (b) Hard disks (c) USB cameras (d) All of the above Answer: (a) Serial and parallel ports 133. Which of the following are block devices (L1) (a) USB cameras (b) Hard disks (c) Disk on key (d) All of the above Answer: (d) All of the above 134. Embedded computers are found in (L1) (a) Microwave ovens (b) Car (c) Robots (d) All of the above Answer: (d) All of the above 135. Embedded systems almost always run (L1) (a) Real-time operating system (b) Network operating system (c) Distributed operating system (d) All of the above Answer: (a) Real-time operating system 136. An RTOS has an advanced algorithm for (L1) (a) Cache (b) Memory (c) Scheduling (d) Networking Answer: (c) Scheduling 137. Key factors in a real-time OS are (L2) (a) Minimal interrupt latency (c) Quick response Answer: (d) All of the above
(b) Minimal thread switching latency (d) All of the above
138. In hard real-time systems ________ is limited or missing (L1) (a) Primary storage (b) Secondary storage (c) Cache (d) Processor Answer: (b) Secondary storage 139. Soft real-time systems have ________ utility than hard real-time systems. (L1) (a) All (b) No (c) Advanced (d) Limited Answer: (d) Limited
20 Cracking the Operating Systems Skills
140. Multimedia data consist of (L1) (a) Image (c) Video data Answer: (d) All of the above
(b) Audio files (d) All of the above
141. Special-purpose embedded operating systems are found in ________ (L1) (a) Palm and pocket PCs (b) Cellular phones (c) Tablet computer (d) All of the above Answer: (d) All of the above 142. Most handheld devices have (L1) (a) Small amount of memory and slow processors (b) Small display screens (c) Both a and b (d) High end processors with huge memory Answer: (c) Both a and b 143. The amount of physical memory in a handheld depends on the device, but typically it is somewhere between (L1) (a) 1 MB and 1 GB (b) 1 GB and 10 GB (c) 10 GB and 1 TB (d) Any size Answer: (d) Any size, depends on the manufacturer like smart phones even have 128 GB memory. 144. The ________ provides an interface to which a client can send a request and in response, the server executes the action and sends back results to the client. (L1) (a) Network (b) Computer server system (c) Application (d) File-server system Answer: (b) Computer server system 145. The ________ provides a file-system interface where clients can create, update, read, and delete files. (L1) (a) File server system (b) Computer server system (c) GUI (d) Network Answer: (a) File server system 146. In peer-to-peer (P2P) system model, ________ and ________ are not distinguished from one another. (L1) (a) Kernel and user (b) Application and user (c) Client and server (d) One user and another Answer: (c) Client and server
Introduction 21
147. Open source operating systems are those made available in ________ format (L1) (a) Binary code (b) Source code (c) Hex code (d) pdf Answer: (b) Source code 148. Which of the following is open source operating system (L1) (a) Linux (b) Windows (c) Mac OS (d) All of the above Answer: (a) Linux 149. Which of the following is closed source operating system (L1) (a) Android (b) Linux (c) Windows (d) All of the above Answer: (c) Windows 150. ________ is generating source code from binaries (L1) (a) Forward engineering (b) Reverse engineering (c) Application development (d) Compilation Answer: (b) Reverse engineering
2
Operating System Services
OSes provide environments in which programs run, and services for the users of the system. This chapter covers most of the operating system structures and services. 1. Almost all operating systems have a ________ (L1) (a) Multi-threading (b) Keyboard (c) Open source code (d) User interface Answer: (d) User interface 2. A ________ interface is one in which commands and directives to control those commands are entered into files, and those files are executed. (L1) (a) File (b) Batch (c) Thread (d) User Answer: (b) Batch 3. The program must be able to end its execution ________ (L1) (a) Normally (b) Abnormally indicating error (c) Either a or b (d) Both a and b Answer: (c) Either a or b 4. A running program may require I/O, which may involve a ________ (L1) (a) File (b) I/O device (c) Either a or b (d) Neither a nor b Answer: (c) Either a or b 5. Communications between processes may be implemented via ________ (L1) (a) Sharing memory (b) Network (c) Sharing cache (d) Serial ports Answer: (a) Sharing memory 6. Errors may occur in ________ (L2) (a) CPU and memory hardware (c) User program Answer: (d) All of the above
(b) I/O devices (d) All of the above
Operating System Services 23
7. When there are multiple users or multiple jobs running at the same time, ________ must be allocated to each of them. (L1) (a) Compiler (b) Resources (c) Debugger (d) Network Answer: (b) Resources 8. On systems with multiple command interpreters to choose from, the interpreters are known as (L1) (a) Class (b) Objects (c) Applications (d) Shells Answer: (d) Shells 9. The main function of the ________ is to get and execute the next user-specified command. (L1) (a) Debugger (b) Assembler (c) Command interpreter (d) Compiler Answer: (c) Command interpreter 10. A mouse-based window and menu system is called ________ interface (L1) (a) Graphical user (b) Command line user (c) Batch user (d) Debugger Answer: (a) Graphical user 11. ________ provides an interface to the services made available by an operating system (L1) (a) Application calls (b) System calls (c) Any software API (d) Hardware Answer: (b) System calls 12. The most common API’s available to application programmers are (L3) (a) WIN32 APIs (b) POSIX API (c) JAVA API (d) All of the above Answer: (d) All of the above 13. Which of the following is a system call (L2) (a) CreateProcess() (b) NTCreateProcess() (c) Process() (d) All of the above Answer: (b) NTCreateProcess() 14. A ________ is associated with each system maintains a table indexed according to them. (a) Number (b) (c) Special character (d) Answer: (a) Number
call, and the system-call interface (L1) Character Storage
24 Cracking the Operating Systems Skills
15. Which of the following methods are used to pass parameters to the operating system? (L1) (a) Through registers (b) Block or table in memory (c) Push and pop off the stack (d) All of the above methods Answer: (d) All of the above methods 16. Which of the following is a type of system call (L2) (a) Process control (b) File and device manipulation (c) Communications and protection (d) All of the above Answer: (d) All of the above 17. The dump is written to disk and may be examined by a (L2) (a) Compiler (b) Software (c) Debugger (d) Application Answer: (c) Debugger 18. Which of the following is a UNIX process control system call? (L2) (a) Fork() (b) Open() (c) Ioctl() (d) Pipe() Answer: (a) Fork() 19. Which of the following is a UNIX file manipulation system call? (L3) (a) Read() (b) Exit() (c) alarm() (d) mmap() Answer: (a) Read() 20. Which of the following is a UNIX communication system call? (L2) (a) getpid() (b) close() (c) mmap() (d) sleep() Answer: (c) mmap() 21. Which of the following is a Windows protection system call? (L2) (a) CreateProcess() (b) SetSecurityDescriptorGroup() (c) CreateFile () (d) MapViewOfFile () Answer: (b) SetSecurityDescriptorGroup() 22. If we create a new job or process, or perhaps even a set of jobs or processes, we should be able to ________ its execution. (L2) (a) Kill (b) Create (c) Control (d) Master Answer: (c) Control 23. ________ is an example of a multitasking system. (L2) (a) FreeBSD (b) MSDOS (c) Both a and b (d) Neither a nor b Answer: (a) FreeBSD
Operating System Services 25
24. To start a new process, the shell executes a ____ system call. (L2) (a) Read (b) Alarm (c) Wait (d) Fork Answer: (d) Fork 25. The selected program is loaded into the memory via ________ system call. (L2) (a) Write (b) Exec (c) Sleep (d) Exit Answer: (b) Exec 26. What is the output of the code when “i.txt” exists? (assume fd1 is 3) (L2) void main() { int fd1=open(“i.txt”,O_RDONLY); close(2); int fd2=dup(fd1); printf(“%d”,fd2); } (a) 2 (b) 4 (c) Error (d) None of the above Answer: (a) ‘close’ is a system call that closes the file corresponding to the descriptor. If it is a primary or default process, it will be opened automatically on the next boot. Now the available FDs will be 2,4,5,… So ‘2’ will be allocated to the duplicate file. 27. What is the output of the code when “i.txt” exists? (assume fd1 is 3)? (L2) void main() { int fd1=open(“i.txt”,O_RDONLY); close(2); int fd2=dup2(fd1,5); printf(“%d”,fd2); } (a) 2 (b) 4 (c) 5 (d) None of the above Answer: (c) ‘dup2’ is a system call that copies the FD into the specified FD number. It may also leave some in between FDs. Say here it leaves 4 in between. 28. What is the output of the code when “i.txt” exists? (assume fd1 is 3) (L2) void main() { int fd1=open(“i.txt”,O_RDONLY); int fd2=dup2(fd1,5); int fd3=dup(fd1); printf(“%d”,fd3); } (a) 6 (b) 4 (c) 5 (d) None of the above Answer: (b) As 4 is left in between by the dup2, the lateral dup opens in 4.
26 Cracking the Operating Systems Skills
29. What is the output of the code when “i.txt” exists? (assume fd1 is 3) (L2) void main() { int fd1=open(“i.txt”,O_RDONLY); int fd2=dup2(fd1,2); printf(“%d”,fd2); } (a) 2 (b) 4 (c) –1 (d) Error Answer: (a) Here ‘dup2’ automatically closes ‘2’ and opens the duplicate in there. 30. What is the output of the code when “i.txt” has “bye” and “hai.txt” has “hai”? (L3) void main() { int fd1=open(“i.txt”,O_RDONLY); int fd2= open(“hai.txt”,O_RDONLY); char s1[5],s[5]; write(fd2, (read (fd1,s,3)),3); read(fd2,s1,3); printf(“%s”,s1); } (a) hai (b) Bye (c) Segmentation Fault (d) Error Answer: (a) Sometimes it may be followed by some garbage values. The second argument of ‘write’ must be a buffer or value holder. But the ‘read’ doesn’t actually return the buffer after copying. It just returns an instance of ‘size_t’ type, the number of characters is returned. So here the argument is not compatible, and hence the ‘write’ doesn’t works. Still as it is a function call, it alters by itself and skips the operation. So finally again the same ‘hai’ is read and printed. The garbage values are due to some extra length. 31. What is the output of the code when “hai.txt” has “hai”? (L2) void main() { int fd1=open(“hai.txt”,O_RDONLY); int fd2= fcntl(fd1,F_DUPFD,0); char s1[5]; read(fd2,s1,3); printf(“%s”,s1); } (a) hai (b) Garbage value (c) Segmentation fault (d) Error Answer: (a) ‘fcntl’ is a system call that can act as any other system call using the corresponding flag. Here ‘fcntl’ is converted into ‘fdup’. ‘F_DUPFD’ is the flag for ‘dup’.
Operating System Services 27
32. What is the output of the code when “hai.txt” exists? (L2) void main() { int fd1=open(“hai.txt”,O_RDONLY); int fd2= fcntl(fd1,F_GETFL); if(fd2==O_RDONLY) printf(“read”); } (a) Read (b) Prints nothing (c) Segmentation fault (d) Error Answer: (a) ‘F_GETFL’ is the flag that reads the status of the file. File status flags are ‘O_APPEND’, ‘O_NONBLOCK’. 33. What is the output of the code when “hai.txt” has access mode 0777? (L2) void main() { int fd1=open(“hai.txt”,O_RDONLY); int fd2= fcntl(fd1,F_GETFL); if(fd2==O_APPEND) printf(“append ”); else if(fd2==O_NONBLOCK) printf(“nonblack ”); } (a) Append (b) Nonblock (c) Append nonblock (d) None of the above Answer: (d) It prints nothing. The output of ‘F_GETFL’ is a positive number. It is formed as a result of the bitwise ‘OR’ operation over the file status flags like ‘O_ APPEND’, ‘O_NONBLOCK’ and other bits of ‘O_ACCMODE’. The value may be default value or can be edited using the same ‘fcntl’ with different flag. 34. What is the hex value of ‘O_APPEND’ flag? (L2) (a) 400 (b) 800 (c) 200 (d) None of the above Answer: (a) In O_APPEND mode the reader of the file will be set to the end of the file and the user can append data into it. 35. What is the hex value of ‘O_NONBLOCK’ flag? (L2) (a) 400 (b) 800 (c) 200 (d) None of the above Answer: (b) This to open the program and all its function in non-blocking mode. It means no function can cause a delay and should return a value immediately. 36. File attribute includes ________ (L1) (a) File name and type (c) Accounting information Answer: (d) All of the above
(b) File protection codes (d) All of the above
28 Cracking the Operating Systems Skills
37. The various resources controlled by the operating system can be thought of as (L1) (a) Applications (b) Software units (c) Devices (d) Hardware units Answer: (c) Devices 38. Many system calls exist simply for the purpose of transferring information between the ________ and ________ (L2) (a) Application and hardware (b) User program and OS (c) Hardware and software (d) Application 1 and application 2 Answer: (b) User program and OS 39. Which of the following is a common model of inter-process communication? (L2) (a) Message passing (b) Shared memory (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 40. Messages can be exchanged between the processes ___ through a common mailbox. (L2) (a) Directly (b) Indirectly (c) Either a or b (d) Neither a nor b Answer: (c) Either a or b 41. In the ________, processes uses shared memory create and shared memory attach system calls to create and gain access to regions of memory owned by other processes. (L2) (a) Shared-memory model (b) Message-passing model (c) Networking model (d) All of the above models Answer: (a) Shared memory model 42. ________ programs create, delete, copy, rename, print, dump, list, and generally manipulate files and directories. (L2) (a) Networking (b) File management (c) File modification (d) Storage Answer: (b) File management 43. Programming-language support include: (L1) (a) Compilers (b) Assemblers (c) Debuggers and interpreters (d) All of the above Answer: (d) All of the above
Operating System Services 29
44. Program loading happens through (L1) (a) Absolute or relocatable loaders (c) Debuggers and interpreters Answer: (a) Absolute or relocatable loaders
(b) Compilers (d) Assemblers
45. Communication programs provide the mechanism for (L2) (a) Creating virtual connections among processes (b) Send messages (c) To log in remotely (d) All of the above Answer: (d) All of the above 46. Application programs include (L2) (a) Compilers and assemblers (b) Web browsers and word processors (c) Debuggers and interpreters (d) All of the above Answer: (b) Web browsers and word processors 47. The first problem in designing a system is to (L2) (a) Write software (b) Debug issues (c) Define goals and specifications (d) All of the above Answer: (c) Define goals and specifications 48. Traditionally, operating systems are written in ________ (L1) (a) Assembly language (b) High level language (c) Middle level language (d) Any language Answer: (a) Assembly language 49. C Language is ________ (L1) (a) Assembly language (b) High level language (c) Middle level language (d) Any language Answer: (c) Unlike other programming languages, C language is not a high level language. It binds the gap between operating system and programming and thus it is a middle level language. 50. The Linux and Windows XP operating systems are written mostly in ________ (L1) (a) Visual Basic (b) C Language (c) JAVA language (d) COBOL Answer: (b) C language 51. The advantage of using a higher level language for implementing operating systems is ________ (L2) (a) Code can be written faster (b) Is more compact (c) Easy to understand and debug (d) All of the above Answer: (d) All of the above
30 Cracking the Operating Systems Skills
52. An operating system is far easier to ________ if it is written in a higher level language (L2) (a) Port (b) Compile (c) Interpret (d) All of the above Answer: (a) Port 53. The disadvantage of implementing an operating system in a higher level language is ________ (L1) (a) Reduced speed (b) Increased storage requirements (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 54. A modern compiler can perform ________ (L1) (a) Complex analysis and sophisticated optimizations (b) Simple analysis (c) Reduced hardware (d) All of the above Answer: (a) Complex analysis and sophisticated optimizations 55. The most critical units are ________ (L1) (a) Memory manager (b) CPU scheduler (c) Interrupt handler (d) All of the above Answer: (d) All of the above 56. In MS-DOS, the interfaces and levels of functionality are ________ (L2) (a) Written in an efficient way (b) Not well separated (c) Easy to debug (d) Well separated Answer: (b) Not well separated 57. In MS-DOS, application program ________ the basic I/O routines to write directly (L2) (a) Cannot access (b) Well separates (c) Can access (d) Are same as Answer: (c) Can access 58. UNIX and MSDOS were initially limited by ________ (L2) (a) Hardware functionality (b) Software functionality (c) Applications (d) Networking Answer: (a) Hardware functionality
Operating System Services 31
59. Everything below the system-call interface and above the physical hardware is the (L1) (a) Application (b) Kernel (c) Library (d) Framework Answer: (b) Kernel 60. The kernel provides the ________ (L1) (a) File system (b) Memory management (c) CPU scheduling (d) All of the above Answer: (d) All of the above 61. In ________ approach, the operating system is broken into a number of layers or levels (L1) (a) Layered (b) Modular (c) Kernel (d) Software Answer: (a) Layered 62. The main advantage of the layered approach is ____ (L1) (a) Simplicity of construction (b) Debugging (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 63. In ________ approach, all nonessential components are removed from the kernel and implemented as system and user level programs (L2) (a) Layered (b) Macrokernel (c) Microkernel (d) Monolithic kernel Answer: (c) Microkernel 64. The main functionality of the microkernel is to provide a ________ facility between the client program and the various services running in user space (L1) (a) Communication (b) Interrupt (c) Application (d) Debugging Answer: (a) Communication 65. The microkernel provides ________ (L1) (a) Security (b) Reliability (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 66. In microkernel most services run in ________ (L1) (a) Kernel space (b) User space (c) Hardware (d) BIOS Answer: (b) User space
32 Cracking the Operating Systems Skills
67. In microkernel if a service fails, the rest of the operating system ________ (L1) (a) Crashes (b) Remains untouched (c) Stops executing (d) Will start from first Answer: (b) Remains untouched 68. The QNX microkernel provides ________ (L2) (a) Services for message passing (b) Process scheduling (c) Low level network communication (d) All of the above Answer: (d) All the above 69. Microkernels can suffer from ________ (L1) (a) Performance decrease (b) Increased system function overhead (c) High user space (d) All of the above Answer: (d) All the above 70. The best current methodology for operating system design involves ________ (L1) (a) Object-oriented programming (b) Sequential programming (c) Multithreading (d) All of the above Answer: (a) Object-oriented programming 71. The fundamental idea behind a virtual machine is to abstract the ________ of a single computer into several different execution environments (L1) (a) Software (b) Hardware (c) Firmware (d) All of the above Answer: (b) Hardware 72. By using ________ an operating system can create the illusion that a process has its own processor with its own (virtual) memory. (L1) (a) CPU scheduling (b) Virtual-memory techniques (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 73. The virtual machine provides an interface that is ________ to the underlying bare hardware. (L1) (a) Identical (b) Different (c) Partially same (d) Partially different Answer: (a) Identical 74. A major difficulty with the VM virtual machine approach involved ________ (L1) (a) Networking (b) Scheduling (c) Interrupts (d) Disk systems Answer: (d) Disk systems
Operating System Services 33
75. One important advantage of virtual machines is that the ________ (L1) (a) Host system is protected from the VM (b) VMs are protected from each other (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 76. A virus inside a guest operating system might damage that ________ (L2) (a) Operating system (b) Host machine (c) Guests (d) All of the above Answer: (a) Operating system 77. Since each virtual machine is completely isolated from all other virtual machines, there are no ________ problems (L1) (a) Network (b) Memory (c) Protection (d) All of the above Answer: (c) Protection 78. Sharing of resources in VM happens through ________ (L2) (a) Sharing a file system volume (b) Sending information over the virtual communications network (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 79. ________ becomes simpler in virtual machine concept (L2) (a) System development time (b) Application development time (c) Hardware testing time (d) All of the above Answer: (a) System development time 80. The virtualized workstation allows for rapid ________ of programs in varying environments. (L2) (a) Development (b) Porting (c) Testing (d) All of the above Answer: (d) All of the above 81. Physical-to-virtual conversions result in ________ optimization, as many lightly used systems can be combined to create one more heavily used system. (L1) (a) People (b) Resource (c) Network (d) All of the above Answer: (b) Resource
34 Cracking the Operating Systems Skills
82. ________ is the most common because it makes guest operating systems and applications “believe” they are running on native hardware. (L1) (a) Networking (b) Software (c) Virtualization (d) Memory Answer: (c) Virtualization 83. ________ is one in which the host system has one system architecture and the guest system was compiled for a different architecture. (L2) (a) Virtual machine (b) Simulation (c) Caching (d) Operating system Answer: (b) Simulation 84. Emulation can increase the life of programs and allow us to explore old architectures without having an actual old machine, but its major challenge is ________ (L1) (a) Performance (b) Simulation (c) Cost (d) All of the above Answer: (a) Performance 85. Emulation challenge is that it is difficult to create a correct emulator because, in essence, this involves writing an entire ________ (L1) (a) Application (b) CPU in firmware (c) CPU in hardware (d) CPU in software Answer: (d) CPU in software 86. The virtual machine software can run in ________ mode, since it is the operating system. (L1) (a) Kernel (b) User (c) Hardware (d) Any of the above Answer: (a) Kernel 87. In VM concept, we must have a virtual user mode and a virtual kernel mode, both of which run in a ________ (L1) (a) Application space (b) Kernel mode (c) Physical user mode (d) Any of the above Answer: (c) Physical user mode 88. The real I/O might have taken 100 milliseconds, the virtual I/O might take less time because it is ________ (L1) (a) Interpreted (b) Spooled (c) Has more memory (d) All of the above Answer: (b) Spooled
Operating System Services 35
89. Original I/O might have taken some milliseconds, the virtual I/O might take more time than that because it is ________ (L1) (a) Spooled (b) Costlier (c) Interpreted (d) All of the above Answer: (c) Interpreted 90. AMD virtualization technology is found in several AMD processors which defines two new modes of operation ________ (L1) (a) Host and guest (b) User and kernel (c) Application and kernel (d) Any of the above Answer: (a) Host and guest 91. If the guest tries to access a virtualized resource, then control is passed to the ________ to manage that interaction. (L1) (a) Guest (b) Host (c) User (d) Application Answer: (b) Host 92. ________ is a popular commercial application that abstracts Intel X86 and compatible hardware into isolated virtual machines. (L2) (a) Windows (b) Ubuntu (c) Java (d) VMware workstation Answer: (d) VMware workstation 93. The ________ layer is the heart of VMware, as it abstracts the physical hardware into isolated virtual machines running as guest operating systems. (L1) (a) Virtualization (b) Software (c) Hardware (d) Application Answer: (a) Virtualization 94. Each virtual machine has its own virtual ________ and so forth. (L1) (a) CPU (b) Memory and disk drives (c) Network interfaces (d) All of the above Answer: (d) All of the above 95. The ________ is a specification for an abstract computer. (L1) (a) VMware (b) Application (c) Java virtual machine (d) All of the above Answer: (c) Java virtual machine 96. The JVM may be implemented in software on top of a ________ (L1) (a) Host operating system (b) Web browser (c) Hardware on a chip (d) Any one of the above Answer: (d) Any one of the above
36 Cracking the Operating Systems Skills
97. If the JVM is implemented in software, the ________ interprets the bytecode operations one at a time. (L1) (a) Java interpreter (b) Compiler (c) Either a or b (d) Neither a nor b Answer: (a) Java interpreter 98. A faster software technique uses a ________ (L1) (a) Java (b) Just-in-time (JIT) (c) Line by line (d) Any one of the above Answer: (b) Just-in-time (JIT) 99. ________ is the activity of finding and fixing errors, or bugs in a system. (L1) (a) Compiling (b) Interpreting (c) Debugging (d) Scheduling Answer: (c) Debugging 100. Debugging seeks to find and fix errors in ________ (L1) (a) Hardware (b) Software (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 101. Debugging can also include ________ (L1) (a) Performance tuning (b) Cost reducing (c) Scheduling (d) Interrupting Answer: (a) Performance tuning 102. If a process fails, most operating systems write the error information to a ________ (L2) (a) Application (b) Log file (c) Memory (d) Network Answer: (b) Log file 103. The operating system can also take a ________, a capture of the memory of the process. (L3) (a) Screen shot (b) User log (c) Kernel log (d) Core dump Answer: (d) Core dump 104. Running programs and core dumps can be probed by a ________, a tool designed to allow a programmer to explore the code and memory of a process. (L1) (a) Debugger (b) CRO (c) Logger (d) Compiler Answer: (a) Debugger
Operating System Services 37
105. A kernel failure is called a ________ (L2) (a) Success (b) Log (c) Interrupt (d) Crash Answer: (d) Crash 106. As with a process failure, error information is saved to a log file, and the memory state is saved to a ________ (L1) (a) Crash dump (b) Stack (c) Log (d) Queue Answer: (a) Crash dump 107. To identify bottlenecks, we must be able to monitor ________ (L1) (a) Compiler (b) Cost of the system (c) System performance (d) Crash dump Answer: (c) System performance 108. ________ must be added to compute and display measures of system behaviour (L2) (a) Code (b) Compiler (c) Scheduler (d) Crash Answer: (a) Code 109. An analysis program can process the log file to determine ________ (L1) (a) System performance (b) Bottlenecks (c) Inefficiencies (d) All of the above Answer: (d) All of the above 110. The UNIX command top displays ________ (L1) (a) Resources used on the system (b) Top of the stack (c) Bottlenecks in the program (d) Memory contents Answer: (a) Resources used on the system 111. Tools can be used to display ________ (L1) (a) State of disk I/O (b) Memory allocation (c) Network traffic (d) All of the above Answer: (d) All of the above 112. ________ is a facility that dynamically adds probes to a running system, both in the user processes and in the kernel. (L2) (a) Stack trace (b) DTrace (c) CTrace (d) System trace Answer: (b) DTrace
38 Cracking the Operating Systems Skills
113. Lines ending with ________ are executed in user mode (L3) (a) Trace (b) K (c) U (d) UM Answer: (c) U 114. ________ periodically samples the instruction pointer to determine which code is being executed, can show statistical trends but not individual activities. (L2) (a) Debugging (b) Profiling (c) Tracing (d) Compiling Answer: (c) Profiling 115. DTrace is composed of a ________ (L1) (a) Compiler (b) A framework (c) Providers and consumers of probe (d) All of the above Answer: (d) All of the above 116. The DTrace facility takes care to assure that probes do not use (L1) (a) Too much memory (b) CPU capacity (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 117. The system must be configured or generated for each specific computer site, a process sometimes known as ________ (L2) (a) Application (b) System generation (SYSGEN) (c) Logging (d) Networking Answer: (b) System generation (SYSGEN) 118. On most computer systems, a small piece of code known as the ________ locates the kernel, loads it into the main memory, and starts its execution. (L1) (a) Boot strap program (b) Kernel program (c) Application (d) Driver Answer: (a) Boot strap program 119. When a CPU receives a reset event, for instance, when it is powered up or rebooted, the ________ is loaded with a predefined memory location, and execution starts there. (L1) (a) General purpose register (b) Control register (c) Data register (d) Instruction register Answer: (d) Instruction register 120. ________ is convenient because it needs no initialization and cannot easily be infected by a computer virus. (L1) (a) Cache (b) RAM (c) ROM (d) SRAM Answer: (c) ROM
Operating System Services 39
121. The bootstrap program can perform a ________ (L1) (a) Run diagnostics (b) Booting steps (c) Initialize all aspects of the system (d) All of the above Answer: (d) All of the above 122. Storing the operating system in ROM is suitable for (L1) (a) Small operating system (b) Simple supporting hardware (c) Rugged operation (d) All of the above Answer: (d) All of the above 123. All forms of ROM are also known as ________, since their characteristics fall somewhere between those of hardware and those of software. (L1) (a) Application (b) Firmware (c) Kernel (d) User code Answer: (b) Firmware 124. Executing code in firmware is ________ than executing code in RAM. (L1) (a) Slower (b) Faster (c) Equal (d) Incomparable Answer: (a) Slower 125. ________ is an example of an open-source bootstrap program for Linux systems. (L1) (a) Master boot record (b) Extended boot record (c) GRUB (d) All of the above Answer: (c) GRUB 126. The master boot record (MBR) is the ________ sector of the hard disk, with zero as its offset (L1) (a) First (b) Second (c) Last (d) Middle Answer: (a) First 127. Code in the MBR and volume boot record (VBR) is in essence loaded ________ (L1) (a) Different way (b) Same way (c) Anywhere (d) At the last Answer: (b) Same way 128. A disk that has a boot partition is called a ________ (L1) (a) Boot disk (b) System disk (c) Either a or b (d) Neither a nor b Answer: (c) Either a or b
40 Cracking the Operating Systems Skills
129. Once the full bootstrap program has been loaded, it can (L1) (a) Traverse the file system to find the OS kernel (b) Load kernel into memory (c) Start executing the loaded code (d) All of the above Answer: (d) All of the above 130. Since an operating system is large, ________ is important. (L1) (a) Scheduling (b) Modularity (c) Debugging ability (d) Networking Answer: (b) Modularity
3
Process Management
This chapter covers process management which is an integral part of any modern-day operating system. We also cover questions from system calls as part of this chapter. 1. A process is a ________ (L1) (a) Program in execution (c) Networking agent Answer: (a) Program in execution
(b) Operating system itself (d) Debugger
2. A process includes ________ (L1) (a) Program counter (c) Heap Answer: (d) All of the above
(b) Process stack (d) All of the above
3. A program becomes a process when (L1) (a) An executable file is loaded into memory (b) Process starts (c) From power on (d) Any time Answer: (a) An executable file is loaded into memory. 4. As a process executes, it changes ________ (L1) (a) Program (b) Time (c) State Answer: (c) State 5. Each process may be in ________ (L1) (a) New or terminated state (c) Ready state Answer: (d) Any of the above states
(d) All of the above
(b) Running or waiting state (d) Any of the above states
6. ________ process can be running on any processor at any instant. (L1) (a) One (b) Two (c) Many (d) No Answer: (a) One
42 Cracking the Operating Systems Skills
7. ________ indicates the address of the next instruction to be executed for this process. (L1) (a) Stack (b) Program counter (c) Queue (d) Program Answer: (b) Program counter 8. ________ vary in number and type, depending on the computer architecture. (L1) (a) Software (b) Hardware (c) CPU registers (d) Application Answer: (c) CPU registers 9. CPU registers include ________ (L2) (a) Accumulators (c) Stack pointers Answer: (d) All of the above
(b) Index and general-purpose registers (d) Application
10. ________ includes a process priority, pointers to scheduling queues, and any other scheduling parameters. (L1) (a) Program counter (b) CPU scheduling information (c) Stack pointer (d) Memory manager Answer: (b) CPU scheduling information 11. ________ may include information such as the value of the base and limit registers, the page tables, or the segment tables etc. (L1) (a) CPU scheduling information (b) Accounting information (c) Program counter (d) Memory manager Answer: (d) Memory manager 12. Accounting information includes ________ (L1) (a) Amount of CPU and real time used (b) Time limits (c) Process numbers (d) All of the above Answer: (d) All of the above 13. I/O status information includes ________ (L1) (a) List of I/O devices allocated to the process (b) CPU details (c) Process details (d) All of the above Answer: (a) List of I/O devices allocated to the process
Process Management 43
14. A process is a program that performs a single ________ of execution. (L1) (a) Operation (b) Thread (c) Instruction (d) None of the above Answer: (b) Thread 15. The objective of multiprogramming is to have some process running at all times, to maximize (L1) (a) Memory utilization (b) CPU utilization (c) Cost utilization (d) Power utilization Answer: (b) CPU utilization 16. The ________ selects an available process for program execution on the CPU. (L1) (a) Interrupts (b) Process scheduler (c) BIOS (d) Memory manager Answer: (b) Process scheduler 17. As processes enter the system, they are put into a ________ (L1) (a) Program (b) Stack (c) Job queue (d) Cache Answer: (c) Job queue 18. The processes that reside in the main memory and are ready and waiting to execute are kept on a list called the ________ (L1) (a) Ready queue (b) Steady queue (c) Job queue (d) Interrupt queue Answer: (a) Ready queue 19. The queue is generally stored as a ________ (L1) (a) Structure (b) Array (c) Linked list (d) Union Answer: (c) Linked list 20. A ready-queue header contains pointers to the ________ and ________ process control blocks in the list (L1) (a) First and second (b) First and third (c) First and final (d) Second and final Answer: (c) First and final 21. The list of processes waiting for a particular I/O device is called a (L1) (a) Job queue (b) Ready queue (c) Stack (d) Device queue Answer: (d) Device queue
44 Cracking the Operating Systems Skills
22. The primary distinction between the long-term and short-term schedulers lies in ________ (L2) (a) Frequency of execution (b) Cost (c) Stack (d) CPU Answer: (a) Frequency of execution 23. Often, the short-term scheduler executes at least once every (L2) (a) Second (b) 100 minutes (c) 100 seconds (d) 100 milliseconds Answer: (d) 100 milliseconds 24. If it takes 10 milliseconds to decide to execute a process for 100 milliseconds, then ________ percent of the CPU is being used for scheduling the work. (L2) (a) 10 (b) 9 (c) 100 (d) 90 Answer: (b) 9 25. The long-term scheduler controls the ________ (L2) (a) Degree of multiprogramming (b) Frequency of processor (c) Memory present in the system (d) Hardware response time Answer: (a) Degree of multiprogramming 26. If the degree of multiprogramming is stable, then the average rate of process creation must be ________ the average departure rate of processes leaving the system (L1) (a) Greater than (b) Less than (c) Equal to (d) Variable to Answer: (c) Equal to 27. Time-sharing systems such as ________ systems often have no long-term scheduler but simply put every new process in memory for the short-term scheduler. (L3) (a) UNIX (b) Microsoft windows (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 28. The process is swapped out, and is later swapped in, by the ________ (L2) (a) Medium-term scheduler (b) Long-term scheduler (c) Short-term scheduler (d) All of the above Answer: (a) Medium-term scheduler 29. When an interrupt occurs, the system needs to save the current ________ of the process running on the CPU so that it can restore that context when its processing is done (L2) (a) Memory (b) Context (c) Program (d) All of the above Answer: (b) Context
Process Management 45
30. Switching the CPU to another process requires performing a state save of the ________ process and a state restore of a ________ process. (L1) (a) Different, current (b) Current, current (c) Current, different (d) Different, different Answer: (c) Current, different 31. The task of switching the CPU to another process is called ________ (L1) (a) Context switch (b) Process switch (c) Stack switch (d) Interruption Answer: (a) Context switch 32. Context-switch time ________ overhead, because the system does no useful work while switching (L1) (a) Has no (b) Reduces (c) Has variable (d) Adds Answer: (d) Adds 33. Context-switch speed varies from machine to machine depending on ________ (L2) (a) Memory speed (b) Number of registers that must be copied (c) Existence of special instructions (d) All of the above Answer: (d) All of the above 34. The processes in most systems can execute concurrently, and they may be created and deleted ________ (L1) (a) Dynamically (b) Statically (c) Either a or b (d) Neither a nor b Answer: (a) Dynamically 35. A process may create several new processes, via a ________ system call, during the course of execution. (L1) (a) Create system (b) Create process (c) Kernel (d) Any one of the above Answer: (b) Create process 36. The creating process is called a ________ process, and the new processes are called the ________ of that process. (L1) (a) Child 1, child 2 (b) Child, parent (c) Parent, children (d) Parent 1, parent 2 Answer: (c) Parent, children
46 Cracking the Operating Systems Skills
37. Most operating systems identify processes according to a ________ (L1) (a) Unique id (uid) (b) Process identifier (pid) (c) Memory id (mid) (d) Stack id (sid) Answer: (b) Process identifier (pid) 38. On UNIX, we can obtain a listing of processes by using the ________ command (L2) (a) ps (b) top (c) ls (d) dir Answer: (a) ps 39. In general, a process needs resources like ________ to accomplish its task. (L1) (a) CPU time (b) Memory (c) Files, I/O devices (d) All of the above Answer: (d) All of the above 40. The ________ system call loads a binary file into memory and starts its execution (L2) (a) Fork() (b) exec() (c) open() (d) write() Answer: (b) exec() 41. A process terminates when it finishes executing its final statement and asks the operating system to delete it by using the ________ system call. (L2) (a) exit() (b) open() (c) exec() (d) write() Answer: (a) exit() 42. All the resources of the process, including physical and virtual memory, open files, and I/O buffers; are deallocated by the ________ (L2) (a) Application (b) Kernel (c) Operating system (d) Administrator Answer: (c) Operating system 43. A process can cause the termination of another process via an appropriate ________ (L1) (a) Thread (b) Application call (c) Kernel call (d) System call Answer: (d) System call 44. When one process creates a new process, the identity of the new process is passed to the ________ (L1) (a) Parent (b) Child (c) New process (d) None of the above Answer: (a) Parent
Process Management 47
45. A parent may terminate the execution of one of its children for ________ (L2) (a) The child has exceeded its usage of some of the resources that it has been (b) The task assigned to the child is no longer required (c) The parent is exiting, and the operating system does not allow a child to continue if its parent terminates (d) All of the above Answer: (d) All of the above 46. Processes executing concurrently in the operating system may be ________ (L2) (a) Independent processes (b) Cooperating processes (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 47. Any process that does not share data with any other process is ________ (L1) (a) Dependent (b) Independent (c) Neither dependent nor independent (d) Null process Answer: (b) Independent 48. A process is ________ if it can affect or be affected by the other processes executing in the system. (L1) (a) Cooperating (b) Independent (c) Dependent (d) Bad process Answer: (a) Cooperating 49. Since several users may be interested in the same piece of information, we must provide an environment to allow concurrent access to such information. This is called ________ (L1) (a) Convenience (b) Modularity (c) Information sharing (d) None of the above Answer: (c) Information sharing 50. If we want a particular task to run faster, we must break it into subtasks, each of which will be executing in parallel with the others. This is known as ________ (L1) (a) Information sharing (b) Convenience (c) Modularity (d) Computation speed up Answer: (d) Computation speed up 51. We may want to construct the system in a modular fashion, dividing the system functions into separate processes or threads. This process is termed ________ (L1) (a) Convenience (b) Sharing (c) Modularity (d) Speed up Answer: (c) Modularity
48 Cracking the Operating Systems Skills
52. Even an individual user may work on many tasks at the same time. For instance, a user may be editing, printing, and compiling in parallel. This is called ________ (L1) (a) Sharing (b) Convenience (c) Speeding (d) Multithreading Answer: (b) Convenience 53. ________ processes require an inter-process communication (IPC) mechanism that will allow them to exchange data and information. (L2) (a) Dependent (b) Independent (c) Shared (d) Cooperating Answer: (d) Cooperating 54. The two fundamental models of inter-process communication (IPC) are ________ (L1) (a) Shared memory and message passing (b) Shared memory and unshared memory (c) Message passing and unshared memory (d) None of the above Answer: (a) Shared memory and message passing 55. Processes can exchange information by reading and writing data to the ________ (L1) (a) Message passed buffer (b) Shared region (c) Unshared region (d) None of the above Answer: (b) Shared region 56. Shared memory allows ________ speed and convenience of communication. (L3) (a) Average (b) Minimum (c) Maximum (d) All of the above Answer: (c) Maximum 57. Shared memory is ________ than message passing, as message passing systems are typically implemented using system calls and thus require more time-consuming task of kernel interventions. (L2) (a) Faster (b) Slower (c) Average (d) None of the above Answer: (a) Faster 58. Once shared memory is established, all accesses are treated as routine memory accesses, and ________ assistance from the kernel is required. (L2) (a) Full (b) Medium (c) No (d) All of the above Answer: (c) No
Process Management 49
59. Typically, a shared-memory region resides in the ________ space of the process creating the shared memory segment. (L2) (a) Memory (b) Address (c) Data (d) All of the above Answer: (b) Address 60. The processes are also responsible for ensuring that they are not ________ to the same location simultaneously. (L1) (a) Writing (b) Reading (c) Writing and reading (d) All of the above Answer: (a) Writing 61. The shared buffer is implemented as a circular array with ________ logical pointers. (L3) (a) Five (b) Four (c) Three (d) Two Answer: (d) Two 62. A message-passing facility provides at least ________ operations (L2) (a) No (b) Two (c) One (d) Many Answer: (b) Two 63. Messages sent by a process can be of ________ (L2) (a) Fixed size (b) Variable size (c) Both a or b (d) Neither a nor b Answer: (c) Both a or b 64. If processes P and Q want to communicate, they must send messages to and receive messages from each other; a ________ must exist between them. (L2) (a) Data link (b) Communication link (c) Address link (d) None of the above Answer: (b) Communication link 65. Processes that want to ________ must have a way to refer to each other. (L2) (a) Communicate (b) Kill other process (c) Create new process (d) All of the above Answer: (a) Communicate 66. Under ________ communication, each process that wants to communicate must explicitly name the recipient or sender of the communication. (L3) (a) New (b) Old (c) Indirect (d) Direct Answer: (d) Direct
50 Cracking the Operating Systems Skills
67. ________ send a message to process P (L3) (a) Receive (p, message) (b) Send (p, p) (c) Send (p, message) (d) None of the above Answer: (c) Send (p, message) 68. ________ receive a message from process Q (L2) (a) Send (p, message) (b) Receive (Q, message) (c) Send (Q, Q) (d) Receive (Q, Q) Answer: (b) Receive (Q, message) 69. A link is established ________ between every pair of processes that want to communicate. (L2) (a) Automatically (b) Manually (c) Partially (d) None of the above Answer: (a) Automatically 70. A link is associated with ________ processes (L2) (a) Three (b) Four (c) Two Answer: (c) Two
(d) Many
71. Between each pair of processes, there exists ________ link (L2) (a) One (b) Two (c) Three (d) Many Answer: (a) One 72. With indirect communication, the messages are sent to and received from ________ (L3) (a) Mailboxes (b) Ports (c) Neither a nor b (d) Either a or b Answer: (d) Either a or b 73. A ________ can be viewed abstractly as an object into which messages can be placed by processes and from which messages can be removed. (L2) (a) Port (b) Mailbox (c) Shared box (d) None of the above Answer: (b) Mailbox 74. A ________ will send a message to mailbox A. (L1) (a) Receive (A, message) (b) Send (A, message) (c) Send (A, A) (d) None of the above Answer: (b) Send (A, message)
Process Management 51
75. A ________ will receive a message from mailbox A. (L1) (a) Receive (A, message) (b) Send (A, A) (c) Send (A, message) (d) None of the above Answer: (a) Receive (A, message) 76. The operating system then must provide a mechanism that allows a process to (L2) (a) Create a mailbox (b) Send and receive messages through the mailbox (c) Delete a mailbox (d) All of the above Answer: (d) All of the above 77. The process that creates a new mailbox is that mailbox’s ________ by default. (L1) (a) Servant (b) Owner (c) Client (d) None of the above Answer: (b) Owner 78. The ownership and receiving privilege may be passed to other processes through appropriate ________ (L1) (a) Application calls (b) Framework calls (c) System calls (d) None of the above Answer: (c) System calls 79. Communication between processes takes place through calls to ________ and receive () primitives. (L1) (a) Send () (b) Receive () (c) Read () (d) Write () Answer: (a) Send () 80. Message passing may be either blocking or non-blocking also known as ________ (L2) (a) Synchronous (b) Asynchronous (c) Either a or b (d) Neither a nor b Answer: (c) Either a or b 81. In blocking send, the sending process is blocked until the message is received by the receiving process or by the ________ (L2) (a) Mailbox (b) Port (c) Hub (d) Application Answer: (a) Mailbox 82. In non-blocking receive, the receiver retrieves a ________ (L1) (a) Valid message (b) Null (c) Either a or b (d) Application Answer: (c) Either a or b
52 Cracking the Operating Systems Skills
83. When both send () and receive () are blocking, we have a ________ between the sender and the receiver. (L3) (a) Rendezvous (b) Synchronization (c) Either a or b (d) Neither a nor b Answer: (a) Rendezvous 84. Whether communication is direct or indirect, messages exchanged by communicating processes reside in a ________ (L2) (a) Pipeline (b) Permanent queue (c) Message queue (d) Temporary queue Answer: (d) Temporary queue 85. A process must first create a shared memory segment using the ________ system call (L2) (a) Shemset () (b) Shmget () (c) Shmnget () (d) None of the above Answer: (b) Shmget () 86. Processes that wish to access a shared-memory segment must attach it to their address space using the ________ system call. (L2) (a) shmat () (b) Shmget () (c) Shmnget () (d) Shmemset () Answer: (a) shmat () 87. Connection ports are named ________ and are visible to all processes (L2) (a) New ports (b) Objects (c) Shared ports (d) None of the above Answer: (b) Objects 88. If a client needs to send a larger message, it passes the message through a ________ which sets up a region of shared memory. (L2) (a) Objects (b) Ports (c) Section object (d) None of the above Answer: (c) Section object 89. A ________ is defined as an endpoint for communication. (L2) (a) Socket (b) Ports (c) Object (d) Queue Answer: (a) Socket 90. A pair of processes communicating over a network employ ________ socket (L1) (a) Single (b) Pair of (c) Multiple (d) No Answer: (b) Pair of
Process Management 53
91. Servers implementing specific services such as ________ listen to well-known ports (L2) (a) Telnet (b) FTP (c) HTTP (d) All of the above Answer: (d) All of the above 92. When a client process initiates a request for a connection, it is assigned a port by its ________ (L2) (a) Host computer (b) client (c) own (d) Any of the above Answer: (a) Host computer 93. In contrast to the IPC facility, the messages exchanged in RPC communication are ________ and are thus no longer just packets of data. (L3) (a) Same (b) Well structured (c) Not structured (d) Easy to transmit Answer: (b) Well structured 94. A ________ is simply a number included at the start of a message packet. (L2) (a) Channel (b) Token (c) Bus (d) Port Answer: (d) Port 95. The semantics of RPCs allow a client to invoke a procedure on a remote ________ as it would invoke a procedure locally. (L2) (a) Host (b) Bus (c) Client (d) Channel Answer: (a) Host 96. The RPC system hides the details that allow communication to take place by providing a ________ on the client side. (L3) (a) Token (b) Link key (c) Stub (d) Channel Answer: (c) Stub 97. A ________ acts as a conduit allowing two processes to communicate. (L2) (a) Message (b) Pipe (c) Channel (d) Stub Answer: (b) Pipe 98. In implementing a pipe, which of the following has to be considered? (L2) (a) Does the pipe allow unidirectional communication or bidirectional communication? (b) If two-way communication is allowed, is it half duplex or full duplex (c) Can the pipes communicate over a network, or must the communicating processes reside on the same machine (d) All of the above Answer: (d) All of the above
54 Cracking the Operating Systems Skills
99. Ordinary pipes allow ________ processes to communicate in standard producer consumer fashion (L2) (a) One (b) Two (c) Three (d) Many Answer: (b) Two 100. The producer writes to one end of the pipe called ________ (L2) (a) Write end (b) Read end (c) RW end (d) None of the above Answer: (a) Write end 101. The consumer reads from other end of the pipe called ________ (L2) (a) Read end (b) Write end (c) RW end (d) None of the above Answer: (a) Read end 102. Ordinary pipes are ________ allowing communication (L2) (a) Multidirectional (b) Bidirectional (c) Unidirectional (d) None of the above Answer: (c) Unidirectional 103. If two-way communication is required, two pipes must be used, with each pipe sending data in ________ direction (L1) (a) Same (b) Different (c) Many (d) None of the above Answer: (b) Different 104. An ordinary pipe ________ be accessed from outside the process that creates it. (L2) (a) Can (b) Cannot (c) Sometimes (d) None of the above Answer: (b) Cannot 105. Typically, a parent process creates a pipe and uses it to communicate with a child process it creates via ________ (L2) (a) Read (b) Write (c) Fork (d) Pipe Answer: (c) Fork 106. Named pipes provides a tool that is/has ________ (L2) (a) Bidirectional communication (b) More powerful communication tool (c) No parent-child relationship is required (d) All of the above Answer: (d) All of the above 107. Once a named pipe is established, ________ processes can use it for communication (L2) (a) Single (b) Several (c) Two (d) No Answer: (b) Several
Process Management 55
108. Named pipes are referred to as ________ in UNIX systems (L2) (a) LILO (b) FILO (c) LIFO (d) FIFO Answer: (d) FIFO 109. A FIFO is created with the ________ system call (L2) (a) mkopen() (b) mkread() (c) mkfifo() Answer: (c) mkfifo()
(d) None of the above
110. FIFOs allow bidirectional communication and ________ transmission is permitted (L2) (a) Half-duplex (b) Full-duplex (c) Any type of (d) None of the above Answer: (a) Half-duplex 111. Pipes are used quite often in the UNIX command-line environment for situations in which the output of one command serves as ________ to the second. (L2) (a) Output (b) Input (c) Either input or output (d) Channel Answer: (b) Input 112. A pipe can be constructed on the command line using the ________ character (L2) (a) & (b) * (c) % (d) | Answer: (d) | 113. In command ls | more, ________ serves as the producer (L2) (a) More (b) ls (c) Both ls and more (d) Neither ls nor more Answer: (b) ls 114. As a process executes it changes ________ (L1) (a) Channel (b) Priorities (c) State Answer: (c) State
(d) None of the above
115. Long-term scheduling is the selection of processes that will be allowed to contend for ________ (L1) (a) CPU (b) Memory (c) I/O (d) ALU Answer: (a) CPU 116. A thread is a basic unit of CPU utilization; it comprises a ________ (L3) (a) Thread ID (b) Program counter (c) Register set and a stack (d) All of the above Answer: (d) All of the above
56 Cracking the Operating Systems Skills
117. What is the hex value of ‘O_RDONLY’ flag? (L3) (a) 0 (b) 1 (c) 2 (d) None of the above Answer: (a) It is interesting to note that ‘read’ gets 0 always like FD 0 of standard input. 118. What is the hex value of ‘O_WRONLY’ flag? (L3) (a) 0 (b) 1 (c) 2 Answer: (b) Same as ‘read’ for ‘write’ also.
(d) None of the above
119. What is the hex value of ‘O_RDWR’ flag? (L3) (a) 0 (b) 1 (c) 2 (d) None of the above Answer: (c) Similarly, there are many other flags like O_EXCL (to go to another command when the file doesn’t exist), O_NOCTTY (if the prescribed file has a terminating device in the path, it cannot take control of the file), O_NOLINK, O_ NOTRANS, O_TRUNC, etc. 120. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); int f1= fcntl(fd1,F_GETFL); int ret= fcntl(fd1,F_SETFL,O_APPEND); int f2= fcntl(fd1,F_GETFL); (f1==f2)?printf(“%x”,f2):printf(“they are different”); } (a) Some integer value (b) Prints nothing (c) They are different (d) Compiler dependent Answer: (c) By default O_APPEND will not be active as the file is opened in RDONLY mode, it has the reader in first character. So when making it into APPEND mode, the flags will be changed definitely. 121. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); int f1= fcntl(fd1,F_GETFL); int ret= fcntl(fd1,F_SETFL,O_APPEND); int f2= fcntl(fd1,F_GETFL); (f1==f2)?printf(“they are same”):printf(“%x”,f2); } (a) 8000 (b) 8400 (c) They are same (d) Compiler dependent Answer: (b) F_SETFL is a flag used to the set the specified flag to the file. The default flag value is 8000. So adding APPEND to it gets 8400 as the value of APPEND is 400.
Process Management 57
122. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); int f1= fcntl(fd1,F_GETFL); int ret= fcntl(fd1,F_SETFL,O_SYNC); int f2= fcntl(fd1,F_GETFL); (f1==f2)?printf(“they are same”):printf(“%x”,f2); } (a) 8000 (b) 8800 (c) They are same (d) Compiler dependent Answer: (c) SYNC is a default status enabled for any file opened. But additionally, altering the SYNC and ASYNC flags will not alter the GETFL value. 123. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); int f1= fcntl(fd1,F_GETFL); int ret= fcntl(fd1,F_SETFL,O_ASYNC); int f2= fcntl(fd1,F_GETFL); (f1==f2)?printf(“they are same”):printf(“%x”,f2); } (a) 8000 (b) 4000 (c) They are same (d) Compiler dependent Answer: (c) As said above altering the SYNC and ASYNC flags will not alter the GETFL value. 124. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); int f1= fcntl(fd1,F_GETFL); int ret= fcntl(fd1,F_SETFL,O_NONBLOCK); int f2= fcntl(fd1,F_GETFL); (f1==f2)?printf(“they are same”):printf(“%x”,f2); } (a) 8000 (b) 8800 (c) They are same (d) Compiler dependent Answer: (b) By default the file will be in blocking mode. So when changed gives new value for GETFL. 125. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); int f1= fcntl(fd1,F_GETFL);
58 Cracking the Operating Systems Skills
int ret= fcntl(fd1,F_SETFL,O_RDWR); int f2= fcntl(fd1,F_GETFL); (f1==f2)?printf(“they are same”):printf(“%x”,f2); } (a) 8000 (b) 8800 (c) They are same (d) Compiler dependent Answer: (c) Actually SETFL cannot change access mode. It can change only the APPEND and NONBLOCK status flags. 126. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); int ret= fcntl(fd1,F_SETFL,O_RDWR); printf(“%d”,ret); } (a) 0 (b) 1 (c) –1 (d) Compiler dependent Answer: (a) The function returns 0 even when it is success or failure. 127. What is the output of the code when “hai.txt” exists? (assume this is the first process launched) (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); struct flock lock; int ret; memset(&lock, 0, sizeof lock); lock.l_type = F_RDLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = 0; ret = fcntl(fd1, F_SETLK, &lock); if (ret == –1) perror(“fcntl”); else printf(“\nFD %d acquired read lock”, fd1); } (a) Hai.txt locked already (b) fcntl (c) FD 3 acquired read lock (d) Error Answer: (c) This is a flag used to acquire locks over data. May be useful in multiprocessing environment. Here the third argument is a pointer to inbuilt structure ‘flock’. ‘l_type’ means lock type, Read or write. ‘LCK’ for lock and ‘UNLCK’ for unlock.
Process Management 59
128. What is the output of the code when “hai.txt” exists? (assume this is the first process launched) (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); struct flock lock; int ret; memset(&lock, 0, sizeof lock); lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = 0; ret = fcntl(fd1, F_SETLK, &lock); if (ret == –1) perror(“fcntl”); else printf(“\nFD %d acquired write lock”, fd1); } (a) fcntl: Hai.txt locked already (b) fcntl: write lock not applicable for read only format (c) FD 3 acquired write lock (d) None of the above Answer: (d) fcntl: Bad file descriptor. It is not possible to acquire write lock in read mode. 129. What is the output of the code when “hai.txt” is already locked by some other function with RDLCK? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); if (fd1 == –1) printf(“%d”,errno); else printf(opened”); } (a) 11 (b) 12 (c) 13 (d) None of the above Answer: (c) This is the value of EACCES. 130. What is the output of the code when “hai.txt” is already locked by some other function with RDLCK? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); struct flock lock;
60 Cracking the Operating Systems Skills
int ret; memset(&lock, 0, sizeof lock); lock.l_type = F_RDLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = 0; ret = fcntl(fd1, F_SETLK, &lock); if (ret == –1) printf(“%d”,errno); else printf(“\nacquired read lock”); } (a) 11 (b) 12 (c) 13 (d) None of the above Answer: (d) It prints “acquired read lock”. Any number of processes can acquire read lock over a file. It is a shared lock. 131. What is the output of the code when “hai.txt” is already locked by some other function with RDLCK? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); struct flock lock; int ret; memset(&lock, 0, sizeof lock); lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = 0; ret = fcntl(fd1, F_SETLK, &lock); if (ret == –1) printf(“%d”,errno); else printf(“\n acquired write lock”); } (a) 11 (b) 12 (c) 13 (d) None of the above Answer: (d) It prints “acquired write lock”. A file locked by RDLCK (read lock) by an FD can be locked with WRLCK (write lock) by another FD. 132. What is the output of the code when “hai.txt” is already locked by some other function with WRLCK? (L3) void main() { int fd1=open(“hai.txt”,O_RDWR); struct flock lock;
Process Management 61
int ret; memset(&lock, 0, sizeof lock); lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = 0; ret = fcntl(fd1, F_SETLK, &lock); if (ret == –1) printf(“%d”,errno); else printf(“\n acquired write lock”); } (a) 11 (b) 12 (c) 13 (d) None of the above Answer: (a) This is the errno value of EAGAIN. Occurs on trying to acquire lock over already locked file. Only one process may acquire write lock over a file. It is an exclusive lock. 133. What is the output of the code when “hai.txt” is already locked by some other function with WRLCK? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); struct flock lock; int ret; memset(&lock, 0, sizeof lock); lock.l_type = F_RDLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = 0; ret = fcntl(fd1, F_SETLK, &lock); if (ret == –1) printf(“%d”,errno); else printf(“acquired read lock”); } (a) 11 (b) 12 (c) 13 (d) None of the above Answer: (a) A file with exclusive lock cannot be given any shared lock. So gets the same EAGAIN error. A same file can have different regions locked by different locks. Even there may be partially locked files. The region is determined by l_start and l_len members of flock structure. l_whence is to make sure that a lock is not applied before the first character or start of the file. At times it can be used to check prevention of clash of regions.
62 Cracking the Operating Systems Skills
134. What is the output of the code when “hai.txt” is already locked by some other function with WRLCK? (assume no other process is running) (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); struct flock lock; int ret; memset(&lock, 0, sizeof lock); lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = 0; ret = fcntl(fd1, F_SETLKW, &lock); if (ret == –1) printf(“%d”,errno); else printf(“acquired write lock”); } (a) 11 (b) 12 (c) 13 (d) None of the above Answer: (d) It prints “acquired write lock”. ‘SEFTLKW’ flag is also for setting flag. It will wait if a conflicting lock is held by another process. It waits till the lock is released and then assigns the new lock. But will terminate if some signals occur to stop them. 135. What is the output of the code when “hai.txt” is already locked by some other function with WRLCK and an interrupt occurs in between? (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); struct flock lock; int ret; memset(&lock, 0, sizeof lock); lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = 0; ret = fcntl(fd1, F_SETLKW, &lock); if (ret == –1) printf(“%d”,errno); else printf(“acquired write lock”); } (a) 9 (b) prints nothing (c) 13 (d) None of the above Answer: (d) It gives 94 for EINTR, the interrupt error.
Process Management 63
136. What is the output of the code when “hai.txt” exists? (assume this is the first program launched) (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); struct flock lock; int ret; memset(&lock, 0, sizeof lock); lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = 0; ret = fcntl(fd1, F_GETLK, &lock); if (ret == –1) printf(“%d”,errno); else if(lock.l_type == F_UNLCK) printf(“can acquired write lock”); } (a) Can acquire write lock (b) Prints nothing (c) 9 (d) None of the above Answer: (a) ‘F_GETLK’ flag checks if the specified lock can be acquired over the file. If so it will not acquire the lock, but changes the ‘l_type’ into ‘F_UNLCK’ and leaves the other members undisturbed. 137. What is the output of the code when “hai.txt” exists? (assume “hai.txt” is locked with WRLCK by process with PID 4034) (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); struct flock lock; int ret; memset(&lock, 0, sizeof lock); lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = 0; ret = fcntl(fd1, F_GETLK, &lock); if (ret == –1) printf(“%d”,errno); else if(lock.l_type == F_UNLCK) printf(“can acquired write lock”); else printf(“%d locked the file”,l_pid) }
64 Cracking the Operating Systems Skills
(a) Can acquire write lock (b) 4034 acquired write lock (c) 9 (d) None of the above Answer: (b) When the specified lock has a clash already then ‘F_GETLK’ flag modified the members that cause the problem like, ‘l_start’, ‘l_len’ when there is a reason clash and also the ‘l_pid’ gets the PID of the locked process. 138. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); int ret = fcntl(fd1, F_GETFD); printf(“%d”,ret); } (a) 0 (b) 1 (c) 8000 (d) None of the above Answer: (a) ‘F_GETFD’ prints a file descriptor flag values. It is different from file status flag. Only one file descriptor flag is taken into account, FD_CLOEXEC. By default it is 0, which means the file should not be closed when the program encounters an EXEC command. 139. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); int ret = fcntl(fd1, F_SETFD,1); ret = fcntl(fd1, F_GETFD); printf(“%d”,ret); } (a) 0 (b) 1 (c) 8000 (d) None of the above Answer: (b) ‘F_SETFD’ is the flag used to set the file descriptor flag. 1 means to close the file opened by the FD when the program encounters a read call. In some systems even the flag named FD_CLOEXEC is not defined, just referred as file descriptor flags. 140. What is the output of the code? (L3) void main() { printf(“%x”,FD_CLOEXEC); } (a) 0 (b) 1 (c) 1000 (d) None of the above Answer: (b) The flag means close on EXEC, as said above the value of the corresponding flag is 1. By default the flag is not activated in any FD. 141. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); int ret = fcntl(fd1, F_GETOWN); printf(“%d”,ret); }
Process Management 65
(a) The owner’s name (b) The owner account reference number (c) Owner process ID (d) None of the above Answer: (d) It gives 0. ‘F_GETOWN’ can be used only when the FD is associated to a socket. It gives a positive or a negative number other than 0 and –1. The positive number is the process ID, the negative number is the process group ID. 0 means the instruction has failed and -1 is an error. Like any other flag this to has ‘F_SETOWN’ that sets the specified number as the process ID or the process group ID. But F_SETOWN also cannot set the process group id to –1. 142. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); int ret = unlink(“hai.txt”); int fd2=open(“hai.txt”,O_RDONLY); printf(“%d”,fd2); } (a) 4 (b) –1 (c) 3 (d) None of the above Answer: (b) unlink is a system used to permanently close a file. So trying to open a file after unlinking it is not possible. Hence, gives –1 as the call fails. It can be regained on restart. If come basic standard files are unlinked then it might also lead to reinstall OS. 143. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); int ret = unlink(“hai.txt”); printf(“%d”,ret); } (a) 0 (b) 1 (c) –1 (d) None of the above Answer: (a) Even on success unlink returns 0 only. 144. What is the output of the code when “hai.txt” has “hai”? (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); int ret = unlink(“hai.txt”); char c[10]; read(fd1,c,3); printf(“%s”,c); } (a) hai (b) Segmentation fault (c) –1 (d) None of the above Answer: (a) Even though the file is unlinked, the data is still associated with FD.
66 Cracking the Operating Systems Skills
145. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); int ret = unlink(fd1); int fd2=open(“hai.txt”,O_RDONLY); printf(“%d”,fd2); } (a) 4 (b) –1 (c) 3 (d) None of the above Answer: (a) ‘unlink’ doesn’t work on FD values. 146. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); int ret = unlink(fd1); printf(“%d”,ret); } (a) 0 (b) –1 (c) 1 (d) None of the above Answer: (b) Failure returns –1. 147. What is the output of the code when “hai.txt” exists? (L2) void main() { int fd1=open(“hai.txt”,O_WRONLY); int ret = close(“hai.txt”); int fd2=open(“hai.txt”,O_RDONLY); printf(“%d”,fd2); } (a) 4 (b) –1 (c) 3 (d) None of the above Answer: (b) ‘close’ system call temporarily closes the file. It can be regained on restart. 148. What is the output of the code when “hai.txt” has “hai”? (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); int ret = close(“hai.txt”); char c[10]; read(fd1,c,3); printf(“%s”,c); } (a) hai (b) Segmentation fault (c) –1 (d) None of the above Answer: (a) Even though the file is closed, the data is still associated with FD. 149. What is the output of the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_WRONLY); int ret = close(fd1);
Process Management 67
int fd2=open(“hai.txt”,O_RDONLY); printf(“%d”,fd2); } (a) 4 (b) –1 (c) 3 (d) None of the above Answer: (c) Close can take a FD as input and closen it. So the FD is available for any next file. So the second open will also get FD 3. 150. What is the output of the code when “hai.txt” exists? (L3) void main() { int ret = close(2); int fd2=open(“hai.txt”,O_RDONLY); printf(“%d”,fd2); } (a) –1 (b) 2 (c) 3 (d) None of the above Answer: (b) Even basic files can be closed. Here the Error FD can be opened again by restarting the system. 151. What is the output of the code when “hai.txt” exists? (assume PID of the process is 3600) (L2) void main() { int fd1=open(“hai.txt”,O_RDONLY); printf(“%d”,getpid()); } (a) 3 (b) 3600 (c) 3602 (d) None of the above Answer: (b) ‘getpid()’ is the system call used to get the process ID of the current file. 152. What is the output of the code when “hai.txt” exists? (assume PID of the process is 3600) (L2) void main() { int fd1=open(“hai.txt”,O_RDONLY); printf(“%d”,getpid()); int fd2=open(“hai.txt”,O_RDONLY); printf(“%d”,getpid()); } (a) 3600 3600 (b) 3600 3602 (c) 3602 3602 (d) None of the above Answer: (a) The process ID of the running process will never change. 153. What is the output of the code when “hai.txt” exists? (assume PID of the process is 3600) (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); printf(“%d”,getppid()); } (a) 1 (b) 0 (c) Some random number (d) None of the above
68 Cracking the Operating Systems Skills
Answer: (d) The actual output is 1, the global parent. ‘getppid()’ gets the parent process ID. Basically, all the processes are launched by the running OS process 1. So it is the parent for all processes other than reproduced processes. But in most of the modern OS structures it is designed on such a way that the global parent 1 creates a subfile and allocates it as parent for all other normal files. This is to reduce the kernel overhead. This number will be given by the function as it is in charge of creating and launching every new process. 154. State true or false (L2) Statement: all process has the same parent id. (a) True (b) False (c) OS dependent Answer: (b) All normal processes have the same global parent. But processes that are launched by other processes or produced by others like ‘fork()’ gets a different parent ID, the ID of the launching/creating process. 155. What is the output of the code when “hai.txt” exists? (assume PID of the process is 3600) (L2) void main() { int fd1=open(“hai.txt”,O_RDONLY); printf(“%d”,getpid(fd1)); int fd2=open(“hai.txt”,O_RDONLY); printf(“%d”,getpid(fd2)); } (a) 3600 3600 (b) –1 –1 (c) 0 0 (d) None of the above Answer: (d) This throws errors as ‘getpid()’ cannot take arguments. 156. What will be error thrown by the code when “hai.txt” exists? (L3) void main() { int fd1=open(“hai.txt”,O_RDONLY); printf(“%d”,getpid(fd1)); int fd2=open(“hai.txt”,O_RDONLY); printf(“%d”,getpid(fd2)); } (a) Fatal error: getpid: cannot take any arguments (b) Too many arguments to function ‘getpid’ (c) kernel version dependent (d) None of the above Answer: (b) It also shows a note, the definition prototype of ‘getpid’ for reference. 157. What is the output of the code when “hai.c” exists? (assume this is the first process launched) (L2) void main() { int fd= opne(“hai.c”,O_RDONLY); printf(“%d”, fd); }
Process Management 69
(a) 3 (b) Garbage values (c) Error (d) None of the above Answer: (c) “Undefined reference to `open`”. 158. What is the output of the code when “hai.txt” has “hai”? (L3) void main() { char c[5]; read(open(“hai.txt”,O_RDONLY),c,3); printf(“%s”,c); } (a) hai (b) Garbage symbols (c) Error (d) None of the above Answer: (a) This works normally. The FD returned by ‘open’ is directly passed to the read call. 159. What is the output of the code when “hai.txt” has “hai”? (L3) void main() { char c[5]; read( “hai.txt”,c,3); printf(“%s”,c); } (a) hai (b) Garbage symbols (c) Error (d) None of the above Answer: (b) As the read call cannot open the file, it prints garbage value. 160. What is the output of the code? (L1) void main() { int ret = system(“ls”); } (a) ls (b) –1 (c) Executes the command “ls” (d) None of the above Answer: (c) ‘system’ is a system call that executes the specified command.
4
Multithreading and Scheduling
This chapter deals with multithreading which is the ability of an operating system process to manage its use by more than one user at a time and also manage multiple requests by the same user in the computer. This chapter also covers scheduling which is the method by which work specified by some means is assigned to resources that complete the work. 1. Many software packages that run on modern desktop PCs are ________ (L1) (a) Single threaded (b) Double threaded (c) Multithreaded (d) Any of the above Answer: (c) Multithreaded 2. The benefits of multithreaded programming are ________ (L1) (a) Responsiveness (b) Resource sharing (c) Economy and scalability (d) All of the above Answer: (d) All of the above 3. Testing and debugging such concurrent programs is inherently ________ than testing and debugging single-threaded applications. (L1) (a) More difficult (b) More easier (c) Different (d) Same Answer: (a) More difficult 4. The one-to-one model maps ________ (L1) (a) Each user thread to multiple kernel threads (b) Each user thread to a kernel thread (c) Many user threads to a single kernel thread (d) Any of the above Answer: (b) Each user thread to a kernel thread 5. The many-to-many model maps ________ (L1) (a) Many user threads to multiple kernel threads (b) Each user thread to a kernel thread
Multithreading and Scheduling 71
(c) Many user level threads to a smaller or equal number of kernel threads (d) Any of the above Answer: (c) Many user level threads to a smaller or equal number of kernel threads 6. ________ implement the one-to-one model (L2) (a) Linux (b) Windows operating system (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 7. ________ implement the two-level model (L2) (a) IRIX (b) HP-UX (c) TRU64 UNIX (d) All of the above Answer: (d) All of the above 8. A ________ provides the programmer with an API for creating and managing threads. (L1) (a) Application (b) Thread library (c) Kernel (d) Framework Answer: (b) Thread library 9. The main thread library that is in use nowadays is ________ (L3) (a) POSIX Pthreads (b) Win32 (c) Java (d) All of the above Answer: (d) All of the above 10. ________ refers to the POSIX standard defining an API for thread creation and synchronization. (L2) (a) Java (b) Pthreads (c) Mutex (d) All of the above Answer: (b) Pthreads 11. Threads are the fundamental model of program execution in a ________ program (L1) (a) Java (b) C (c) Microprocessor (d) COBOL Answer: (a) Java 12. ________ is the task of terminating a thread before it has completed. (L2) (a) Thread start (b) Thread cancellation (c) Application cancellation (d) Framework destroy Answer: (b) Thread cancellation
72 Cracking the Operating Systems Skills
13. A thread that is to be cancelled is often referred to as the ________ (L2) (a) Thread start (b) Thread cancellation (c) Target thread (d) Framework destroy Answer: (c) Target thread 14. ________ is a method in which one thread immediately terminates the target thread. (L2) (a) Thread cancellation (b) Synchronous cancellation (c) Asynchronous cancellation (d) Any of the above Answer: (c) Asynchronous cancellation 15. ________ is a method which periodically checks whether it should terminate, allowing it an opportunity to terminate itself in an orderly fashion. (L3) (a) Deferred cancellation (b) Synchronous cancellation (c) Asynchronous cancellation (d) Any of the above Answer: (a) Deferred cancellation 16. The number of threads in the pool can be set heuristically based on ________ (L2) (a) Number of CPUs in the system (b) The amount of physical memory (c) Expected number of concurrent client requests (d) All of the above Answer: (d) All of the above 17. A multithreaded process contains several different flows of control ________ (L2) (a) Within the same address space (b) Anywhere in the memory (c) In various address spaces (d) All of the above Answer: (a) Within the same address space 18. User-level threads are threads that are visible to the programmer and are unknown to the ________ (L2) (a) Application (b) Kernel (c) Frameworks (d) All of the above Answer: (b) Kernel 19. CPU ________ is the basis of multiprogrammed operating systems (L1) (a) Scheduling (b) Interrupts (c) Signals (d) stalling Answer: (a) Scheduling
Multithreading and Scheduling 73
20. By switching the CPU among processes, the operating system can make the computer ________ (L1) (a) To sleep (b) More productive (c) To interrupt (d) All of the above Answer: (b) More productive 21. The objective of multiprogramming is to have some process running at all times, to maximize ________ (L1) (a) Cost (b) Software utilization (c) CPU utilization (d) Time Answer: (c) CPU utilization 22. Process execution consists of a cycle of ________ (L2) (a) CPU execution (b) I/O wait (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 23. Process execution begins with a ________ and is followed by an ________ (L2) (a) CPU burst, another CPU burst (b) I/O burst, memory burst (c) I/O burst, CPU burst (d) Neither a nor b Answer: (d) CPU burst, I/O burst 24. An I/O-bound program typically has many short ________ (L2) (a) CPU bursts (b) I/O bursts (c) Memory bursts (d) Any of the above Answer: (a) CPU bursts 25. The ________ is the module that gives control of the CPU to the process selected by the short-term scheduler. (L2) (a) Scheduler (b) Dispatcher (c) Memory (d) Frameworks Answer: (b) Dispatcher 26. Dispatcher function involves ________ (L3) (a) Switching context (b) Switching to user mode (c) Jumping to the proper location in the user program to restart that program (d) All of the above Answer: (d) All of the above
74 Cracking the Operating Systems Skills
27. The dispatcher should be as ________ possible, since it is invoked during every process switch. (L2) (a) Fast (b) Slow (c) Cost effective (d) Time effective Answer: (a) Fast 28. The time it takes for the dispatcher to stop one process and start another running is known as the ________ (L2) (a) Signalling (b) Scheduling (c) Dispatch latency (d) Total time Answer: (c) Dispatch latency 29. Conceptually, CPU utilization can range from ________ (L2) (a) 0 to 100% (b) 0 to 10% (c) 10 to 90% (d) 90 to 100% Answer: (a) 0 to 100% 30. One measure of work is the number of processes that are completed per time unit, called ________ (L2) (a) Throughput (b) Total work (c) Total time (d) Unit time Answer: (a) Throughput 31. The interval from the time of submission of a process to the time of completion is the ________ (L2) (a) Total time (b) Interval time (c) Turnaround time (d) Unit time Answer: (c) Turnaround time 32. ________ time is the sum of the periods spent waiting in the ready queue. (L2) (a) Unit time (b) Waiting time (c) Turnaround time (d) Total time Answer: (c) Waiting 33. The time from the submission of a request until the first response is produced is called ________ (L2) (a) Response time (b) Turnaround time (c) Waiting time (d) Total time Answer: (a) Response time
Multithreading and Scheduling 75
34. It is desirable to maximize ________ (L2) (a) CPU utilization (b) Throughput (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 35. It is desirable to minimize ________ (L2) (a) Turnaround time (b) Waiting time (c) Response time (d) All of the above Answer: (d) All of the above 36. The simplest CPU-scheduling algorithm is the ________ (L1) (a) First-come, last-served scheduling algorithm (b) First-come, first-served scheduling algorithm (c) Last-come, first-served scheduling algorithm (d) All of the above Answer: (b) First-come, first-served scheduling algorithm 37. The average waiting time under the FCFS policy is ________ (L2) (a) Quite long (b) Quite short (c) Medium (d) unpredictable Answer: (a) Quite long 38. Pre-emptive SJF scheduling is sometimes called ________ (L1) (a) Priority scheduling (b) FCFS scheduling (c) Shortest-remaining-time-first scheduling (d) Last-come, last-serve scheduling Answer: (c) Shortest-remaining-time-first scheduling 39. In ________ scheduling algorithm, a priority is associated with each process, and the CPU is allocated to the process with the highest priority. (L1) (a) FCFS (b) Priority (c) Shortest-remaining-time-first scheduling (d) Last-come, last-serve scheduling Answer: (b) Priority 40. A major problem with priority scheduling algorithms is ________ (L2) (a) Time taken to switch (b) Cost involved (c) Starvation (d) All of the above Answer: (c) Starvation
76 Cracking the Operating Systems Skills
41. The round robin scheduling algorithm is designed especially for ________ (L2) (a) Time sharing systems (b) High cost involved systems (c) Starving systems (d) Any of the above Answer: (a) Time sharing systems 42. In round robin scheduling, a small unit of time, called a ________ is defined. (L2) (a) Clock (b) signal (c) Time slice (d) Interrupt Answer: (c) Time slice 43. A ________ scheduling algorithm partitions the ready queue into several separate queues (L2) (a) FCFS (b) Multilevel queue (c) Round robin (d) SJF Answer: (b) Multilevel queue 44. The ________ queue scheduling algorithm, in contrast, allows a process to move between queues. (L3) (a) Round robin (b) Multilevel (c) Multilevel feedback (d) FCFS Answer: (c) Multilevel feedback 45. One distinction between user-level and kernel-level threads lies in how they are ________ (L2) (a) Interrupted (b) Scheduled (c) Written (d) Separated Answer: (b) Scheduled 46. To decide which kernel thread to schedule onto a CPU, the kernel uses ________ (L2) (a) Software application (b) Interrupt mechanism (c) Scheduling algorithm (d) System-contention scope Answer: (d) System-contention scope 47. User-level thread priorities are set by the ________ (L2) (a) Thread itself (b) Software application (c) Programmer (d) System administrator Answer: (c) Programmer 48. If multiple CPUs are available, ________ becomes possible (L2) (a) Load sharing (b) Cost sharing (c) Administration (d) Programming Answer: (a) Load sharing
Multithreading and Scheduling 77
49. Asymmetric multiprocessing has ________ handled by a single processor – the master server (L2) (a) Scheduling decisions (b) I/O processing (c) System activities (d) All of the above Answer: (d) All of the above 50. In case of ________, the processor is self-scheduling (L2) (a) Asymmetric multiprocessing (b) Symmetric multiprocessing (c) Both a and b (d) Neither a nor b Answer: (b) Symmetric multiprocessing 51. SMP systems try to avoid migration of processes from one processor to another and instead attempt to keep a process running on the same processor because of ________ (L2) (a) High cost of invalidating and repopulating cache (b) Huge time taken to process (c) Huge memory wasted (d) All of the above Answer: (a) High cost of invalidating and repopulating cache 52. A process that has an affinity for the processor on which it is currently running is called as ________ (L2) (a) Symmetric processor (b) Processor affinity (c) Thread dependent processor (d) Uniprocessor Answer: (b) Processor affinity 53. When an operating system has a policy of attempting to keep a process running on the same processor but not guaranteeing that it will do so is ________ (L3) (a) Soft affinity (b) Hard affinity (c) Single processor (d) Multiprocessor Answer: (a) Soft affinity 54. ________ attempts to keep the workload evenly distributed across all processors in an SMP system. (L2) (a) Hard balancing (b) Soft balancing (c) Load balancing (d) None of the above Answer: (c) Load balancing 55. With ________, a specific task periodically checks the load on each processor and, if it finds an imbalance, it evenly distributes the load by moving processes from overloaded to idle or less busy processors. (L3) (a) Pull migration (b) Push migration (c) Task migration (d) None of the above Answer: (b) Push migration
78 Cracking the Operating Systems Skills
56. ________ occurs when an idle processor pulls a waiting task from a busy processor. (L1) (a) Push migration (b) Pull migration (c) Task migration (d) None of the above Answer: (b) Pull migration 57. A recent trend in computer hardware is to place multiple processor cores on the same physical chip, resulting in a ________ (L2) (a) Multicore processor (b) Single core processor (c) Multithread processor (d) Symmetric multiprocessor Answer: (a) Multicore processor 58. With ________ multithreading, a thread executes on a processor until a long latency event such as a memory stall occurs. (L3) (a) Single core (b) Fine grained (c) Coarse grained (d) Symmetric Answer: (c) Coarse grained 59. ________ multithreading switches between threads at a much finer level of granularity – typically at the boundary of an instruction cycle. (L2) (a) Symmetric (b) Fine grained (c) Coarse grained (d) Single core Answer: (b) Fine grained 60. A system with ________, even a single-CPU system, frequently acts like a multiprocessor system. (L2) (a) Interrupts (b) Multiple threads (c) Multiple cores (d) Virtualization Answer: (d) Virtualization 61. ________ uses priority based thread scheduling (L3) (a) Solaris (b) Windows (c) iOS (d) All the above Answer: (a) Solaris 62. ________ schedules threads using a priority based, pre-emptive scheduling algorithm. (L3) (a) Linux (b) Windows XP (c) iOS (d) All the above Answer: (b) Windows XP
Multithreading and Scheduling 79
63. The portion of the Windows XP kernel that handles scheduling is called ________ (L3) (a) Interrupt (b) Signal (c) Dispatcher (d) Scheduler Answer: (c) Dispatcher 64. If no ready thread is found, the dispatcher will execute a special thread called the ________ (L3) (a) Wait thread (b) Idle thread (c) Dispatch thread (d) Timer thread Answer: (b) Idle thread 65. The ________ scheduler is a pre-emptive, priority based algorithm with two separate priority ranges: a real-time range from 0 to 99 and a nice value ranging from 100 to 140. (L3) (a) Windows (b) Linux (c) Solaris (d) iOS Answer: (b) Linux 66. CPU-scheduling algorithm should consider ________ (L2) (a) Maximizing CPU utilization under the constraint that the maximum response time is 1 second (b) Maximizing throughput such that turnaround time is (on average) linearly proportional to total execution time (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 67. ________ modeling is an analytic evaluation in which a particular predetermined workload is taken and defines the performance of each algorithm for that workload. (L3) (a) Deterministic (b) Queueing (c) Simulation (d) None of the above Answer: (a) Deterministic 68. To get a more accurate evaluation of scheduling algorithms, we can use ________ (L2) (a) Trial and run method (b) Simulation (c) Queueing (d) Any of the above Answer: (b) Simulation
80 Cracking the Operating Systems Skills
69. The stimulator must first mimic the system on which the scheduling is to be done. This is done by a collection of variables that captures the salient properties of the system. This variable set is ________ (L2) (a) System (b) Specification (c) State (d) None of the above Answer: (c) State 70. The simulator has a variable representing a clock; as this variable’s value is increased, the simulator modifies the system state to reflect ________ (L2) (a) The activities of the devices (b) The processes (c) The scheduler (d) All of the above Answer: (d) All of the above 71. The general approaches that are used to handle critical sections in operating systems are ________ (L2) (a) Pre-emptive kernels (b) Non pre-emptive kernels (c) Both a and b (d) Neither a nor b Answer: (c) Both a and b 72. A ________ kernel allows a process to be pre-empted while it is running in kernel mode (L2) (a) Pre-emptive (b) Non pre-emptive (c) Both a and b (d) Neither a nor b Answer: (a) Pre-emptive 73. A non-pre-emptive kernel is essentially free from ________ on kernel data structures, as only one process is active in the kernel at a time. (L2) (a) Interrupts (b) Race conditions (c) Signals (d) Data structures Answer: (b) Race conditions 74. Race conditions are prevented by requiring that critical regions be protected by ________ (L2) (a) Threads (b) Signals (c) Locks (d) APIs Answer: (c) Locks 75. A ________ is a thread synchronization construct that can be used either to send signals between threads to avoid missed signals, or to guard a critical section like you would with a lock. (L2) (a) Lock (b) Signals (c) Interrupts (d) Semaphore Answer: (d) Semaphore
Multithreading and Scheduling 81
76. No two processes can execute ________ operations on the same semaphore at the same time. (L2) (a) Lock and unlock (b) wait() and signal() (c) Interrupts and signals (d) Semaphore and locks Answer: (b) wait() and signal() 77. In a multiprocessor environment, ________ must be disabled on every processor; otherwise, instructions from different processes (running on different processors) may be interleaved in some arbitrary way. (L2) (a) Locks (b) signals (c) Interrupts (d) All of the above Answer: (c) Interrupts 78. A semaphore with a waiting queue may result in a situation where two or more processes are waiting indefinitely for an event that can be caused only by one of the waiting processes. These processes are said to be ________ (L2) (a) Locked (b) Deadlocked (c) Interrupted (d) Signalled Answer: (b) Deadlocked 79. A scheduling challenge arises when a higher-priority process needs to read or modify kernel data that are currently being accessed by a lower-priority process-or a chain of lower-priority processes. Such cases we use ________ (L2) (a) Priority inversion (b) Interrupts (c) Signals (d) Locks Answer: (a) Priority inversion 80. What is the output of the code? (L3) void main() { int ret = system(“ls”); printf(“%d”,ret); } (a) 0 (b) –1 (c) 1 (d) None of the above Answer: (a) Even the success gives 0 as any other system call. But executes the command “ls” before it. 81. What is the output of the code? (L3) void main() { char c[ ] = “ls”; int ret = system (c); } (a) Executes “ls” command (b) Prints nothing (c) Compiler traps (d) None of the above Answer: (a) Even this works. It just requires a string.
82 Cracking the Operating Systems Skills
82. What is the output of the code? (L3) void main() { int ret = system(“ASDF”); } (a) Error (b) Prints nothing (c) Compiler traps (d) None of the above Answer: (d) Compilation is not a problem as the syntax is correct, “system” takes a string as argument. But executing this has a logical error. 83. What will be the error thrown by the code? (L3) void main() { int ret = system(“ASDF”); } (a) Fatal error: ASDF: command not found (b) sh: ASDF: not found (c) Fatal error: ASDF: definition not found (d) Compiler dependent Answer: (b) Commands will have a definition. As all the commands are a part of shell it is a ‘sh’ error. For the command “ASDF” the same will be searched in the file system. So when the appropriate code is missing it just gives “not found” instead of telling “command not found”. 84. What is the output of the code? (L3) void main() { int ret = system(“ASDF”); printf(“%d”,ret); } (a) –1 (b) 0 (c) Any negative number other than -1 (d) None of the above Answer: (d) It gives 32512. This is the termination status of the system call. This is mainly because the specified command cannot be found. For other different problems it may differ. 85. State true or false. (L2) Statement: the return value of “system” function call will never be -1. (a) True (b) False Answer: (b) it will be –1 when the termination itself fails. When a child process cannot be created at the required scenario or the termination status of the command line interpreter cannot be found, it gives –1.
Multithreading and Scheduling 83
86. What is the output of the code? (L3) void main() { int ret = system( ); printf(“%d”,ret); } (a) 32512 (b) 0 (c) Any negative number other than –1 (d) Error Answer: (a) Now there is no command to search. So termination status is the same. 87. What is the output of the code? (L3) void main() { void *p; int ret = system(p); printf(“%d”,ret); } (a) 32512 (b) 0 (c) Error (d) None of the above Answer: (d) This gives 1. Even an int or float pointer gives the same value. But there won’t be any error. 88. What is the output of the code? (L3) void main() { void *p= NULL; int ret = system(p); printf(“%d”,ret); } (a) 1 (b) 0 (c) Error (d) None of the above Answer: (a) Even in the case of NULL pointer it gives the same result 1, when it fails. 89. What is the result of the code? (L3) void main() { int ret = system(“fork()”); } (a) Compiler traps (b) Nothing happens (c) Error (d) None of the above Answer: (c) It’s not a compiler error, it’s a logical error. “fork()” is a system call that is used to create child pocess. 90. What is the result of the code? (L3) void main() { int ret = system(“fork()”); } (a) sh: fork(): not found (b) sh: 1: Syntax error: end of file unexpected
84 Cracking the Operating Systems Skills
(c) sh: 0: fork: no function found (d) None of the above Answer: (b) The syntax of ‘fork()’ is an error. 91. What is the output of the code? (after the logical error) (L3) void main() { int ret = system(“fork()”); printf(“%d”,ret);} (a) 0 (b) 1 (c) 5312 (d) None of the above Answer: (d) 512. 92. What is the output of the code? (L3) void main() { int ret = system(“open()”); printf(“%d”,ret);} (a) ’logical error: sh: 1: Syntax error: end of file unexpected’ followed by 512 (b) ’logical error: sh: 1: Syntax error: end of file unexpected’ followed by 0 (c) ’logical error: sh: 1: Syntax error: end of file unexpected’ followed by 1 (d) None of the above Answer: (a) Any system call passed as an argument to ‘system’ system call results in the same logical error. 93. What is the output of the code when “hai.txt” exists? (L3) void main() { int ret = system(“open(“hai.txt”,O_RDONLY)”); printf(“%d”,ret);} (a) ’logical error: sh: 1: Syntax error: end of file unexpected’ followed by 512 (b) prints nothing (c) compilation error (d) None of the above Answer: (c) The “” for ‘hai.txt’ in the argument to ‘system’ system call breaks the arguments into two strings with a constant in between. The constant is ‘hai.txt’ as it is the only part not surrounded by quotes. 94. What is the error of the code when “hai.txt” exists? (L3) void main() { int ret = system(“open(“hai.txt”,O_RDONLY)”); printf(“%d”,ret);}
Multithreading and Scheduling 85
(a) Expected ‘)’ before ‘hai’ (b) Invalid arguments to ‘system’ (c) ‘open’ passed as argument to ‘system’ (d) None of the above Answer: (a) All the problem is due to the “” of ‘hai.txt’ 95. What is the output of the code? (L3) void main() { int ret = system(“open(\“hai.txt\”,O_RDONLY)”); printf(“%d”,ret);} (a) ‘logical error: sh: 1: Syntax error: end of file unexpected’ followed by 512 (b) ‘logical error: sh: 0: Syntax error: end of file unexpected’ followed by 512 (c) ‘logical error: sh: 1: Fatal error: end of file unexpected’ followed by 512 (d) ‘None of the above Answer: (d) ‘logical error: sh: 1: Syntax error: word unexpected (expecting “)”)’ followed by 512. This is because it internally treats ‘open’ as argument to ‘system’ and ‘hai.txt’ as argument to ‘open’ which is not expected. 96. What is the output of the code? (L3) void main() { execl(“/bin/ls”, “ls”,0,0); } (a) Executes the command ‘ls’ (b) Prints nothing (c) Compiler traps (d) None of the above Answer: (a) ‘execl’ is a system call that executes the specified command. It is different from ‘system’. It aborts the execution of the program and transfers the control to execute the command. The first argument is the path of the command. The second argument is the command itself. Whereas the third argument is the option to be specified to the command, if any. If no option is needed just can be skipped. Even more than one option can be specified. The final argument is always 0, just as a terminator for the argument list. It stands for ‘EXECute and Leave’ 97. What is the output of the code? (L2) void main() { execl(“/bin/ls”, “ls”,0); } (a) Executes the command ‘ls’ (b) Prints nothing (c) Compiler traps (d) None of the above Answer: (a) As said above this too works. As no option is required it can be skipped and the last argument is 0 as well.
86 Cracking the Operating Systems Skills
98. What is the output of the code? (L3) void main() { execl(“/bin/ls”, “ls”,0); printf(“hai”);} (a) Executes the command ‘ls’ (b) Executes the command ‘ls’ and prints “hai” (c) Prints “hai” and executes the command ‘ls’ (d) None of the above Answer: (a) ‘execl’ doesn’t bring the control back to the function after executing the command. 99. What is the output of the code? (L2) void main() { execl(“/bin/ls”, “ls”, “–lrt”,0); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) Error (c) Compiler dependent (d) None of the above Answer: (a) Here “–lrt” is the additional option specified for the command. It works normally. 100. What is the output of the code? (L3) void main() { execl(“/bin/ls”, “ls”, “–l”, “–r”, “–t”,0); printf(“hai”);} (a) Executes the command ‘ls –l’ (b) Executes the command ‘ls –r’ (c) Executes the command ‘ls –t’ (d) Executes the command ‘ls –lrt’ (e) None of the above Answer: (d) “ls –l –r –t” is same as “ls –lrt”. 101. What is the output of the code? (L3) void main() { execl(“ls”, “ls”, “–l”, “–r”, “–t”,0); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) Compilation error (c) Logical error (d) None of the above Answer: (d) It skips the system call (fails) as the command is not available in the specified path or the specified path is not valid. So prints “hai”.
Multithreading and Scheduling 87
102. What is the output of the code? (L3) void main() { execl(“/bin/”, “ls”, “–l”, “–r”, “–t”,0); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) hai (c) Logical error (d) None of the above Answer: (d) Even now the path specified doesn’t contain the definition of ‘ls’. So the same “hai” is printed. 103. What is the output of the code when the executable file ‘ls’ is copied from “bin” into desktop of user? (L3) void main() { execl(“/home/user/Desktop/ls”, “ls”, “–lrt”,0); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) hai (c) Logical error (d) None of the above Answer: (a) When the definition is available in specified address it just uses it. 104. What is the output of the code when the executable file ‘ls’ is copied into the desktop of user and renamed as “fun”? (L3) void main() { execl(“/home/user/Desktop/fun”, “ls”, “–lrt”,0); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) hai (c) Logical error (d) None of the above Answer: (a) Even this works normally. It is just a file and file name, and thus can be changed. 105. What is the output of the code? (L3) void main() { execl(“/bin/ls”, “ls”, “–l”, “–r”, “–t”); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) hai (c) Logical error (d) None of the above Answer: (c) When the argument list is not properly terminated it causes some problems. 106. What will be the error thrown by the code? (L3) void main() { execl(“/bin/ls”, “ls”, “–l”, “–r”, “–t”); printf(“hai”);}
88 Cracking the Operating Systems Skills
(a) sh: 1: syntax error: no such file or directory (b) ls: cannot access : no such file or directory (c) sh: 1: ls: command missing (d) None of the above Answer: (b) The garbage values is the file name formed by the compiler. The issue is mainly due to the missing termination 0. 107. What is the output of the code? (L3) void main() { execl(“/bin/ls”, “ls”, “lrt”); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) hai (c) Logical error (d) None of the above Answer: (a) There is a size in the path specified “bin/ls”. This makes the path unavailable and the system call fails. Thus the program is executed further and “hai” is printed. 108. What is the output of the code? (L3) void main() { execl(“/bin/ls”, “ls”, “lrt”); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) hai (c) Logical error (d) None of the above Answer: (a) Even this works. Here the termination 0 doesn’t cause confusion as there are no more arguments to be specified as option. Single argument is treated normally and only then the next argument is checked for 0. So this works normally. 109. What is the output of the code? (L3) void main() { execl(“ls”, “ls”, “lrt”); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) hai (c) Logical error (d) None of the above Answer: (b) Here only the file name is specified without the path to the file. So ‘execl’ fails to find the file and thus, ‘hai’ is printed. 110. What is the output of the code? (L3) void main() { execlp(“ls”, “ls”, “–lrt”); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (c) Logical error
(b) hai (d) None of the above
Multithreading and Scheduling 89
Answer: (a) ‘execlp’ is a system call that acts the same as ‘execl’, but here the path to the specified file is not required. When the file name is given it automatically searches inside and finds the location. Note: It can be interpreted that, ‘system()’ system call is a combination of ‘execlp()’ and ‘fork()’. ‘system()’ is equivalent to ‘fork()’ followed by ‘execlp()’ by the child. ‘fork()’ is a system call that produces a child process along with the parent process, discussed in later sections. 111. What is the output of the code? (L3) void main() { execlp(“/bin/ls”, “ls”, “–lrt”); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) hai (c) Logical error (d) None of the above Answer: (a) ‘execl’ cannot skip address, but ‘execlp’ can have address. Its job of searching is reduced by specifying the address. 112. What is the output of the code when ‘ls’ file is copied into the desktop of the user and renamed as ‘fun’? (L3) void main() { execlp(“/home/user/Desktop/fun”, “ls”, “–lrt”); printf(“hai”);} (a) Executes the command ‘ls -lrt’ (b) hai (c) Logical error (d) None of the above Answer: (a) Even this works normally. 113. What is the output of the code when ‘ls’ file is copied into the desktop of the user and renamed into ‘fun’? (L3) void main() { execlp(“fun”, “ls”, “–lrt”); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) hai (c) Logical error (d) None of the above Answer: (b) The specified file name will be searched only in mount file system and not in user files. ‘fun’ is present in the desktop only. So ‘execlp’ fails as it didn’t find the file and executes the remaining part of the program. 114. What is the output of the code when ‘hai.txt’ exists? (L3) void main() { execlp(“ls”, “gedit”, “hai.txt”); printf(“hai”);}
90 Cracking the Operating Systems Skills
(a) Prints ‘hai’ (c) Error Answer: (c) It is a logical error.
(b) Opens ‘hai.txt’ in text editor (d) None of the above
115. What is the logical error thrown by the code when ‘hai.txt’ exists in the desktop of the user? (L3) void main() { execlp(“ls”, “gedit”, “hai.txt”); printf(“hai”);} (a) sh: 1: Syntax error: incomplete syntax of ‘gedit’ (b) sh: 1: fatal error: no such file or directory (c) sh: 1: fatal error: cannot find ‘hai.txt’ (d) None of the above Answer: (d) It gives ‘gedit: cannot access hai.txt: No such file or directory’. Actually here ‘gedit’ works normally, but ‘hai.txt’ is not in the same directory. 116. What is the output of the code when ‘hai.txt’ exists in desktop of user? (L3) void main() { execlp(“ls”, “gedit”, “/home/user/Desktop/hai.txt”); printf(“hai”);} (a) Logical error- gedit: cannot access hai.txt: No such file or directory (b) Logical error- sh: 1: fatal error: no such file or directory (c) Prints ‘hai’ (d) None of the above Answer: (d) It gives ‘gedit: cannot access /home/user/desktop/hai.txt: No such file or directory’. ‘gedit’ doesn’t support this form of opening of files. 117. What is the output of the code? (L3) void main() { execlp(“ls”, “clear”, 0); printf(“hai”);} (a) Executes the command ‘clear’ (b) Executes the command ‘ls’ (c) Prints ‘hai’ (d) None of the above Answer: (b) The second argument is the command. Logically the file name and the command are same. Every command (with different arguments) is treated as an sub file inside the base file. At such instances when the command name is mentioned differently (not existing), but the file name and path is valid, Linux searches for the file (inside the base file) when it is not present the basic command without any arguments is executed. 118. What is the output of the code? (L3) void main() { execlp(“ls”, “clear”); printf(“hai”);}
Multithreading and Scheduling 91
(a) Executes the command ‘clear’ (b) Executes the command ‘ls’ (c) Prints ‘hai’ (d) None of the above Answer: (d) It gives logical error ‘clear: cannot access : No such file or directory’. As the termination 0 is missing, the file name is created abnormally and while searching for the same creates further issues. 119. What is the output of the code? (L3) void main() { execlp(“clear”, “clear”,0); printf(“hai”);} (a) Executes the command ‘clear’ (b) Logical error (c) Prints ‘hai’ (d) None of the above Answer: (a) This works normally and clears the terminal. 120. What is the output of the code? (L3) void main() { execlp(“clear”, “clear”); printf(“hai”);} (a) Executes the command ‘clear’ (b) Logical error (c) Prints ‘hai’ (d) None of the above Answer: (a) This too works normally, still shows a warning of incomplete arguments while compiling. 121. What is the output of the code? (L3) void main() { execlp(“clear”, “ls”, “–lrt”,0); printf(“hai”);} (a) Executes the command ‘clear’ (c) Logical error Answer: (a) Skips ‘ls’.
(b) Executes the command ‘ls -lrt’ (d) Prints ‘hai’
122. What is the output of the code? (L3) void main() { execlp(“clear”, “ls”, “–lrt”); printf(“hai”);} (a) Executes the command ‘clear’ (b) Executes the command ‘ls –lrt’ (c) Logical error (d) Prints ‘hai’ Answer: (a) When there is only one argument specified the sub file name is generated well and good. When there are multiple arguments specified the file name is generated by appending the list until a 0 is encountered and eventually ends up in adding some garbage into the name as 0 is missing. The logic of generating the sub file name is different in both the cases.
92 Cracking the Operating Systems Skills
123. What is the output of the code when ‘ls’ is copied into the desktop of the user and renamed as ‘fun’? (L3) void main() { execlp(“/home/user/Desktop/fun”, “clear”,0); printf(“hai”);} (a) Executes the command ‘clear’ (b) Executes the command ‘ls’ (c) Logical error (d) Prints ‘hai’ Answer: (b) As said above, even if the command passed is invalid the basic command of the file without any arguments is executed. 124. What is the output of the code? (L3) void main() { execlp(“clear”,0); printf(“hai”);} (a) Executes the command ‘clear’ (b) Compiler traps (c) Error (d) Prints ‘hai’ Answer: (a) Here the first argument specified is the file name. As the command is not specified the sub file name is not specified, but the 'clear' doesn't support any additional argument. So technically there will be only one definition (sub file) inside the command file. Thus, skipping it doesn’t have a difference. 125. What is the output of the code? (L3) void main() { execlp(“ls”); printf(“hai”);} (a) Executes the command ‘ls’ (b) Error (c) Prints ‘hai’ (d) None of the above Answer: (c) The termination 0 is important in such cases. It throws compilation error “ too few arguments to function ‘execlp’”. 126. What is the output of the code? (L3) void main() { execlp(“ls”,0); printf(“hai”);} (a) Executes the command ‘ls’ (b) Error (c) Prints ‘hai’ (d) None of the above Answer: (c) It throws a logical error. Unlike ‘clear’ command, ‘ls’ takes in options from the user. So gives a logical error. 127. What will be the error thrown by the code? (L3) void main() { execlp(“ls”,0); printf(“hai”);}
Multithreading and Scheduling 93
(a) sh: 1: fatal error: found end of file (b) sh: 1: syntax error: incomplete command ‘ls’ (c) Aborted (core dumped) (d) None of the above Answer: (d) It throws “ A NULL argv[0] was passed through an exec system call. Aborted (core dumped)”. 128. What is the output of the code? (L2) void main() { execlp(“ls”, “–lrt”,0); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) error (c) Prints ‘hai’ (d) None of the above Answer: (d) It executes the command ‘ls’. Here ‘–lrt’ is regarded as a command and not as an option. The sub file “lrt” is missing, thus the basic command is executed. 129. What is the output of the code? (L2) void main() { execlp(“ls”, “–lrt”); printf(“hai”);} (a) Executes the command ‘ls –lrt’ (b) Error (c) Prints ‘hai’ (d) None of the above Answer: (b) It shows the same logical error as usual as the terminating 0 is missing. It gives “ –lrt: cannot access : No such file or directory”. 130. What is the output of the code? (L2) void main() { execl(“/bin/clear”,0); printf(“hai”);} (a) Executes the command ‘clear’ (b) Error (c) Prints ‘hai’ (d) None of the above Answer: (c) The path specified to ‘clear’ is wrong. 131. What is the output of the code when “hai.c” exists? (L1) void main() { struct stat s; stat(“hai.c”, &s); printf(“%d”,s.st_uid); } (a) 1000 (b) Error
94 Cracking the Operating Systems Skills
(c) Prints the user id of the user who created the file (d) None of the above Answer: (c) ‘stat’ is a pre-defined structure that is used to store the details of a file. ‘stat’ system call with a ‘stat structure pointer’ will initialise the object with the status of the corresponding file. The member ‘st_uid’ has the user id of the owner of the file. Mostly it is 1000 especially in single user environment. 132. What is the output of the code when “hai.c” exists? (L2) void main() { struct stat s; stat(“hai.c”, &s); printf(“%d”,s.st_nlink); } (a) 1 (b) Error (c) Prints the number of hard links the file has (d) None of the above Answer: (c) Hard link is the number of copies of the same file in the same name. 133. What is the output of the code when “hai.c” exists? (L2) void main() { struct stat s; stat(“hai.c”, &s); printf(“%d”,s.st_ino); } (a) 1 (b) Error (c) Prints the inode number (d) None of the above Answer: (c) In LINUX OS, inode is a data structure used to represent a file system object. Each inode stores the corresponding attributes of the associated file in disk partitions. So for reference, every inode has a number. This is inode number. 134. What is the output of the code when “hai.c” does not exist? (L3) void main() { struct stat s; stat(“hai.c”, &s); printf(“%d”,s.st_uid); } (a) 0 (b) Error (c) Prints the user id of the user who created the file (d) None of the above Answer: (a) When no such file exists, there cannot be a user. So just returns 0.
Multithreading and Scheduling 95
135. What is the output of the code when “hai.c” does not exist? (L3) void main() { struct stat s; stat(“hai.c”, &s); printf(“%d”,s.st_nlink); } (a) 0 (b) Error (c) Some garbage value (d) None of the above Answer: (d) Gives a negative garbage value to indicate nothing such exists. 0 is returned when the file itself is discarded as no process holds it open. 136. What is the output of the code when “hai.c” exists? (L2) void main() { struct stat s; int ret=stat(“hai.c”, &s); printf(“%d”,ret); } (a) 1 (b) Error (c) Some non-negative number (d) None of the above Answer: (d) It returns 0 as usual. 137. What is the output of the code when “hai.c” does not exist? (L1) void main() { struct stat s; int ret=stat(“hai.c”, &s); printf(“%d”,ret); } (a) –1 (b) Error (c) Some non-negative number (d) None of the above Answer: (a) As usual gives -1 for failure. 138. What is the output of the code when only one copy of “hai.c” exists? (L3) void main() { struct stat s,*v; v=&s; stat(“hai.c”, v); printf(“%d”, (*v).st_nlink); } (a) 1 (b) error (c) Segmentation fault (d) None of the above Answer: (a) This is logically same, so works properly.
96 Cracking the Operating Systems Skills
139. What is the output of the code when only one copy of “hai.c” exists? (L3) void main() { struct stat s; stat(“hai.c”, s); printf(“%d”, s.st_nlink); } (a) 1 (b) Error (c) Segmentation fault (d) None of the above Answer: (b) The second argument must be a pointer to a structure. So throws a compilation error “incompatible type for argument of ‘stat’ ”. 140. What is the output of the code when only one copy of “hai.c” exists? (L3) void main() { struct stat s; stat(“hai.c”, &s); s.st_nlink=3; printf(“%d”, s.st_nlink); } (a) 1 (b) 3 (c) Error (d) None of the above Answer: (b) Even the members can be edited. 141. What is the output of the code? (L2) void main() { struct stat s; printf(“%d”, s.st_nlink); } (a) 1 (b) Garbage value (c) Error (d) None of the above Answer: (d) By default it has some negative garbage values. It is not associated with any file, so technically equivalent to be associated with a non-existing file. Hence, the behaviour is same. 142. What is the output of the code? (L3) void main() { struct stat s; s.st_nlink=5; printf(“%d”, s.st_nlink); } (a) 5 (b) Negative garbage value (c) Error (d) None of the above Answer: (a) Structure members can also be accessed before initialising it using the ‘stat’ system call.
Multithreading and Scheduling 97
143. What is the output of the code? (L3) void main() { typedef struct stat v; v s; s.st_nlink=5; printf(“%d”, s.st_nlink); } (a) 5 (b) Negative garbage value (c) Error (d) None of the above Answer: (a) Even this is correct as they are logically same. 144. What is the output of the code? (L2) struct stat{ int link; }; void main() { struct stat v; v.link=9; printf(“%d %d”, v.st_nlink, v.link); } (a) Negative garbage value 9 (b) 0 9 (c) Error (d) None of the above Answer: (c) It throws a compilation error “redefinition of ‘struct stat’ ”. Also throws “ ‘strcut stat’ has no member named ‘st_nlink’ ”. 145. What is the output of the code when “hai.c” exists? (L3) void main() { int fd= open(“hai.c”,O_RDONLY); struct stat v; stat(fd,&v); printf(“%d”, v.st_nlink); } (a) 1 (b) –1 (c) Error (d) None of the above Answer: (d) ‘stat; system call doesn’t work the same for file name and FD number. For a specified fd it fails and the members get the default value. Even uid of this structure will have 0 only. 146. One of the added component that is involved in the CPU-scheduling function is the ___ (L3) (a) Dispatcher (b) Switches (c) Mutex (d) Process Answer: (a) Dispatcher
98 Cracking the Operating Systems Skills
147. Least time to go is a ___ scheduling algorithm (L3) (a) Static (b) Dynamic (c) Both a and b (d) Neither a nor b Answer: (b) Dynamic 148. A very common method in embedded systems is to ___ schedule jobs (L3) (a) FIFO (b) Dynamically (c) Manually (d) All of the above Answer: (c) Manually
5
Process Synchronization
This chapter deals with process synchronization that refers to the idea in which multiple processes are to join up or handshake at a certain point, in order to reach an agreement or commit to a certain sequence of action. 1. The ________ semaphore provides mutual exclusion for accesses to the buffer pool and is initialized to the value 1. (L1) (a) Single (b) Binary (c) Mutex (d) Multi Answer: (c) Mutex 2. Semaphores provide a convenient and effective mechanism for process synchronization but using them incorrectly can result in ________ errors that are difficult to detect (L1) (a) Crash (b) Syntax (c) Logical (d) Timing Answer: (d) Timing 3. A ________ data type encapsulates private data with public methods to operate on that data. (L1) (a) Integer (b) Abstract (c) Floating point (d) Complex Answer: (b) Abstract 4. A ________ type is an ADT which presents a set of programmer-defined operations that are provided mutual exclusion within the monitor. (L2) (a) Monitor (b) Abstract (c) Floating point (d) Integer Answer: (a) Monitor 5. To control access to critical sections, Solaris provides ________ (L2) (a) Adaptive Mutexes (b) Condition variables (c) Semaphores (d) All of the above Answer: (d) All of the above
100 Cracking the Operating Systems Skills
6. An ________ protects access to every critical data item. (L1) (a) Condition variables (b) Adaptive Mutex (c) Semaphores (d) All of the above Answer: (b) Adaptive Mutex 7. Solaris uses the adaptive-Mutex method to protect only data that are accessed by ________ segments. (L2) (a) Medium code (b) Long code (c) Short code (d) All of the above Answer: (c) Short code 8. Solaris uses ________ to order the list of threads waiting to acquire either an adaptive mutex or a reader-writer lock. (L2) (a) Mutex (b) Turnstiles (c) Adaptive Mutex (d) Semaphores Answer: (b) Turnstiles 9. A ________ is a queue structure containing threads blocked on a lock. (L2) (a) Semaphore (b) Mutex (c) Adaptive Mutex (d) Turnstile Answer: (d) Turnstile 10. To prevent a priority inversion, turnstiles are organized according to a ________ protocol (L2) (a) Highest priority (b) Turnstile specific (c) Priority inheritance (d) Shortest job first Answer: (c) Priority inheritance 11. ________ are similar to condition variables, that is, they may notify a waiting thread when a desired condition occurs. (L2) (a) Events (b) Signals (c) Interrupts (d) All of the above Answer: (a) Events 12. A ________ indicates that an object is available and a thread will not block when acquiring the object. (L2) (a) Interrupted state (b) Lock state (c) Event state (d) Signalled state Answer: (d) Signalled state
Process Synchronization 101
13. A ________ indicates that an object is not available and a thread will block when attempting to acquire the object. (L2) (a) Signalled state (b) Lock state (c) Non-signalled state (d) Event state Answer: (c) Non-signalled state 14. A relationship exists between the state of a dispatcher object and the state of a ________ (L1) (a) Thread (b) Signal (c) Event (d) Process Answer: (a) Thread 15. ________ kernel is fully pre-emptive, so a task can be pre-empted when it is running in the kernel. (L2) (a) Mac-Os (b) Linux (c) Solaris (d) Windows Answer: (b) Linux 16. The Linux kernel provides ________ for locking in the kernel (L2) (a) Spin locks (b) Semaphores (c) Reader-Writer versions of the spin and semaphore (d) All of the above Answer: (d) All of the above 17. Linux provides ________ to disable kernel pre-emption (L1) (a) Pre-empt_enable() (b) Pre-empt_disable() (c) Kernel_disable() (d) Thread_disable() Answer: (b) Pre-empt_disable() 18. The Pthreads API provides ________ for thread synchronization. (L2) (a) Mutex locks (b) Condition variables (c) RW locks (d) All of the above Answer: (b) All of the above 19. The mutual exclusion of critical sections ensures that the critical sections are executed ________ (L2) (a) Atomically (b) Parallely (c) All of the above (d) Any of the above Answer: (a) Atomically
102 Cracking the Operating Systems Skills
20. A collection of instructions that performs a single logical function is called ________ (L2) (a) Instruction (b) Transaction (c) Atomicity (d) Multithreading Answer: (b) Transaction 21. Information residing in ________ storage does not usually survive system crashes. (L2) (a) Cache (b) Non-volatile (c) Volatile (d) All of the above Answer: (c) Volatile 22. ________ are more reliable than main memory but less reliable than magnetic tapes. (L2) (a) Disks (b) SSD (c) Registers (d) All of the above Answer: (a) Disks 23. Information residing in ________ storage is never lost (L2) (a) Volatile (b) Non-volatile (c) Stable (d) All of the above Answer: (c) Stable 24. When a system failure occurs, we must consult the ________ to determine which transactions need to be redone and which need to be undone. (L2) (a) Registers (b) Interrupts (c) Log (d) All of the above Answer: (c) Log 25. One way to ensure ________ is to associate a lock with each data item and to require that each transaction follows a locking protocol that governs how locks are acquired and released. (L2) (a) Reliability (b) Serializability (c) Stability (d) All of the above Answer: (b) Serializability 26. A set of processes is in a ________ state when every process in the set is waiting for an event that can be caused only by another process in the set. (L2) (a) Deadlocked (b) Ready (c) Waiting (d) Running Answer: (a) Deadlocked
Process Synchronization 103
27. In a deadlock, processes never finish executing, and system resources are tied up, preventing other jobs from ________ (L2) (a) Executing (b) Sleeping (c) Waiting (d) Starting Answer: (d) Starting 28. A deadlock situation can arise if ________ occurs simultaneously in a system (L1) (a) Mutual exclusion (b) Hold and wait (c) No pre-emption, circular wait (d) All of the above Answer: (d) All of the above 29. We ________ the system to enter a deadlocked state, detect it, and recover. (L2) (a) Can allow (b) Cannot allow (c) Sometimes allow (d) Sometimes deny Answer: (a) Can allow 30. The mutual-exclusion condition must hold for ________ resources (L1) (a) Sharable (b) All (c) Non-sharable (d) Specific Answer: (c) Non-sharable 31. A state is ________ if the system can allocate resources to each process in some order and still avoid a deadlock. (L2) (a) Safe (b) Unsafe (c) Corrupted (d) Locked Answer: (a) Safe 32. What is the output of the code? (L2) void main() { int ret=fork(); if (ret==0) printf(“child ”); else if (ret>0) printf(“ parent”); } (a) Child parent (b) Parent child (c) Unpredictable (d) None of the above Answer: (c) Mostly it executes ‘parent’ first, still it is unpredictable. It may execute the parent or child anything first. It is based on the return value. If the return value is 0, then the child is going to execute first, if the return value is some positive number then the parent is going to execute first. The order can be changed through code using ‘sleep’ instruction.
104 Cracking the Operating Systems Skills
33. What is the output of the code? (L2) void main() { int ret=fork(); if (ret==0) printf(“child ”); else if (ret>0) { sleep(2); printf(“ parent”); }} (a) Child parent (b) Parent child (c) Unpredictable (d) None of the above Answer: (a) Here if the parent is executing first then it starts to sleep for 2 seconds, then the child executes in that period. So it gives the order ‘child parent’. 34. What is the output of the code? (L2) void main() { int ret=fork(); if (ret==0) { sleep(2); printf(“child ”); } else if (ret>0) printf(“ parent”); } (a) Child parent (b) Parent child (c) Unpredictable (d) None of the above Answer: (b) The same as the above gives ‘parent child’. Here, child sleeps first. 35. How is child technically known in this case? (L3) void main() { int ret=fork(); if (ret==0) printf(“child ”); else if (ret>0) { sleep(2); printf(“ parent”); }} (a) Zombie (b) Orphan (c) Nothing specific (d) None of the above Answer: (a) Every child will report its status before exiting to its parent after completing execution. In this case, when the child is exiting the parent will be sleeping. So it cannot receive the status. Thus, here the child is called ‘Zombie’. (parent not listening to child). The process can be confirmed to be Zombe by executing the command ‘ps –al’ where the status corresponding to the PID will be ‘Z’.
Process Synchronization 105
36. How is child technically known in this case? (L3) void main() { int ret=fork(); if (ret==0) { sleep(2); printf(“child ”); } else if (ret>0) printf(“ parent”); } (a) Zombie (b) Orphan (c) Nothing specific (d) None of the above Answer: (b) Here the parent exits first while the child is sleeping. So the child has no parents, and becomes ‘Orphan’. 37. What is the output of the code? (L3) void main() { int fp[2]; char s[5]; pipe(fp); int ret=fork(); if (ret==0) { read(fp[0],s,4); printf(“%s”,s); } else if (ret>0) { write(fp[1], “hai”,4);}} (a) hai (b) Prints nothing (c) Unpredictable (d) None of the above Answer: (a) ‘pipe’ is an inter-process communication (IPC) mechanism for related processes. It is used for passing messages between related processes like parent and child. Also the order of execution may be unpredictable, but the ‘read’ from the pipe FD will wait for the ‘write’ into another pipe FD. Hence, the communication is synchronised. 38. What is the output of the code? (L3) void main() { int fp[2]; char s[5]; pipe(fp); int ret=fork(); if (ret==0)
106 Cracking the Operating Systems Skills
{ read(fp[0],s,4); printf(“%s”,s); } else if (ret>0) { sleep(2); write(fp[1], “hai”,4);}} (a) hai (b) Garbage (c) Prints nothing (d) None of the above Answer: (a) Here the parent first sleeps, so the child starts. But the first instruction of the child itself is a ‘read’ of a pipe. As the pipe has not completed the ‘write’ the instruction waits infinitely for the ‘write’ operation to complete. So after 2 seconds the parent resumes execution and then the child executes. So the synchronisation of ‘pipe’ works even while ‘sleep’ is used. 39. What is the output of the code? (L3) void main() { int fp[2]; char s[5]; pipe(fp); int ret=fork(); if (ret==0) { read(fp[1],s,4); printf(“%s”,s); } else if (ret>0) { write(fp[0], “hai”,4);}} (a) hai (b) Garbage (c) Prints nothing (d) None of the above Answer: (b) Actually pipe fd[1] is referred as write end and pipe fd[0] is referred as read end. The operations must be associated to the corresponding ends only. Else such confusions will occur. 40. What is the output of the code? (L3) void main() { int fp[2]; char s[5]; pipe(fp); int ret=fork(); if (ret==0) { write(fp[1], “hai”,4);} else if (ret>0) { read(fp[0],s,4); printf(“%s”,s); }}
Process Synchronization 107
(a) hai (b) Prints nothing (c) Unpredictable (d) None of the above Answer: (a) The read and write can be interchanged between the processes, only the pipe FDs cannot be interchanged. 41. What is the output of the code? (L2) void main() { int fp[2]; char s[5]; pipe(fp); int ret=fork(); if (ret==0) { write(fp[0], “hai”,4);} else if (ret>0) { read(fp[0],s,4); printf(“%s”,s); }} (a) hai (b) Garbage (c) Prints nothing (d) None of the above Answer: (d) Compiler traps. Here both the parent and child cannot work as both child and parent are associated with same FD. So the communication is not completed. As it is a synchronous communication, it traps the terminal until it is completed. Thus, the compiler traps. 42. What is the output of the code? (L3) void main() { int fp[2]; char s[5]= “\0”; pipe(fp); int ret=fork(); if (ret==0) { write(fp[0], “hai”,4);} else if (ret>0) { printf(“%s”,s); }} (a) Null (b) Garbage (c) Prints nothing (d) None of the above Answer: (c) Here the read is not given only the write operation is given. So no synchronisation issue. As the read is not specified, the communication is aborted after the end of the program.
108 Cracking the Operating Systems Skills
43. What is the output of the code? (L3) void main() { int fp[2]; char s[5]= “\0”; pipe(fp); int ret=fork(); if (ret==0); else if (ret>0) { read(pf[0],s,4); printf(“%s”,s); }} (a) Null (b) Garbage (c) Prints nothing (d) None of the above Answer: (d) The terminal traps. Here it has a ‘read’ function. So a ‘read’ function waits infinitely for a ‘write’ into the pipe. 44. What is the output of the code? (L2) void main() { int fp[5]; char s[5]= “\0”; pipe(fp); int ret=fork(); if (ret==0) { write(fp[3], “hai”,4);} else if (ret>0) { read(pf[2],s,4); printf(“%s”,s); }} (a) hai (b) Compiler traps (c) Prints nothing (d) None of the above Answer: (a) When the array of pipe FD is larger, it automatically pairs them and assigns the odd FD to write and even FD to read. 45. What is the output of the code? (L3) void main() { int fp[5]; char s[5]= “\0”; char c[5]= “\0”; pipe(fp); int ret=fork(); if (ret==0)
Process Synchronization 109
{ read(pf[0],c,4); printf(“ %s”,c); write(fp[3], “bye”,4);} else if (ret>0) { write(fp[1], “hai”,4); read(pf[2],s,4); printf(“ %s”,s); }} (a) hai bye (b) bye hai (c) Error (d) Unpredictable Answer: (d) It may be ‘(a)’ or ‘(b)’. The order is based on internal timestamp allocation and execution of instruction. 46. What is the output of the code? (L2) void main() { int fp[5]; char s[5]= “\0”; pipe(fp); int ret=fork(); if (ret==0) { read(pf[4],c,4); printf(“ %s”,c); } else if (ret>0) { write(fp[0], “hai”,4); }} (a) hai (b) Compiler traps (c) Error (d) None of the above Answer: (d) It prints nothing. As usual as the FD allocated to the write function is wrong so prints nothing. 47. What is the output of the code? (L2) void main() { int fp[5]; char s[5]= “\0”; pipe(fp); int ret=fork(); if (ret==0) { read(pf[4],c,4); printf(“ %s”,c); } else if (ret>0) { write(fp[5], “hai”,4); }}
110 Cracking the Operating Systems Skills
(a) hai (b) Compiler traps (c) Error (d) None of the above Answer: (a) This works as if the array is created with size 6 and initialised. ‘pipe’ system call automatically allocates the final write to the next memory location. 48. What is the output of the code? (L3) void main() { int fp; char s[5]= “\0”; pipe(fp); int ret=fork(); if (ret==0) { read(pf[0],c,4); printf(“ %s”,c); } else if (ret>0) { write(fp[1], “hai”,4); }} (a) hai (b) Compiler traps (c) Error (d) None of the above Answer: (c) It gives a usual ‘C’ error “subscripted value is neither array nor pointer”. This is not initiated to the next location because, the compiler cannot access the next memory location of a normal variable, and relative accessing is possible only in the arrays and pointer. 49. What is the output of the code? (L2) void main() { int *fp; char s[5]= “\0”; char c[5]= “\0”; pipe(fp); int ret=fork(); if (ret==0) { read(pf[0],c,4); printf(“ %s”,c); write(fp[3], “bye”,4);} else if (ret>0) { write(fp[1], “hai”,4); read(pf[2],s,4); printf(“ %s”,s); }}
Process Synchronization 111
(a) hai bye or bye hai (b) Error (c) Unpredictable (d) None of the above Answer: (d) Prints nothing. As here the pointer is not allocated with memory, it doesn’t get initiated to the pipe FD. 50. What is the output of the code? (L1) void main() { int fp[2]; char c[5]= “\0”; pipe(fp); int ret=fork(); if (ret==0) { read(fp[0],c,4); printf(“ %s”,c);} else if (ret>0) { write(fp[1], “hai”); }} (a) hai (b) Error (c) Unpredictable (d) None of the above Answer: (b) Prints nothing. Here, the argument for length is skipped in the write call, and the function fails eventually. On the other hand, read function waits endlessly as the write has failed. 51. What is the output of the code? (L2) void main() { int fp[2]; char c[5]= “\0”; pipe(fp); int ret=fork(); if (ret==0) { write(fp[1], “hai”,4); read(pf[0],c,4); printf(“ %s”,c);} else if (ret>0);} (a) hai (b) Error (c) Unpredictable (d) None of the above Answer: a) It works as any IPC between different processes. 52. What is the output of the code? (L2) void main() { int ret=mkfifo(“/tmp/f”,0666); int fp= open(“/tmp/f”,O_WRONLY);
112 Cracking the Operating Systems Skills
write(fp, “hai”,4); close(fp);} (a) Creates the file “f” in “/tmp” and writes “hai” into it. (b) Creates the file “f” in “/tmp” and writes “hai” into it in encrypted form. (c) Unpredictable (d) None of the above Answer: (a) ‘mkfifo’ is the system call for named pipe. This method is used for synchronous message passing between unrelated files. Here, a common file is created in ‘/tmp’ folder of the file system where the message will be stored. It is also to be noted that the terminal will be locked until another file opens and reads the message as the process is synchronous. 53. What is the output of the code when it is executed after the above code in a new terminal? (L2) void main() { char c[4]; int fp= open(“/tmp/f”,O_RDONLY); read(fp, c,4); printf(“%s”,c); close(fp);} (a) hai (b) Error (c) Unpredictable (d) None of the above Answer: (a) This is the corresponding ‘read’ operation of named pipes. These two code snippets are simple examples of using named pipe for communication. 54. What is the output of the code when it is executed without the ‘write’ code? (assuming this is the first process launched after the system is boot) (L2) void main() { char c[4]= “\0”; int fp= open(“/tmp/f”,O_RDONLY); printf(“%d”,fp); close(fp);} (a) –1 (b) 3 (c) Prints nothing (d) None of the above Answer: (a) This shows that the file doesn’t exist. Even if the whole process has been executed previously, it has the same output. Actually, the file in “/tmp” will not be accessible once the communication is completed. 55. What is the output of the code when it is executed without the ‘write’ code? (L2) void main() { char c[4]= “\0”; int fp= open(“/tmp/f”,O_RDONLY);
Process Synchronization 113
read(fp, c,4); printf(“%s”,c); close(fp);} (a) hai (b) Error (c) Prints nothing (d) None of the above Answer: (c) When the write operation is not done, the file doesn’t exist. So the default value of the character array gets printed. As it is null, it prints nothing. 56. What is the output of the code when it is executed after the ‘write’ code in the same corresponding location that writes ‘hai’? (L2) void main() { char c[4]= “\0”; int fp= open(“/home/user/Desktop/f”,O_RDONLY); read(fp, c,4); printf(“%s”,c); close(fp);} (a) hai (b) Error (c) Prints nothing (d) None of the above Answer: (a) Even this works. The file exists even after the communication is over. But cannot be opened normally, as every file will be associated with the process that creates it and is accessible only by the same. 57. ________ synchronization is defined as a mechanism which ensures that two or more concurrent processes or threads do not simultaneously execute some particular program segment known as critical section. (L2) (a) Thread (b) Process (c) Both a and b (d) Neither a nor b Answer: a) Thread 58. ________ occurs when many processes are waiting for a shared resource which is being held by some other process. (L2) (a) Starvation (b) Deadlock (c) Priority inversion (d) CPU crash Answer: (b) Deadlock 59. ________ occurs when a process is waiting to enter the critical section but other processes keep on executing the critical section and the first process just keeps on waiting. (L1) (a) Deadlock (b) System crash (c) Starvation (d) Busy waiting Answer: (c) Starvation
114 Cracking the Operating Systems Skills
60. ________ occurs when a high priority process is in the critical section, it may be interrupted by a medium priority process. This is the violation of rules but this may happen and may lead to some serious consequences when dealing with realtime problems. (L2) (a) Starvation (b) Priority inversion (c) Busy waiting (d) Deadlock Answer: (b) Priority inversion 61. What is the output of the code? (L3) void main() { int retval,shmid; void *memory = NULL; char *p; shmid = shmget ((key_t)123456789, 6, IPC_CREAT|0666 ); printf (“\n %d”, shmid); memory =shmat (shmid, NULL, 0); p=(char *) memory; memcpy (p, “hello”, 6); retval = shmdt (p); } (a) Prints the Shmid allocated for the process (b) Error (c) 196003 (d) None of the above Answer: (a) This mechanism is called shared memory. Here, a memory in shared region is created. A process first attached to the memory does the read / write operation and then detaches. Only one process can be attached to the memory at once, but the communication can be between many processes. ‘shmget’ system call gets the ‘shmid’, the unique shared memory ID which is based on the key value. ‘shmat’ is attach and ‘shmdt’ is detach. This is the shared memory ‘write’ operation. 62. What is the output of the code when it is executed after the above code? (L3) void main() { int retval,shmid; void *memory = NULL; char *p; shmid = shmget ((key_t)12345, 6, IPC_CREAT | 0666); printf (“\n %d”, shmid); memory =shmat (shmid, NULL, 0); p=(char *) memory; printf (“ %s \n”,p);
Process Synchronization 115
retval = shmdt (p); retval = shmctl (shmid, IPC_RMID, NULL); } (a) Prints the Shmid allocated for the process followed by “hello” (b) Error (c) 196003 “hello” (d) None of the above Answer: (a) This is the corresponding ‘read’ operation. This also gets the same ‘shmid’ as the keys are same. Also this IPC mechanism is asynchronous, mainly because it can share the memory with any number of processes provided they all know the key. 63. What is the output of the code when it is executed after the corresponding ‘write’ code that has written ‘hai’ in the memory? (L3) void main() { int retval,shmid; void *memory = NULL; char *p; shmid = shmget ((key_t)12345, 6); printf (“\n %d”, shmid); memory =shmat (shmid, NULL, 0); p=(char *) memory; printf (“%s \n”,p); retval = shmdt (p); retval = shmctl (shmid, IPC_RMID, NULL); } (a) Prints the Shmid allocated for the process followed by “hai” (b) Error (c) 196003 “hai” (d) None of the above Answer: (b) It throws “too few arguments to function ‘shmget’ ”. 64. What is the output of the code when it is executed after the corresponding ‘write’ code that has written ‘hai’ in the memory? (L3) void main() { int retval,shmid; void *memory = NULL; char *p; shmid = shmget ((key_t)12345, 6,0); printf (“\n %d”, shmid); memory =shmat (shmid, NULL, 0); p=(char *) memory;
116 Cracking the Operating Systems Skills
printf (“%s \n”,p); retval = shmdt (p); retval = shmctl (shmid, IPC_RMID, NULL); } (a) Prints the Shmid allocated for the process followed by “hai” (b) Error (c) 196003 “hai” (d) None of the above Answer: (a) This works normally. Actually, the flag was ‘IPC_CREATE|0666’ for creating the shared memory of it is not already created. When it is sure that it has been already created in ‘write’ part it can be skipped. ‘shmctl’ is the control call, the falg ‘IPC_RMID’ means to free the memory after the message is being read by the particular process. 65. What is the output of the code when it is executed without the corresponding ‘write’ code? (L3) void main() { int retval,shmid; void *memory = NULL; char *p; shmid = shmget ((key_t)12345, 6,0); printf (“\n %d”, shmid); memory =shmat (shmid, NULL, 0); p=(char *) memory; printf (“%s \n”,p); retval = shmdt (p); retval = shmctl (shmid, IPC_RMID, NULL); } (a) –1 (b) Error (c) –1 segmentation fault (d) None of the above Answer: (c) Here the memory and the shmid for the specified doesn’t exist, so ‘shmid’ gets –1. As the memory is itself not present, and trying to connect and read from the same results in segmentation fault. 66. What is the output of the code when its corresponding write operation gets ‘shmid’ 1956 and write ‘hai’ into the memory? (L3) void main() { int retval,shmid; void *memory = NULL; char *p; shmid = 1956; memory =shmat (shmid, NULL, 0);
Process Synchronization 117
p=(char *) memory; printf (“%s \n”,p); retval = shmdt (p); retval = shmctl (shmid, IPC_RMID, NULL); } (a) hai (b) Error (c) Segmentation fault (d) None of the above Answer: (a) This works as if it is got normally. But the code is only one time usable. 67. What is the output of the code? (L3) void main() { int retval,shmid; void *memory = NULL; int *p; shmid = shmget ((key_t)123456789, 6, IPC_CREAT|0666 ); printf (“\n %d”, shmid); memory =shmat (shmid, NULL, 0); p=(int *) memory; memcpy (p,9 , 1); retval = shmdt (p); } (a) Prints the Shmid allocated for the process (b) Error (c) Segmentation fault (d) None of the above Answer: (c) Integer constants cannot be set into memory addresses. 68. What is the output of the code? (L3) void main() { int retval,shmid,r=9; void *memory = NULL; int *p; shmid = shmget ((key_t)123456789, 6, IPC_CREAT|0666 ); printf (“\n %d”, shmid); memory =shmat (shmid, NULL, 0); p=(int *) memory; p=&r; retval = shmdt (p); } (a) Prints the Shmid allocated for the process (b) Error
118 Cracking the Operating Systems Skills
(c) Segmentation fault (d) None of the above Answer: (a) As any normal memory this also can have memory address. 69. What is the output of the code when it is executed after the above code? (L3) void main() { int retval,shmid; void *memory = NULL; int *p; shmid = 1956; memory =shmat (shmid, NULL, 0); p=(int *) memory; printf (“%d \n”,*p); retval = shmdt (p); retval = shmctl (shmid, IPC_RMID, NULL); } (a) 9 (b) Error (c) Segmentation fault (d) None of the above Answer: (c) Actually in the above program, ‘r’ is a program scope variable. So will be freed after the program has completed. The shared memory will now have the address of the variable which is already freed. On trying to read an integer from a freed memory spot results in segmentation fault. 70. What is the output of the code? (L2) void main() { int retval,shmid; void *memory = NULL; char *p; shmid = shmget ((key_t)123456789, 6, IPC_CREAT|0666 ); printf (“\n %d”, shmid); memory =shmat (shmid, NULL, 0); p=(char *) memory; memcpy (p, “hello”, 6); retval = shmdt (p); retval=shmctl(shmid, IPC_RMID, NULL); } (a) Prints the Shmid allocated for the process (b) Error (c) 196003 (d) None of the above Answer: (a) This is a normal write operation. But the final ‘shmctl’ with the flag ‘IPC_RMID’ frees the allocated memory.
Process Synchronization 119
71. What is the output of the code when it is executed after the above code? (L3) void main() { int retval,shmid; void *memory = NULL; char *p; shmid = shmget ((key_t)12345, 6, IPC_CREAT | 0666); memory =shmat (shmid, NULL, 0); p=(char *) memory; printf (“ %s \n”,p); retval = shmdt (p); retval = shmctl (shmid, IPC_RMID, NULL); } (a) hello (b) Error (c) Prints nothing (d) None of the above Answer: (c) As said above the previous code frees the allocated memory once it detaches. So in this program it is created again and initialised to NULL. Thus, prints nothing. 72. What is the output of the code when it is executed after the same read code of the previous question? (L3) void main() { int retval,shmid; void *memory = NULL; char *p; shmid = shmget ((key_t)12345, 6, 0); memory =shmat (shmid, NULL, 0); p=(char *) memory; printf (“ %s \n”,p); retval = shmdt (p); retval = shmctl (shmid, IPC_RMID, NULL); } (a) Prints nothing (b) Error (c) Segmentation fault (d) None of the above Answer: (c) Here the ‘IPC_CREAT’ flag is removed. So the ‘shmid’ is not created again. Thus, it gets –1 as the ID is not existing. Then the read happens in unallocated address dumping the core. 73. What is the output of the code? (L2) struct msgbuf { long mtype; char msgtxt[5]; };
120 Cracking the Operating Systems Skills
void main() { struct msgbuf msg; int msgid; msgid=msgget((key_t)12345,0644|IPC_CREAT); printf (“\n %d”,msgid); msg.mtype=1; strcpy(msg.msgtxt,”hai”); msgsnd(msgid,&msg,sizeof(msg),0); } (a) Prints nothing (b) Error (c) Prints the msgid allocated for the communiction/message (d) None of the above Answer: (c) This is Message Queue mechanism. The ‘msgbuf’ is a predefined structure that should be declared here with only the required members alone. The msg_type is like a key. Only processes that know the key value can open the message. 74. What is the output of the code when it is executed after the above code? (L3) struct msgbuf { long mtype; char msgtxt[5]; }; void main() { struct msgbuf msg; int msgid; msgid=msgget((key_t)12345,0644); msgrcv(msgid,&msg,sizeof(msg),1,0); printf(“%s\n”,msg.msgtxt); msgctl(msgid,IPC_RMID,NULL); } (a) “hai” (b) Error (c) Prints the msgid allocated for the communication/message (d) None of the above Answer: (c) This is the corresponding receive part of the message. This is also an asynchronous communication. The third argument on ‘msgrcv’ is the key to m_type that is used to validate the message. 75. What is the output of the code when it is executed after the corresponding write function that write ‘4’ into msgtxt[0]? (L2) struct msgbuf { long mtype; int msgtxt[5]; };
Process Synchronization 121
void main() { struct msgbuf msg; int msgid; msgid=msgget((key_t)12345,0644); msgrcv(msgid,&msg,sizeof(msg),1,0); printf(“%d\n”,msg.msgtxt[0]); msgctl(msgid,IPC_RMID,NULL); } (a) 4 (b) Error (c) Segmentation fault (d) None of the above Answer: (a) In message queue even integers can be passed. 76. What is the output of the code when it is executed after the corresponding write function that writes ‘4’ into msgtxt which is a simple integer variable? (L2) struct msgbuf { long mtype; int msgtxt[5]; }; void main() { struct msgbuf msg; int msgid; msgid=msgget((key_t)12345,0644); msgrcv(msgid,&msg,sizeof(msg),1,0); printf(“%d\n”,msg.msgtxt[0]); msgctl(msgid,IPC_RMID,NULL); } (a) 4 (b) 0 (c) Segmentation fault (d) None of the above Answer: (a) The value of the integer will be passed automatically to the base address of the receiver message. So this works normally. 77. What is the output of the code when it is executed after the corresponding write function that writes ‘4’ into msgtxt which is a simple integer variable? (L2) struct msgbuf { long mtype; int msgtxt[5]; }; void main() { struct msgbuf msg; int msgid; msgid=msgget((key_t)12345,0644); msgrcv(msgid,&msg,sizeof(msg),1,0); printf(“%d\n”,msg.msgtxt[3]); msgctl(msgid,IPC_RMID,NULL); }
122 Cracking the Operating Systems Skills
(a) 4 (b) 0 (c) Segmentation fault (d) None of the above Answer: (b) When the first index gets the passed value, the other indexes will have the default 0. 78. What is the output of the code? (L2) struct msgbuf { int msgtxt; }; void main() { struct msgbuf msg; int msgid; msgid=msgget((key_t)12345,0644|IPC_CREAT); printf (“\n %d”,msgid); msg.msgtxt=4; msgsnd(msgid,&msg,sizeof(msg),0); } (a) Prints nothing (b) Error (c) Prints the msgid allocated for the communication/message (d) None of the above Answer: (c) This also works. Here the msg_type is removed as an attempt to send unsecured or open message. 79. What is the output of the code when it is executed after the above code? (L2) struct msgbuf { int msgtxt; }; void main() { struct msgbuf msg; int msgid; msgid=msgget((key_t)12345,0644); msgrcv(msgid,&msg,sizeof(msg),0); printf(“%d\n”,msg.msgtxt); } (a) 4 (b) Error (c) Segmentation fault (d) None of the above Answer: (b) It gives a compilation error. “too few arguments to function ‘msgrcv’ ”. It doesn’t match with the internal definition of the function. 80. What is the output of the code when it is executed after the corresponding write code in question 78? (L3) struct msgbuf { int msgtxt; };
Process Synchronization 123
void main() { struct msgbuf msg; int msgid; msgid=msgget((key_t)12345,0644); msgrcv(msgid,&msg,sizeof(msg),0,0); printf(“%d\n”,msg.msgtxt); } (a) 4 (b) error (c) Segmentation fault (d) none of the above Answer: (a) As there is no msg_type it opens for 0. 81. What is the output of the code when it is executed after the code in question 78? (L3) struct msgbuf { int msgtxt; }; void main() { struct msgbuf msg; int msgid; msgid=msgget((key_t)12345,0644); msgrcv(msgid,&msg,sizeof(msg),5,0); printf(“%d\n”,msg.msgtxt); } (a) 4 (b) Error (c) Segmentation fault (d) None of the above Answer: (d) The message with type 5 is not existing. So it waits till the message is created. Else the program must be manually aborted to stop. So the intention of sending an open message is not satisfied and the mechanism doesn’t support it. 82. What is the output of the code? (L2) sem_t s; void fun() { sem_wait(&s); printf(“hai”); sem_post(&s); } void main() { sem_init(&s,0,1); int i=0; for(i=0;i