软件开发者要记住的十大操作系统概念,The 10 Operating System Concepts Software Developers Need to Remember。OS are file system, scheduler, and device driver. You probably haveused both Desktop(Windows, Mac, Linux)and Embedded (androidiOS)operating systems beforeThere are 3 key elements of an operating system, which are: (1)Abstractions (process, thread, file, socket, memory),(2)Mechanisms(create, schedule, open, write, allocate), and (3)Policies (LRU, EDFThere are 2 operating system design principles, which are: (1)Separation of mechanism and policy by implementing flexiblemechanisms to support policies, and(2)Optimize for commoncase: Where will the os be used? What will the user want to executeon that machine? What are the workload requirements?The 3 types of Operating Systems commonly used nowadays are: (1)Monolithic OS, where the entire OS is working in kernel space andis alone in supervisor mode; (2) Modular OS, in which some part ofthe system core will be located in independent files called modulesthat can be added to the system at run time; and(3) Micro OSwhere the kernel is broken down into separate processes known asservers. Some of the servers run in kernel space and some run inuser-space.1-Processes and Process managementa process is basically a program in execution. The execution of aprocess must progress in a sequential fashion. To put it in simpleterms, we write our computer programs in a text file and when weexecute this program, it becomes a process which performs all thetasks mentioned in the programWhen a program is loaded into the memory and it becomes a processit can be divided into four sections -stack, heap text and data. Thefollowing image shows a simplified layout of a process inside mainmemoryStackHeapDataTextStack: The process Stack contains the temporary data such asmethod /function parameters, return address and local variablesHeap: This is dynamically allocated memory to a process duringits run tmeText: This includes the current activity represented by the valueof Program Counter and the contents of the processors registersData: This section contains the global and static variablesWhen a process executes, it passes through different states. Thesestages may differ in different operating systems, and the names ofthese states are also not standardized In general, a process can haveone of the following five states at a timeReadyunnIngTerminatedStart: This is the initial state when a process is firststarted/ createdReady: The process is waiting to be assigned to a processorReady processes are waiting to have the processor allocated tothem by the operating system so that they can run Process maycome into this state after Start state or while running it by butinterrupted by the scheduler to assign cpu to some otherprocessRunning: Once the process has been assigned to a processor bythe os scheduler, the process state is set to running and theprocessor executes its instructionsWaiting: Process moves into the waiting state if it needs to waitfor a resource, such as waiting for user input, or waiting for a fileto become availableTerminated or Exit: Once the process finishes its execution,or it is terminated by the operating system, it is moved to theterminated state where it waits to be removed from mainmemoryA Process Control Block is a data structure maintained by theOperating System for every process. The PCB is identified by aninteger process ID(PID). A PCB keeps all the information needed tokeep track of a process as listed belowProcess IDStatePointerPriorityProgram counterCPU registers1/o informationAccounting informationetcProcess State: The current state of the process i.e., whether itIs ready, running, waiting, or whatever.Process Privileges: This is required to allow/disallow accessto system resourcesProcess ID: Unique identification for each of the process in theoperating system.Pointer: A pointer to parent processProgram Counter: Program Counter is a pointer to theaddress of the next instruction to be executed for this processCPU Registers: Various CPU registers where process need tobe stored for execution for running stateCPU Scheduling Information: Process priority and otherscheduling information which is required to schedule theprocessMemory Management Information: This includes theinformation of page table, memory limits, Segment tabledepending on memory used by the operating systemAccounting Information: This includes the amount of CPuused for process execution, time limits, execution ID etc.IO Status Information: This includes a list ofI/o devicesallocated to the process2-Threads and Concurrencya thread is a flow of execution through the process code, with its ownprogram counter that keeps track of which instruction to executenext, system registers which hold its current working variables, and astack which contains the execution history.a thread shares with its peer threads few information like codesegment, data segment and open files. When one thread alters a codesegment memory item, all other threads see thata thread is also called a lightweight process Threads provide away to improve application performance through parallelismThreads represent a software approach to improving performance ofoperating system by reducing the overhead thread is equivalent to aclassical processEach thread belongs to exactly one process and no thread can existoutside a process. each thread represents a separate flow of controlThreads have been successfully used in implementing networkservers and web server They also provide a suitable foundation forparallel execution of applications on shared memory multiprocessorscodedatafilescodedatafilesregistersstackregistersregistersregistersstackstackstackthreadthreadsingle-threaded processmultithreaded processAdvantages of ThreadThreads minimize the context switching timeUse of threads provides concurrency within a processEfficient communicationIt is more economical to create and context switch threadsbreads allow utilization of multiprocessor architectures to agreater scale and efficiencyThreads are implemented in the following 2 waysUser Level Threads: User managed threadsKernel Level Threads: Operating System managed threadsacting on kernel, an operating system coreUser Level ThreadsIn this case, the thread management kernel is not aware of theexistence of threads The thread library contains code for creatingand destroying threads, for passing message and data betweenthreads, for scheduling thread execution and for saving and restoringthread contexts. The application starts with a single threadUser m odeScheduler II SchedulerSchedulerProcess ayProcess Bac853SchedulerKernel modeAdvantagesThread switching does not require Kernel mode privilegesUser level thread can run on any operating systemScheduling can be application specific in the user level threadUser level threads are fast to create and manageDisadvantagesIn a typical operating system, most system calls are blocking.Multithreaded application cannot take advantagemultiprocessingKernel level threadsIn this case, thread management is done by the kernel There is nothread management code in the application area. Kernel threads aresupported directly by the operating system. Any application can beprogrammed to be multithreaded. All of the threads within anapplication are supported within a single processThe Kernel maintains context information for the process as a wholeand for individuals threads within the process. Scheduling by theKernel is done on a thread basis The Kernel performs threadcreation, scheduling and management in Kernel space. Kernelthreads are generally slower to create and manage than the userthreads。User modeProcessPrcSchedulerernel modeAdvantagesKernel can simultaneously schedule multiple threads from thesame process on multiple processes.If one thread in a process is blocked, the Kernel can scheduleanother thread of the same processKernel routines themselves can be multithreadedDisadvantagesKernel threads are generally slower to create and manage thanthe user threadsTransfer of control from one thread to another within the sameprocess requires a mode switch to the Kernel3-SchedulingThe process scheduling is the activity of the process manager thathandles the removal of the running process from the Cpu and theselection of another process on the basis of a particular strategy