当前位置:网站首页>Operating System Random
Operating System Random
2022-08-04 05:33:00 【学习溢出】
Operating System
Operating system is the set of programs that controls a computer.
It provides a pleasant and effective interface between the user and the hardware.
Makes the computer more convenient to use.
User Interface (UI): This component allows interaction with the user, which may occur through graphical icons and a desktop or through a command line.
Application Programming Interfaces (API): This component allows application developers to write modular code.
Application developers often do not have direct access to the system calls, but can access them through an application programming interface (API).
Command Interpreter
A command interpreter is the part of a computer operating system that understands and executes commands that are entered interactively by a human being or from a program. In some operating systems, the command interpreter is called the shell.
The command interpreter isusually separate from the kernel because its purpose differs from that of the kernel.
The kernel’s job is to allowmultiple programs, multipleusers in multi-user systems toaccess the hardware as if eachprogram had its own computer
User Mode and Kernel Mode of CPU
Kernel Mode
- When CPU is in kernel mode, the code being executed can access any memory address and any hardware resource.
- Hence kernel mode is a very privileged and powerful mode.
- If a program crashes in kernel mode, the entire system will be halted (停止).
User Mode
- When CPU is in user mode, the programs don’t have direct access to memory and hardware resources.
- In user mode, if any program crashes, only that particular program is halted.
- That means the system will be in a safe state even if a program in user mode crashes.
- Hence, most programs in an OS run in user mode.
System Call
Definition: When a program in user mode requires access to RAM or a hardware resource, it must ask the kernel to provide access to that resource. This is done via something called a system call.
When a program makes a system call, the mode is switched from user mode to kernel mode. This is called a context switch.
5 types of System Call
- Process control: end, abort, create, terminate, allocate and free memory.
- File management: create, open, close, delete, read file etc.
- Device management
- Information maintenance
- Communication
- fork() : create new process
- exec() : replace to a new process in memory space
- exit() : process executees last statement and delete from system
- wait() : return child to parent
- abort() : parent could terminate the execution of children process
Process States
- New: The process is being created
- Running: Instructions are being executed
- Waiting: The process is waiting for some event to occur
- Ready: The process is waiting to be assigned to a processor
- Terminated: The process has finished execution
Process Control Block (PCB)
Process Control Block is a data structure that contains information of the process related to it.
The process control block is kept in a memory area that is protected from the normal user access.
Some of the operating systems place the PCB at the beginning of the kernel stack for the process as it is a safe location.
User-level threads & Kernel-level threads
USER LEVEL THREAD | KERNEL LEVEL THREAD |
---|---|
User thread are implemented by users | kernel threads are implemented by OS |
OS doesn’t recognized user level threads | Kernel threads are recognized by OS |
Context switch time is less | Context switch time is more |
Context switch requires no hardware support | Hardware support is needed |
If one user level thread perform blocking operation then entire process will be blocked. | If one kernel thread perform blocking operation then another thread can continue execution. |
How semaphore can be used to solve the Critical Section Problem
- The critical aspect of semaphores is that they are executed atomically.
Atomic Instruction: Accomplish certain operations atomically — as a single, uninterruptible unit of work
- Atomically is how you implement mutual exclusion.
- It guarantees that no two processes can execute wait and signal operations on the same semaphore at the same time.
Trap & Interrupt
The main difference between trap and interrupt is that trap is triggered by a user program to invoke OS functionality while interrupt is triggered by a hardware device to allow the processor to execute the corresponding interrupt handler routine.
Preemptive Scheduling and Non-Preemptive Scheduling
- Switches from running to waiting state (Non-preemptive)
- Switches from running to ready state (Preemptive)
- Switches from waiting to ready (Preemptive)
- Terminates (Non-preemptive)
Preemptive: If a process having high priority frequently arrives in the ready queue, low priority process may starve.
Non-Preemptive: If a process with long burst time is running CPU, then later coming process with less CPU burst time may starve.
Scheduling queues of processes
- Job queue –set of all processes in the system
- Ready queue –set of all processes residing in main memory, read and waiting to execute
- Device queues –set of processes waiting for an I/O device
Interprocess Communication
Two types of IPC: Shared Memory, Message Passing
Shared libraries via mapping into virtual address space.
Shared memory by mapping pages read-write into virtual address space.
Paging (Page Fault)
A page fault is a type of exception raised by computer hardware when a running program accesses a memory page that is not currently mapped by the memory management unit (MMU) into the virtual address space of a process.
Logically, the page may be accessible to the process, but requires a mapping to be added to the process page tables, and may additionally require the actual page contents to be loaded from a backing store such as a disk.
Software that handles page faults is generally a part of the operating system kernel.
6 Steps if Page fault occurs:
- reference
- trap
- page is on blocking store
- bring in missing page to physical memory
- reset page table
- restart instruction
Algorithm
Frame-allocation Algorithm: how many frames to give each process
Page-replacement Algorithm: want lowest page-fault rate on both first access and re-access
Scheduling:
- CPU utilization –keep the CPU as busy as possible
- Throughput– of processes that complete their execution per time unit
- Turnaround time –amount of time to execute a particular process
- Waiting time –amount of time a process has been waiting in the ready queue
- Response time –amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)
Banker’s Algorithm:
- Available: The number of available resource of each type
- Max: The maximum demand of each process
- Allocation: The number of resouce of each type currently allocated to each process
- Need: The remaining resource need of each process
Demand Paging:
- Page fault (above)
边栏推荐
猜你喜欢
随机推荐
基于Webrtc和Janus的多人视频会议系统开发7 - publish和subscribe声音设备冲突导致对方听不到声音
安装Apache服务时出现的几个问题, AH00369,AH00526,AH00072....
Miscellaneous [development] [VS Code] remote - SSD retry failed
LeetCode_Nov_4th_Week
键盘扫描码
[daily office][ssh]cheatsheet
JUC并发容器——阻塞队列
Jackson 使用样例
ZYNQ之FPGA LED 灯闪烁实验
2020-03-27
网络通信与Socket编程概述
C语言结构体(必须掌握版)
C语言对文件的操作(完整版)
MySQL之SQL结构化查询语言
C语言无符号整型运算
Tensorflow/Pytorch安装(Anaconda环境下,无版本冲突,亲测有效)
指针运算相关面试题详解【C语言】
Vmmem 进程(WSL2)消耗内存巨大
桌面右键的NVIDIA去除与恢复
枚举和联合(自定义类型)-C语言