# operationg system
## **lecture 2**
### **Operating-System Services**
operating system provides an environment for the execution of programs. It provides certain services to programs and to the users of those programs
These operating system services are provided for the convenience of the programmer, to make the programming task easier.
1. **User interface:** all operating systems have a user interface (UI). This interface can take several forms, like `command-line interface (CLI)` as shells and `batch interface`, `window system.`
> NOTE: Most commonly, the interface is a window system with a pointing device to direct I/O, choose from menus, and make selections and a keyboard to enter text.
2. **Program execution:** The system must be able to load a program into memory and to run that program, The program must be able to end its execution
3. **I/O operations:** such as recording to a `CD` or `DVD` drive or blanking a `display screen`
4. **File-system manipulation:** programs need to read and write files They also need to create and delete them by name, search for a given file, and list file information. some operating systems include permissions management to allow or deny access to files or directories based on file ownership.
5. **Communications:** There are many circumstances in which one process needs to exchange information with another process. Such communication may occur between processes that are executing on the same computer or between processes that are executing on different computer.
6. **Error detection:** The operating system needs to be detecting and correcting errors constantly. Errors may occur in the CPU and memory hardware, in I/O devices, and in the user program For each type of error, the operating system should take the appropriate action to ensure correct computing.
7. **Resource allocation:** When there are multiple users or multiple jobs running at the same time, resources must be allocated to each of them. The operating system manages many different types of resources.
8. ***Accounting:*** We want to keep track of which users use how much and what kinds of computer resources. This record keeping may be used for accounting.
9. **Protection and security:** `Protection` is any mechanism for controlling the access of processes or users to the resources defined by a computer system. `security` is to defend a system from external and internal attacks.
### **Types of System Calls**
1. **Process control:**
◦ end, abort
◦ load, execute
◦ create process, terminate process
◦ get process attributes, set process attributes
◦ wait for time
◦ wait event, signal event
◦ allocate and free memory
2. **File management:**
◦ create file, delete file
◦ open, close
◦ read, write, reposition
◦ get file attributes, set file attributes
3. **Device management:**
◦ request device, release device
◦ read, write, reposition
◦ get device attributes, set device attributes
◦ logically attach or detach devices
4. **Information maintenance:**
◦ get time or date, set time or date
◦ get system data, set system data
◦ get process, file, or device attributes
◦ set process, file, or device attributes
5. **Communications:**
◦ create, delete communication connection
◦ send, receive messages
◦ transfer status information
◦ attach or detach remote devices
### **System Programs**
1. **File management:** These programs create, delete, copy, rename, print, dump, list, and generally manipulate files and directories.
2. **Status information:** Some programs simply ask the system for the date, time, amount of available memory or disk space, number of users, or similar status information.
3. **File modification:** Several text editors may be available to create and modify the content of files stored on disk or other storage devices.
4. **Programming-language support:** Compilers, assemblers, debuggers, and interpreters for common programming languages (such as C, C++, Java).
5. **Program loading and execution:** Once a program is assembled or compiled, it must be loaded into memory to be executed.
6. **Communications:** These programs provide the mechanism for creating virtual connections among processes, users, and computer systems.
7. **Background services:** All general-purpose systems have methods for launching certain system-program processes at boot time. Some of these processes terminate after completing their tasks, while others continue to run until the system is halted.
## **lecture 3**
### **Process State**
• **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**
1. **Process state:** The state may be new, ready, running, waiting, halted, and so on.
2. **Program counter:** The counter indicates the address of the next instruction to be executed for this process.
3. **CPU registers:** The registers vary in number and type, depending on the computer architecture.
4. **CPU-scheduling information:** This information includes a process priority, pointers to scheduling queues, and any other scheduling parameters.
5. **Memory-management information:** This information may include such items as the value of the base and limit registers and the page tables.
6. **Accounting information:** This information includes the amount of CPU and real time used, time limits, account numbers, job or process numbers and so on.
7. **I/O status information:** This information includes the list of I/O devices allocated to the process, a list of open files, and so on.
**note:** The processes that are residing in main memory and are ready and waiting to execute are kept on a list called the ready queue. This queue is generally stored as a linked list. A ready-queue header contains pointers to the first and final PCBs in the list. Each PCB includes a pointer field that points to the next PCB in the ready queue.
### **Scheduling Queues**

• The process could issue an I/O request and then be placed in an I/O queue.
• The process could create a new child process and wait for the child’s termination.
• The process could be removed forcibly from the CPU, as a result of an interrupt, and be put back in the ready queue.
**-long-term scheduler** or **job scheduler** selects processes from secondary storage and loads them into memory for execution.
**-The short-term scheduler** or **CPU scheduler** selects from among the processes that are ready to execute and allocates the CPU to one of them.
## **lecture 6**
### **Dispatcher**
Another component involved in the CPU-scheduling function is the dispatcher. The dispatcher is the module that gives control of the CPU to the process selected by the short-term scheduler. This function involves the following:
**• Switching context
• Switching to user mode
• Jumping to the proper location in the user program to restart that program**
### **Scheduling Criteria**
1. **CPU utilization:** We want to keep the CPU as busy as possible. Concep- tually, CPU utilization can range from 0 to 100 percent. In a real system, it should range from 40 percent (for a lightly loaded system) to 90 percent (for a heavily loaded system).
2. **Throughput:** If the CPU is busy executing processes, then work is being done. One measure of work is the number of processes that are completed per time unit, called throughput.
3. **Turnaround time:** From the point of view of a particular process, the important criterion is how long it takes to execute that process. The interval from the time of submission of a process to the time of completion is the response time.
4. **Waiting time:** The CPU-scheduling algorithm does not affect the amount of time during which a process executes. It affects only the amount of time that a process spends waiting in the ready queue. Waiting time is the sum of the periods spent waiting in the ready queue.
5. **Response time:** the time from the submission of a request until the first response is produced. This measure, called response time, is the time it takes to start responding, not the time it takes to output the response.