The operating system is a piece of software whose job it is to take the base hardware of a device and turn it into a usuable machine for the user. It acts as the intermediary between hardware and user-usage, allowing the user to easily interact directly with the hardware; even when the user does not know they are accessing the hardware. Show
Examples of operating systems include:
Essential Managers of Operating SystemsThere are 5 main managers of operating systems:
The network manager is a new addition to the operating system, previously all operating systems did not have networking capabillities and many still do not. The Operating Systems manages the continious monitoring of resources and enforcement of policies across the system. Memory ManagerThe Memory Maneger is in charge of the main memory on the computer system. Its tasks involve:
Processor ManagerDecides how to allocate the Central Processing Unit (CPU) The tasks of a processor manager are:
Something to note is that a process is not the same as a program. Device ManagerMonitors every device and control unit The tasks of the device manager are:
File ManagerThe File manager keeps track of every file in the system. Its tasks are:
Network ManagerModern operating systems require a network manager. The network manager allows users to share resources while controlling user access to them. These resources can include hardware suhc as printers or disk drives or software such as files. Interaction between OS and ManagersEach Operating Systems has specific individual tasks to perform but it is not enough for each to operate on its own. Each manager must be able to work in harmony with the others at around the same time. ExampleA user types in a command at the keyboard to execute a program. The following simplified steps might occur: Device Manager: Receives keystrokes and builds up command line. Informs process manager that input has been received. Processor Manager: Activates process awaiting a command. Process checks validity of command and then tries to execute the corresponding program. File Manager: Checks to see if the program file is already in memory. If not, it finds ito n external storage and issues requests for it. Device Manager: Communicates with the disk drive and retrives the program file from disk. This goes on for quite a while, but you get the jist. Evolution of Operating SystemsIn early systems jobs were loaded from punch card,s tape or other physical means. The job may include loading the compiler, assembler etc. The CPU remained idle for much of the time due to waiting for user input. The jobs ran sequentially from start to finish. Batch systems were invented which passes a job to a human operator and then the operator would group jobs into batches with similar charecteristics which makes more efficient use of resources. Multi programmingMulti programming is where several programs are loaded into memory simultaenously, sharing the same CPU. When a running program cannot continue (maybe because it is waiting for input from the user) the operating systems switches to another program to run. As you can see in this image the CPU executes whilest other programs are waiting for input. Multi-Access (Time-sharing)This is an extension of multiprogramming. The CPU switches rapidly between processes to give an illusion of uninteruppted execution in parallel. Time-sharing the CPUEach program is allocated a fixed slice of time before the clock interrupts the program. InterruptsThe time sharing method depends on the abillity to interrupt execution at regular clock intervals. There are many circumstances in which it is desirable to interrupt the normal flow of a program to react to special events such as:
An interrupt is a form of automatical call of a sequence of instructions brought about usuaully by an event occuring outside the normal program execution. Such a sequence of instructions is known as an interrupt service routine (ISR). Unlike an ordinary subroutine call, an interrupt can take at any point in the execution sequence. The address of each ISR is usually contained in an interrupt vector. Certain interuppts (e.g. clock timeout) will not return control to the interupted program. Instead, control is handed to another program (context switch). If the programmer does not know when this will happen, how do we protect the register values of the original program? The answer is for the OS to save them in a special data structure called the process control block (PCB). The OS maintains a table of such descriptors, one for each process. Register values can be reloaded when execution resumes at a later time. ProcessesA program is a representation of an algorithm in some programming language. A process refers to the activity performed by a computer when executing a program. A process is created when a program or command is executed. However the correspondance is not always one to one. A single program may have several processes. OS StructureThe OS has:
System InitialisationWhen the system powers on, an interrupt causes the computer to execute a bootstrap program stored in ROM. This code initalises the system, runs diagnostic checks, sets up basic I/O. Basically making it ready to be used. It loads the OS Kernel from boot partition of specified external disk drive and passes control to it. The Kernel performs further initalisation and creates various system processes. Further processes may be created because of user activity. Command InterpreterOften called a shell. Accepts and runs commands specified by the user. May be graphical or textual. The shell is just a normal user-level process System callsUser processes are not allowed to inspect or alter kernal code, or to make calls directly to its subroutine. Services are requested via system calls. Many system calls are given a ‘wrapper’ to make them look like ordinary subroutines. Together with other useful functions, they form an Application Programmer Interface (API) ProcessesProcesses fall under the process manager (discussed earlier) The OS processor manager is responsible for every aspect of a process. A process control block contains:
Process states
Initially when we create a process it goes into the new state which is where we are initalising the process, where memory is being allocated etc. At some point the state will be in the ready state. The process will then go into the running state, if it reaches the end of its run (if it finishes) it enters into the terminated state. When a process is completed it doesn’t just stop, you have to take back memory allocated, close files, take back resources etc. If the process is waiting on an I/O event than it will go into the blocked state which waits for an I/O event. Otherwise it goes back to the ready state which eventually leads back to the running state. Process creationProcesses are created (spawned) by other processes. The original process is the parent and the new process is the child. We’ll use Unix as an example here. The exec() system call allows one program to execute another.
What happens is you stay in your current program and you overwrite your current program with a completely new program but stay in the same process. The fork() system call spawns a new process.
The fork call creates a new process that is identical to the parent. The wait() system call asks the current process to pause for a few seconds while another process runs. When you call fork() it returns a value back to the caller and what it returns is different depending on whether you are a child process or a parent address. If it returns a value less than 0, it’s an error. If it returns the value 0 it is the child process. If it is above 0 than it is the parent. At the startup level, the kernel creates process 0 (the first process). Kernel level process, so can access kernal code and data structures directly. Process 1 is ‘init’ (now called ‘systemd’ on Linux)
When user logs on, the login process checks name and password against stored details, than executes the shell. The Shell prompts for commands, then forks and execs to carry out those commands. At logout, shell process dies. Zombies and OrphansParent processes usually wait for their children to die. If the death of a child is not acknowledged by the parent, the child becomes a ‘zombie’. Zombie processes have no resources, but are still present in the process table. If parent dies before its children, the children become ‘orphans’. The orphans get adopted by Init process. DaemonsA daemon process is not associated with any user or terminal and runs in the background. It performs tasks requested of it by another set of processes. Some examples include:
Process InteractionProcesses that do not need oti nteract with any other processes are known as independant processes. In modern operating systems many processes work together. The operating system will need some way to syncrhonise these processes. Syncrhonisation vs CommunicationSynchronisation requires us to know when a process reaches a certain point in its operation. Unix SignalsA process can usually be terminated by pressing CRTL + C This sends a signal to the process. The process responds by aborting. Signalls can be sent from one process to another using the signal() call. Signals can be sent from the command line using the kill command: sometimes the kill signal isn’t always used to kill the process, it can allow you to send any signal to a given process. You need to specify which signal you want to send and to what process ID you want to send it to. Example kill signals: 1 - hang up2 - interrupt 3 - quit 6 - aboort 9 - kill 14 - alarm 15 - software termination signal The process can choose to ignore the signal, it does not have to terminate. However you cannot ignore the kill signal, it HAS to take effect. A process can “catch” a signal Kil all sends the signal to all processes with a given range of PID or with a name or a sub name. Pipes and SocketsA pipe is a command that allows it to pipe data into something. It attaches the standard output of one program to the standard input of another. SocketsA socket is a communication endpoint of a channel between two processes. Unlike pipes, the processes:
When two processes communicate using sockets, one is designated to the server and the other to the client. In some cases it does not matter which one is which. More usually a daemon server process offers a service to many clients. ThreadsThreads are a sort of mini-process in many modern systems. A thread represents ana ctivity that can be executed independentally (and in parallel) with other parts of the process. Each thread must has its own:
But unlike any process, threads share:
In many systems threads are handled at a higher level than processes and can be switched without involvement of the operating system kernel. If this is the case, thread switching is very rapid and efficient. Such threads are commonly known as user-level threads. Threads are super useful in event driven programming. A thread can be thought of as a light-weight process. Threads are created within a normal (heavyweight) process:
Thread benefits
IssuesThe abillity to run tasks brings many benefits. We we shall see, it also introduces a number of challenges for the programmer. Introduction to Concurrent ProgrammingIt is possible to run sections of code at the same time in a multiprocessing system. You need to identify what can be run concurrently, in parallel. Java ThreadsWhen a java program starts up, a single thread is always created for the program. The JVM also has its own threads for garbage collection, screen updates, event handling etc. You can make a thread in java with like so: Example: ProblemSo we gave an object called “thing” gthat has a method in it that just increments: public void inc() { count = count + 1; }Let’s assume that count is initially zero and we have two threads, T1 and T2 and they both call the increment method. Indeterminacy means we cannot determine the outcome. Mutual ExclusionIndeterminacy arises because of possible simultaenous access to a share resoruce. Solution is to only allow one thread to access a variable. When a thread / process accesses any shared resource, it is in a critical section. One way to enforce mutual exclusion is via semaphores. SemaphoresA semaphore is an integer-valued variable that is used as a flag to signal when a resource is free and can be accessed Only two operations possible, Wait and signal. Also called p and v, test and increment, down and up. Wait() signal ()Wait and signal are indisible. When one thread / process is executing the code in square brackets, no other may do the same. They can also be used to enforce mutual exclusion. There situations where you may want more than 2 threads to get access to a resource. Syncrhonisation problemsThere are a number of famous problems that charecterise the general issue of concuerrency control. One of them is called Producer-Consumer problemSyncrhonisation: The producer-consumer problem A producer process (eg secretary) and a consumer process commmunicates via a buffer. The secretary puts the letter in a letter tray and the manager picks up and processes that lecture. Both running in parallel
these two cycles happen in parallel May have many producers and many consumers Problems to solve We have to ensure that:
Questiont1 t2 wait(s) signal(s) critical reigion critical region signal(s) wait(s) If there was no wait signals at all it wouldnt’ crash, you would just get indeterminacy. AnswerLet’s suppose t1 gets there first, the semaphore is 1. wait(s) waits for semaphore to be raised, so it is and it enters the critical region so it stops the wait let’s suppose t2 gets there, what it should do is wait for a lowered flag but it’s not, it’s raising the flag so t1 and t2 simultaneously access the shared resource. Let’s suppose t2 gets there first, it’s raising an already raised flag and s would go to 2, it’s still a raised flag. It’ll enter its critical region. T1 gets to its wait operation, sees the flag is raised so it goes to its critical region. Again t1 and t2 are both inside critical regions. A producer will wait while the buffer is full, a consumer will wait while it is empty. This is called spinlock or busy-waiting. Dining Philosophers ProblemThe producer-consumer problem models a synchronization environment which processes with dinstinct roles have to coordinate with each other. General Settingn “philosphers” and all they do is eat-think-eat-think all day long. Philsophers need nothing in order to think, but in order to eat a philsopher needs 2 items of cutlery (2 chopsticks). Only n chopsticks, however, are provided. This means that if a philsopher is hungry BUT either neighbour is eating thne he / she must wait until both chopsticks are available. If there are 5 philsophers then there are 5 chopsticks. So they have to share, becasue you need 2 chopsticks to eat. Each philsopher has a unique index value {0, 1, 2, 3, 4}. The philospher with index K must be able to use both chopsticks k and (k+1) mod 5 chopsticks deadlock occurrs in a concurrenct system when each participant is waiting on others to do something. When EVERY process in that set is waiting for another member of the set to do something then you’ve got deadlock. Starvation means one or more of the participants in a concurrent system is denied access resources. DeadlockWhen two trains approach each other at a crossing,both shall come to a full stop and neither shall start up again until the other has gone. Deadlock happens when every process is waiting on a process to finish. Resource Allocation
quest: how many resources in r4? slide 7 comp124–18 r boxes are type of resource dots in boxes are number of that type of resource p circles are processes in general, a cycle indicates there may be deadlock. Ways to deal with deadlockMost operating systems ignore deadlock because it is costly to deal with. What is the intermediary between the computer programs and the hardware for the computer?What is an Operating system. A program that acts as an intermediary between a user of a computer and the computer hardware. A systems program which controls all the computer's resources and provides a base upon which application programs can be written.
Which software provides the interaction between hardware and software?System software is a set of one or more programs, which are designed to control the operation and processing capability of a computer system. It acts as intermediary between computer hardware and application program, it also provides interface between user and computer.
What is the connection between hardware and software?- Hardware and software are mutually dependent on each other. Both of them must work together to make a computer produce a useful output. - Software cannot be utilized without supporting hardware. - Hardware without set of programs to operate upon cannot be utilized and is useless.
What connects the application software to the hardware of a computer?Motherboard. It is the physical arrangement in a computer that contains the computer's basic circuitry and components. It has a socket for the CPU, RAM and expansion part (sound cards, graphic cards ETC) and also connects together the CPU, memory, hard drives, optical drives, video card and more.
|