OS_term
L7 Interprocess Communication
Interprocess communication refers to the exchange or sharing of information between separate independent schedulable tasks. There are several reasons why you might want to do this. Data Parallelization for Computational Speedup Modular, Pipelined or Layered Division of Tasks Use or reuse of a service on the network.
L10:Multi-threaded Processes
Modern operating systems support the model of a single process environment supporting multiple threads of control executing independently at different points within that environment.
L7 Unix Boot Sequence - Creating the first process
https://www.youtube.com/watch?v=DOkPZojTOhI pierre-jean.baraud.fr/blog/2014/06/04/linux-boot-process/pierre-jean.baraud.fr/blog/2014/06/04/linux-boot-process/
tradition thread
A traditional process has a single thread of execution. That is, the process executes instructions retrieved from only one specific point in the program at a time and executes them in a sequential manner. Flow control instructions like loops, selection statements and procedure calls or external events cause the process to jump to other parts of the code when required, but a single threaded process can only do one thing at a time.
Q4: Hard Disk Drive Performance Metrics
Capacity - Highly reliable high capacity cheap solution Data Rate - The bandwidth between a drive and the system, connected by a particular interface e.g. SATA 1.5Gb/s, SATA-2 3Gb/s, SATA-3 6Gb/s, SATA express 16Gb/s Average Latency - Time to access a sector e.g. 4ms-9ms Reliability - Mean Time to Failure
Q2: Multiprocessor System Organisation1
A multiprocessor system can be composed of a heterogeneous or homogenous collection of processors. With homogeneous processors, a single queue of tasks may be serviced by all processors. A homogeneous system can use asymmetric or symmetric multiprocessing . Serpentine queues are commonly used in banks, ticket counters where the tellers perform symmetric multiprocesssing. Multiple queues are used at supermarket checkouts due to physical constraints on queue space and travel time.
Q2 Multitasking
A multitasking (or multiprogramming) operating system allows multiple processes belong to a user to be resident and active on the computer system at one time. On a multiuser multitasking system, some of these processes may belong to different users.
L10:Kernel Space Threads
Implementing threads in kernel space offers greater flexibility and efficiency. A thread issuing a system call does not necessarily block all other threads in that process. Threads can be scheduled onto separate CPUs on a multiprocessor system offering true application concurrency. Threads compete on an equal basis for CPU cycles and they may be preempted by hardware timers easily.
L7:Unix Process Creation
Every process has a unique ID Created using the fork() system call Terminology - Initial process is the Parent and new process is the Child Child process is an exact copy of the parent and inherits values in the parent's user descriptor table. Typically, the exec() system call is used by child after a fork() The exec() system call loads a binary file into the process's memory (destroying the existing program image) and starts execution.
Q4 Hard Disk Drives : side of one platter
One side of one platter contains space reserved for hardware track-positioning information and is not available to the operating system. A disk assembly containing two platters has three sides available for data. Track-positioning data is written to the disk during assembly at the factory. The system disk controller reads this data to place the drive heads in the correct sector position.
L8: pipe
Processes that are related by creation hierarchy and run on the same machine can use a fast kernel based stream communication mechanism known as a pipe. Pipes are FIFO byte stream communication channels implemented with finite size byte stream buffers maintained by the kernel. A process writes data to one end of the pipe, and usually another process reads it from the other end. A pipe exists for the lifetime of the processes that have access to it. A pipe can only be used between related processes and is generally used as a unidirectional communication channel from parent to child or vice versa. The parent would create the pipe
Execution State
The execution position within the process code is represented by a small specific set of information. The current state of the CPU program counter. Various CPU registers may be used for caching other data. A runtime stack stores parameters and linkage for method calls and other temporary data.
Q1: OS must perform the 7 tasks
(i) Allocation and Management of Resources among competing user processes. (ii) Maximising Resource Utilisation with the goal of improving overall system throughput. (iii) Providing a user interface and an application interface to the machine. (iv) Coordinating the many concurrent activities and devices, handling input and output from attached hardware and ensuring correct synchronisation and communication is achieved. (v) Acting as a Resource Guardian to protect various resources of the computer system from malicious or accidental misuse. (vi) Accounting for periods of resource usage by user processes, enforcing quotas or restrictions as appropriate. (vii) Power and Thermal Management.
The mutual exclusion solution for two threads is given below:-
/* Shared variables */ boolean[] flag = {false, false}; int turn; /* Thread code for access to critical section */ /* This thread is thread i, other thread is j */ flag[i] = true; /* This thread wants to enter */ turn = j; /* Let other thread go first if it wants */ while (flag[j] && (turn == j)) { /* Do nothing */ } Critical Section flag [i] = false; Remainder Section In this example the flag is used to indicate whether a thread wishes to use the critical section and turn is used to guarantee mutual exclusion as it can only have one value. Each thread initially sets its flag and allows the other thread to go first if it has also set its flag. A thread can proceed to the critical section if it is its turn, or if the other thread has not set its flag requesting entry.
Hardware Instructions get-and-set
// lock is shared by all threads. Boolean lock = false; Each thread then tries to set lock to true before entering the critical section. The getand-set operation returns the current value of lock and also sets it to true in an indivisible operation. If the value returned is true, then the lock was already set and the thread has to wait until the value returned by get-and-set is false. // Entry code to critical section while ( get-and-set(lock, true) ) { /* loop until the getand-set function returns false, i.e. we got the lock */} critical section get-and-set(lock, false); remainder section Another type of indivisible read/write instruction found on some processors is the xchg or swap instruction which allows the contents of two memory locations to be exchanged indivisibly. If the processor supports the swap hardware instruction then we can implement n-process mutual exclusion as follows:- // lock is shared by all threads Boolean lock = false; // Each thread has its own copy of key Boolean key = true; // Entry code to critical section do { swap(lock,key); } while (key == true); critical section swap(lock,key); remainder section Note: All of these software solutions involve Busy Waiting. When a thread is scheduled, it could spend its time repeatedly re-evaluating a condition which can never change until another thread is scheduled and changes that condition. The solution doesn't guarantee Bounded Waiting either. Note also that the Software Solutions developed earlier (like the baker's algorithm) are somewhat unwieldy for programmers to have to carry around to solve every synchronisation problem. It is easy to omit parts of the entry or exit code which is specifically required for access to each critical section. The solutions are not general enough and not easy to use for the application developer and as we pointed out, they may not work in multiprocessor environments with separate thread caches. Next we look at more general constructs called Semaphores.
L7: Design Issues for Interprocess Communication
1. Naming How is the link between two processes established? The sender may identify (as a parameter to the Send primitive) a process ID or a mailbox or port ID to which a message is to be sent. Indirect vs direct communication. Single channel or multichannel. 2.Synchronisation The message passing operations Send and Receive may be either blocking or non-blocking. Blocking Send: Sending process is blocked until the message passing mechanism has delivered the message to the receiving process or to a mailbox. Non-Blocking Send: The sending process sends a message and can continue other tasks immediately while the message passing mechanism delivers the message. Blocking Receive: Receiver waits until a message is received by it. Non-Blocking Receive: Receiver either gets an available message or a null value returned by the Receive primitive. The implementation of some of these semantics requires the management of a message buffer/queue. 3.Buffering What is the capacity of a Link Buffering is a requirement for implementing non blocking semantics. A link can have zero, limited or unlimited* capacity. Buffering adds complexity and the need for message sequencing. 4. Message Parameters What size should a message packet be? Packets can be of fixed or variable size, typed or untyped messages. Fixed sized messages easier to buffer and manage bandwidth. Typed message useful in strongly typed language environments. 5.Reliability & Security The mechanism must deal with the problems of networked communication such as lost and scrambled messages, and also with security issues. The system should be reliable, fast and easy to use for programmers. Eg. Encryption with SSL or IPSec
L8 create pipe
1.Creating a pipe from a C program The syntax of the pipe system call is as follows: pipe(fdptr); fdptr is a pointer to an array of two integers i.e. declared in C as int fdptr[2]; After the system call to pipe, this array will contain two file descriptors which identify both ends of the new pipe. fdptr[0] is the read descriptor for the pipe and fdptr[1] is the write descriptor. Details of process I/O devices are stored in the process descriptor table. After this pipe is created the values stored in the fdptr array would be, from the picture:- fdptr[0] = 3 (read descriptor) fdptr[1] = 4 (write descriptor) 2.Reading and Writing to Pipes Data structures needed int fdptr[2], n; char strbuff[5]; pipe(fdptr); The write system call is used to put data into the pipe. write(fdptr[1], "Welcome to Unix pipes", 21); To receive information, a process uses the read system call to get data out of the pipe. n = read(fdptr[0], strbuff, 5); If the pipe is empty, the read function blocks the calling process until data can be read from the pipe. If the pipe is not empty but the process attempts to read more data than is in the pipe, the read succeeds returning all data in the pipe and the count of bytes actually read.
L9:Message Queue
1.Message Queue creation strcpy(qname, "/test_queue"); /* the flag O_CREAT is for creating a message queue if it doesn't exist on opening */ modeflags = O_RDWR | O_CREAT; /* Read/Write perm for owner only */ permissions = 0600; attr.mq_flags = 0; /* Blocking allowed mode*/ attr.mq_maxmsg = 10; attr.mq_msgsize = 512; If the message queue doesn't exist, additional parameters are supplied to mq_open mqd_t mq; mq = mq_open(qname, modeflags, permissions, &attr); If the message queue already exists it can be opened with mq = mq_open(qname, modeflags); 2.Sending a message to an opened message queue mq char buffer[max_size]; int priority = 0; memset(buffer,0, max_size); strcpy(buffer,"Hello There"); mq_send(mq, buffer, max_size, priority); 3.Reading a message from an opened message queue int numRead; char buffer[max_size]; int priority; numRead = mq_receive(mq, buffer, max_size, &priority); numRead is the number of bytes in the received message. 4. To close access to the message queue mq_close(mq) To request destruction of the message queue mq_unlink(qname); If the requesting process has permission to do this, then the queue is not destroyed until all open descriptors in other processes that are using the queue have been closed.
L8:Named Pipes
1.Named Pipes A variation of this mechanism known as a named pipe, can be used for communication between unrelated processes that have access to the same file name space. A named pipe is implemented as a special FIFO file by the kernel, rather than as a memory buffer, and so is accessible to independent processes through the file system's shared name space. Named pipes can be shared across machines with a common file system. 2. Creating and Using Named Pipes To create a named pipe file called "mypipe" in the current directory, use:- mknod("mypipe", 010777, 0); The file type is a fifo special file indicated by the code 010 The access permissions to the pipe allow read, write and execute permission for the owner, group and world with a value 777 Processes open named pipes in the same way as regular files, so unrelated processes can communicate by opening the pipe and either reading or writing it. A process can open a pipe in read or write mode. namedpipe = open("mypipe",O_WRONLY); namedpipe = open("mypipe",O_RDONLY); O_WRONLY and O_RDONLY are constants found in the header file "fcntl.h" #include <fcntl.h> Semantics A process opening the pipe for reading will block if there is no process that has it open for writing. Similarly, a process opening the pipe for writing will block if there is no process that has it open for reading. The format of the read and write operations is as follows:- n = read(namedpipe, buffer, nbytes); write(namedpipe, buffer, nbytes);
Q2: Distributed system
A Distributed System is composed of a collection of physically distributed computer systems connected by a local area network. From a scheduling perspective, a distributed operating system would endeavour to monitor and share or balance the load on each processing node. Scheduling in distributed systems is even more complex because the system information is generally not accessible in one single place but is managed on separate nodes in the network. Algorithms must gather information needed for decision making and transmit control information using message exchanges across the network. Message communication can be subject to delays, corruption and loss all leading to greater complexity within distributed algorithms.
L9: How RPC works...
A client process calls the desired procedure and supplies arguments to it. The client RPC stub mechanism packs the arguments into a message and sends it to the appropriate server process. The receiving stub decodes it, identifies the procedure, extracts the arguments and calls the procedure locally. The results are then packed into a message and sent back in a reply which is passed back by the stub to the client as a procedure return.
Q2: Preemptive Scheduling: Round Robin
A common type of algorithm used as the basis for scheduling in multitasking systems is known as Round Robin. Round Robin is chosen because it offers good response time to all processes, which is important for achieving satisfactory interactivity performance in multitasking systems. Round Robin is a preemptive version of FCFS. Each process executes in turn until its quantum expires forcing a task context switch. The quantum can be varied, to give best results for a particular workload. Note that the round robin algorithm incurs a greater number of task switches than non preemptive algorithms. Each task switch takes a certain amount of time for the CPU to change the process environment. Too many task switches (i.e. quantum too small) means a greater proportion of CPU time is spent doing task switches instead of useful work. If the quantum is too large than RR degenerates to FCFS with poor response times. When choosing the quantum for round robin scheduling, it is difficult to suit all jobs. If there is a wide deviation in average CPU burst times then the multilevel queue approach, with feedback may be adopted.
Q4 Hard Disk Drives : Sector
A sector is the smallest amount of data that can be addressed, read from or written to the disk in a single I/O operation. We can view the disk as an array of sectors in the range 0 to n − 1 , essentially the address space of the drive. Some operating systems may group adjacent sectors into clusters. A cluster is the minimum amount of space on a disk that a file can occupy. Reserving a cluster allows the file some growth while maintaining efficiency of unfragmented access. Each platter surface has a read/write head which can move linearly across it. The actuator moves the head to the correct track on a given platter and then waits for the correct block to pass underneath it for access. The contents of each sector area include id information, sector status codes, synchronization bit patterns to guide the read head, 512 bytes of data, error correction codes and sector gaps.
L9:How to find the server's port address...
Although RPC stub mechanisms understand the rules of how to communicate with a service interface, they may not know where the particular service exists on the network. The service could start up on any machine using any communication port. The server's socket is located by first communicating with a directory service with which the server has registered and then establishing a connection over which RPC style exchanges can take place.
Q1: Operating System Distributions
An Operating System Distribution will have additional components to the Kernel such as a File System, a Database Engine, Network Communication Suite, Graphics and Media functions, a Web Server, a User Interface GUI, Security and Authentication elements, Device Drivers for various external I/O devices, and Utilities for configuring the system. The packages chosen for a particular distribution might be tailored for different target environments like desktop machines, servers or mobile devices, home or business use.
Q1: What Is An Operating System?
An operating system (OS): (1) is a large and complex software system which manages all of the hardware resources of a computer and makes it easy to use. (2)Boots machine into a useable state. (3)Provides a layer of abstraction for portable application development. (4)Provides common services for application software to use processing resources, memory space, disk storage, input/output devices and network communication functions of the underlying hardware. (5)It is a concurrent environment where numerous tasks and events must be handled at the same time and the coordination of these tasks must provide for the most efficient and best use of available resources.
Q1: Applications interact with the OS
Applications interact with the OS through Application Programming Interfaces (APIs) and System Calls, which define a set of commonly required functions (and associated parameters) that the operating system components can perform. Applications are therefore written for specific operating systems. The operating system is a programming platform. The availability of the operating system APIs lessen the development effort required to get an application running on the hardware.
Q1: Cloud Computing
Cloud Computing refers to a form of distributed computing where your data and/or applications are hosted remotely at data centres belonging to different companies on the Internet rather than residing within your own computer. You "rent" the software, storage or computational resources of these systems and access them using Web based browsers as the user interface. Cloud computing is seen as a highly reliable, highly available, cost effective high performance means of being able to access your data and applications from anywhere in the world. Microsoft Azure, Amazon Web Services and Google Cloud Platform are examples of Cloud Application Environments.
L10:Concurrency on any operating system
Concurrency on any operating system A thread mechanism can be implemented within the kernel or within an ordinary user space process or both - where user threads are mapped onto kernel threads. Concurrency in any language Multithreaded code can be written in any programming language for which there is a thread library or API that can be linked with the program.
L12:Algorithmic Solutions to the Mutual Exclusion Problem
Conditions necessary for a correct solution to the Mutual Exclusion Problem (a) Mutual Exclusion No two threads can be able to execute simultaneously in the critical code section. (i.e. the section which manipulates the nonshareable resource.) (b) Progress A thread operating outside the critical section cannot prevent another thread form entering the critical section. (c) Bounded Waiting Once a thread has indicated its desire to enter a critical section, it is guaranteed that it may do so in a finite time. The problem is that we want to ensure mutually exclusive access to a critical section of code in a fair way to a number of threads sharing that code. The solution is to design a set of instructions to be executed by any thread entering or leaving that critical section.
Q2 Context Switch
Context Switch code must be efficient Usually supported by hardware instructions Incurs Performance Overhead
Q2 Case study: The Traditional Unix Scheduler
Designed to support a time sharing multitasking interactive environment on a single processor machine. Not originally designed for real time process requirements(scheduling tasks within time constraints) or for symmetric multiprocessing. Modern Unix implementations since about 2003 has been revamped to cater for these requirements. Provides good response time for interactive user tasks while ensuring low priority background tasks don't starve and also that high priority system tasks can be done quickly. Multilevel feedback approach Priority queues which are serviced using round robin. Priority is a value between 0 and 127. Priorities 0 to 49 were for Kernel processes, and priorities from 50 to 127 for user processes. The priority of all processes system wide was calculated at one second intervals from their execution history and a base priority level used to place processes in bands of priority levels. Pj(i) = Basej + CPUj(i)/2 + nicej User processes are preempted after 1 second if still using the CPU and the highest priority task is chosen next. Recent CPU usage reduced a process's scheduling priority by increasing its priority value. To ensure processes are eventually rescheduled, the recorded CPU utilization of a process is decayed during each priority recalculation interval using the following formula:- CPUj(i) = CPUj(i-1)/2
Q4: Physical Characteristics of Hard Disk Drives
Engineering Trends Smaller platter diameters are the trend in newer drives as they offer better rigidity, weigh less and require less power to spin, meaning less noise and heat and improved seek performance. Smaller platters mean a smaller recording surface, but the bit density technology has increased more than sufficiently to compensate.
Q2: non-preemptive algorithms. FCFS (First Come First Served)
FCFS is an inherently fair algorithm but performs badly for interactive systems where the response time is important and in situations where the job length differs greatly.
Q2: Multiprocessor System Organisation2
If the average arrival rate of tasks to a system is λ and μ is the service rate then it can be proven (from Little's Law) that the mean residence or turnaround time (time spent in the box) Τ, is related to λ and μ by the formula:- T = 1/(μ -λ)
Q2: Queuing Process & Service System
If the service system is busy, the arriving tasks are placed in a queueing system waiting for service. The queueing system may have a particular configuration and /or constraints such as being composed of a single queue or multiple queues with finite resources, or serviced according to a particular discipline, Tasks are submitted from the queue to the service system when resources are available based on queue service policy.
Q2: Queuing Theory: Modelling the Arrival and Queuing Process
In a computer system, let's say the arrival pattern of tasks may be random, with single independent tasks arriving one at a time. Many tasks might arrive close together at some times, few at other times and maybe sometimes periods where none at all arrive but assume the arrival of tasks is completely random. For modelling purposes we let λ represent the average rate of tasks arriving into such a system during an observation period. One way to estimate the arrival distribution might be to monitor the system and note the time between task arrivals and then using statistical techniques, fit a probability formula to the data so that we can estimate the number of arrivals in any given period. A Poisson Distribution, for example, can be used with the arrival process we described to our computer system in order to find the probability of a specific number of tasks arriving within a given time period. We assume tasks will remain in the system until completed. In real world queuing systems, the arrival and queuing pattern might be more dynamic, Balk at joining long queue Join for a while and leave due to excessive waiting Jockey between one queue and another Here we ignore those effects on system performance and presume all our tasks arrive randomly, are patient and well behaved.
Q2 Priority Scheduling
In a priority scheduling system, processes are assigned a numeric value which indicates their scheduling priority. Processes with the highest priority are always chosen first by the scheduler. It is an easy scheme to implement but requires a means of allocating priorities fairly so that lower priority tasks do not starve.
Q2: How to deal with multiple users? Dealing with multiple users - Fair-Share Scheduling
In multiuser multitasking systems each user may be running a collection of their own tasks. It is possible that one user or application may be running significantly less processes than another. Our scheduling algorithms so far focus only on achieving fair allocation among the total set of processes, not on achieving fair allocation of CPU time among different users or different applications. Fair-Share Scheduling: The scheme would require some alterations to the process priority calculation to assign a percentage of processor time to each group of processes. For example if there were 4 separate groups with different share weightings per group. Pj(i) = Basej + CPUj(i)/2 + GCPUk(i) / 4xWk (where Wk is a weighting of CPU time assigned to group k such that 0 <= Wk <=1) And we could decay GCPU in the same way GCPUj(i) = GCPUj(i-1)/2
Q2: Process Scheduling Algorithms
In this section, we are going to focus on servicing the queue associated with processes waiting to be assigned to processor(s), also known as the "Ready" queue. These processes are ready for their instructions to be executed in contrast to others that may be waiting for I/O operations. Later we look at approaches to scheduling requests for reading hard disks. Some evaluation criteria are necessary to allow us to compare different queuing policies and their effects on system performance. Processor Utilisation = (Execution Time) / ( Total Time) Throughput = Jobs per Unit time Turnaround Time = (Time job finishes) - (Time job was submitted) Waiting Time = Time doing nothing Response Time = (Time job is first scheduled on resource) - (Time job was submitted) The order in which processes are serviced from a queue can be described by a Gantt Chart. It represents a scheduling sequence. |P1 | P2| p3| Each process receives a number of units of time on a particular resource in the order described.
Q2: Queuing Theory-Arrival Process
In using real world services customers might arrive by - Appointment to a consultant - In groups to a restaurant - At a particular time of night to a taxi service - Randomly There may be a policy of customers being turned away if the service decides it is too busy or has no space to accomodate the queue and so on.
Q2: Queuing Theory
Increasing throughput effectively is a common aim of many real world services, not just computer systems and solutions require the application of queuing theory. In modeling and managing the performance of any system, we must address:- 1.The arrival pattern of tasks and their nature 2.How tasks are queued 3.Processing capacity of the service Every real world system might have its own unique arrival characteristics, physical queue configurations and service capacity and characteristic dynamics. Queuing theory, modelling and simulation has the purpose of assisting managers of those services in how best to organise the system.
message passing facility
Independent processes need a different means of communication as they cannot access each other's disjoint address space. Processes may not trust each other and may reside on different hosts. A message passing facility is any intermediary operating system mechanism which can take data from the address space of one process and place it in an area accessible to the other. In its simplest form, a message passing mechanism must implement two basic primitives, send and receive, or their equivalent, which processes explicitly invoke to exchange messages. Higher level abstractions, such as remote procedure call, are extensions of these basic primitives.
L7 inital start up process
Init is the initial start up process. Its primary role is to create processes from configuration information stored in the file /etc/inittab during boot up depending on the run level selected.
L7: Booting Linux
Master Boot Record (MBR) contains initial bootstrapping code called by the BIOS and partition information about the primary boot device and the active partition. It is always located in the first sector on the disk. In order to locate files from the filesystem of the active partition, additional bootstrapping code and device drivers may be stored here in these unused sectors. This gives enough code then to locate and load the main boot loader program which presents an interface asking the user to select the operating system to boot.
L9: Message Queue
Message queues allow processes to exchange data in the form of whole messages asynchronously. Messages have an associated priority and are queued in priority order. The operating system maintains the message queue independently until it is unlinked (destroyed) by a user process or the system is shutdown. It is not necessary to create a rendezvous style connection between the processes but they must both have access to the message queue and its API. The main functions in the message queue API are the following: mq_open() function creates a new message queue or opens an existing queue, returning a message queue descriptor for use in later calls. mq_send() function writes a message to a queue. mq_receive() function reads a message from a queue. mq_close() function closes a message queue that the process previously opened. mq_unlink() function removes a message queue name and marks the queue for deletion when all processes have closed it. Each message queue has an associated set of attributes, which are set when it is created. Attributes can be queried using:- mq_getattr() The message queue attribute structure fields are defined as:- struct mq_attr { long mq_flags; /*flags 0 or O_NONBLOCK*/ long mq_maxmsg; /*Max number of messages on queue*/ long mq_msgsize; /*Max message size (in bytes)*/ long mq_curmsgs; /*Num messages currently in queue*/ };
L11 The Mutual Exclusion Problem
Method 1 The drivers agreed on the following solution. They set up a large bowl at the entrance to the pass. Before entering the pass, a driver must stop his train, walk over to a bowl and reach into it to see if it contains a rock. If the bowl is empty, he finds a rock and drops it in the bowl, indicating that his train is entering the pass, then he drives the train into the pass. When the train has cleared the pass, he must walk back to the bowl and remove the rock. If a driver arriving at the pass finds a rock in the bowl, he leaves it there. He repeatedly takes a siesta and rechecks the bowl until he finds the bowl empty. Then he drops a rock in the bowl and enters the pass. Problems 1. It is claimed that subversive schedules made up by the Peruvian officials could block the Bolivian train forever. Explain. 2. Unfortunately, one day the two trains crashed. Explain. Method 2 Following the collision, a consultant was called in who concluded that the bowl was being used in the wrong way. The Bolivian driver must wait at entry to the pass until the bowl is empty, then drives through the pass and walks back and puts a rock in the bowl. The Peruvian driver must wait at the entry until the bowl contains a rock, then he drives through the pass and walks back to remove the rock from the bowl. Sure enough, there were no more crashes. Problem Prior to this the Peruvian Train ran twice a day and the Bolivian Train ran once a day. The Peruvians were very unhappy with the new arrangement. Why? Method 3 The consultant was called back to come up with a solution that solved the Peruvians problem as well as preventing crashes. He suggested using two bowls, one for each driver. When a driver wishes to enter, he first drops a rock in his own bowl as a signal that he wishes to use the pass. He then checks the other driver's bowl to see if it is empty. If it is, he drives his train through, walks back and removes the rock from his own bowl. If the other driver's bowl does contain a rock however, then he lets that driver go through the pass first by taking a siesta and retrying the other driver's bowl periodically until the other driver removes the rock after he clears the pass. Problem The solution worked for a long time, until one day both trains were simultaneously blocked at the entry. Method 4 (Solution) A single bowl is used, but initially it contains a rock. If either driver finds a rock in the bowl, he removes it and drives through the pass. He then walks back to put a rock in the bowl. If a driver finds no rock in the bowl when he wishes to enter the pass, he waits. Why does this solution work? How does it differ from Method 1?
Q2 Multiprocessing
Multiprocessing is the use of more than one CPU in a system, either separate physical CPUs or a single CPU with multiple execution cores. With asymmetric multiprocessing, one processor, the master, centrally executes operating system code and handles I/O operations and the assignment of workloads to the other processors which execute user processes. With this scheme, only one processor is accessing system data structures for resource control. While this makes it easier to code the operating system functions, in small systems with few processsor cores the master may not have enough slaves to keep it busy.
Solving Mutual Exclusion on Multiprocessor Systems
One of the assumptions of using software algorithmic solutions to the mutual exclusion problem, as described so far, is that when the data stuctures used for controlling access to a critical section are shared among the threads, all threads must immediately be able to see the effects on those data structures caused by other threads in order for the algorithm to work. This is usually fine in a single processor system because writes to the processor's cache can be seen immediately by another thread using the same cache. However, in a multiprocessor system, the shared data structures may be held in the cache of each processor, so that when one thread alters flags or variable values used in controlling mutual exclusion, those alterations might only affect its local copy for a short time and may not be visible for a while in the caches of the other processors. This means the algorithms can fail to preserve mutual exclusion in such systems. The same is true if you try to achieve mutual exclusion by disabling interrupts. On a single processor system, if you disable interrupts, the current thread cannot be interrupted and swapped, so it can perform a series of operations on data structures without the consequences of potential interleaved execution by another. This is not the case on multiprocessor systems where it is impossible to disable interrupts simultaneously for all processors. Another approach to solving the mutual exclusion problem, which is safer in multiprocessor systems, is to use special processor instructions which can read and write to memory indivisibly of the activities of other processors by asserting lock signals on areas of memory to ensure cache coherence.
L10:Multi-threaded Processes
Overhead Cost: Creating a process incurs processor time to allocate and initialise many structures and incurs ongoing cost in terms of memory resource usage. Organisation of a sequential process's memory space. The stack is an area of memory which is used closely with processor instructions for managing the call/return mechanism
L11:Thread Management in Unix - POSIX Interface
POSIX Standard was developed to provide a common abstraction or virtualization of operating system services by making system calls standard across all Unix system varieties, enhancing code portability. The POSIX pthread API is the component of the interface applicable to thread management. 1.pthread Thread Creation A new thread is created by the pthread_create() function. The function takes four parameters:- An identifier for the structure, of type pthread_t attributes the new thread will have such as stack size and scheduling attributes. where the new thread will begin execution in the program list of arguments to be passed to the function the thread will execute 2.Thread Termination A thread can terminate when it comes to the end of its function. The return value of the function is saved and returned to the caller of a pthread_join() function. The thread can also terminate if it calls pthread_exit() anywhere in its code. Thread remains in the system until it has been detached. 3. Detaching a Thread A thread can be detached either by another thread calling pthread_detach() or by another thread calling pthread_join() which allows a return value to be passed back. The pthread_join() function blocks the caller until the thread terminates.
L9:RPC
RPC is a communication mechanism built on top of an underlying connection oriented message passing facility, like sockets., which is intended to make socket based client server programming easier. The socket based messaging functions are hidden within communications stub programs which are linked with the client and server code. The communications stubs can be generated automatically from the interface that the server exposes.
L9: Remote Procedure Call
Recall the socket mechanism which uses an underlying transport protocol like TCP to create a connection between two end points on a network. The paired sockets form a bi-directional streamed communication channel between client and server. When a client communicates with a server, it usually wants to execute a function of some kind at the server. Using socket based communication is really flexible for creating your own protocols but it places the burden on the programmer for writing all the code required to invoke functions and exchange and parse parameters and results as a series of byte streamed message exchanges.
Q2: non-preemptive algorithms. SJF (Shortest Job First)
SJF is provably the optimal algorithm in terms of throughput, waiting time and response performance but is not fair. SJF favours short jobs over longer ones. The arrival of shorter jobs in the ready queue postpones the scheduling of the longer ones indefinitely even though they may be in the ready queue for quite some time. This is known as starvation. SJF Calculation with approximated CPU burst is more complex than FCFS You must maintain cumulative history information and perform the calculations required for predicting burst length each time you come to choose the next task.
Q2: preemptive or non-preemptive
Scheduling algorithms can be preemptive or non-preemptive. All multitasking systems would employ preemptive scheduling as otherwise, one process might never give up control of the CPU. We will compare some scheduling algorithms using deterministic modeling, i.e. we will define a workload pattern and compare the results across different algorithms.
L8: Network Sockets
Sockets are the more usual and general purpose means of communication between independent processes and can be used when neither kernel data structures or files can be shared, for example communicating across the Internet. A communication channel can be visualized as a pair of communication end-points. A socket is a data structure created by an application to represent a communication channel. The socket must be bound or associated to some entity (service access point/port) within the communication system. By using communication primitives of the socket interface, the process then exchanges this data from its address space to the address space of the communication subsystem which handles delivery. The communication service (e.g TCP/IP) provides the glue for establishing connections between sockets belonging to different processes, which are often on different machines and networks and for transporting and routing messages through the network to a destination. On the Internet, IP addresses and port numbers are used as a means of identifying the endpoints of a connection to which a program's socket might be connected. A communication subsystem which understands the same messaging protocols must be running on every point along the network over which the message travels. In an Internet context, this subsystem implements a communication protocol known as TCP/IP. Different levels of reliability for message delivery through the socket may be specified to the transport control protocol (TCP) when it is created. Faster delivery can be traded for less reliability. A socket may be 'connected' to any named remote socket by the underlying communication protocol. After connection, bytes which are sent to the local socket are delivered to the remote socket. The remote process 'listens' to its socket and receives the data sent into the byte stream.
Q2: Real Time Systems
Some computer systems are designed for specific industrial process control applications. For example, consider a production line where raw materials are supplied at one end of the line and finished goods come out the other. Along the production line, sensors, valves and other actuators are monitored and controlled by the computer system. Sensors bring data to the computer which must be analysed and subsequently results in modifications to valves and actuators. A real time system has well defined, fixed time constraints. Processing must be done within those constraints or the system may fail. Hard Real Time Systems are required to complete a critical task within a guaranteed amount of time Soft Real Time Systems are ones which endeavour to meet scheduling deadlines but where missing an occasional deadline may be tolerable. Critical processes are typically given higher priority than others and their priority does not degrade over time. The dispatch latency must be small to ensure that a real time process can start executing quickly. This requires that system calls be preemptible. It must be possible to preempt the operating system itself if a higher priority real time process want to run. Real Time Scheduling: Earliest Deadline First When an event is detected, the handling process is added to the ready queue. The list is kept sorted by deadline, which for a periodic event is the next time of occurrence of the event. The scheduler services processes from the front of the sorted queue. Least Laxity Algorithm If a process requires 200msec and must finish in 250msec, then its laxity is 50msec. The Least Laxity Algorithm chooses the process with the smallest amount of time to spare. This algorithm might work better in situations where events occurred aperiodically.
L9:Transparency Issues compared to ordinary procedure calling
Some implementation problems make it difficult to make the remote procedure call mechanism completely transparent. Arguments are passed by value, as in the remote address space, address references cannot be evaluated correctly. This makes it difficult to pass dynamic data structures for example. Another difficulty may result if the server is running on a different machine architecture to the client. It will be necessary for the RPC mechanism to find an agreeable external data representation format(XDR) for representing the information exchanged so that it is interpreted correctly by both parties.
Q1: Kernel
The Kernel refers to the core set of services associated with managing the CPU, managing the electrical memory managing low level hardware devices. The Kernel is common to various Operating System Distributions.
Q4:Zoned Bit Recording
The larger outer tracks contain a much greater area of recording material than the inner ones. The number of sectors stored on inner tracks is constrained by the bit density of the magnetic surface. Tracks are grouped based on their distance from the centre with the outer zones being used to store more sectors than the inner ones. his also means that if the rotational velocity is constant, that data can be transferred faster from the outer tracks than the inner tracks. As the drive is filled from the outside in, it gives its best performance when new and empty.
Q2 Process Scheduling
The number of processes in a multitasking system is generally much greater than the number of processors. Each process must compete with others for the available resources. CPU time is valuable and the operating system must decide which processes are assigned to use the processor(s) and for how long.
Q2 Scheduling Decision
The operating system may then decide to allocate the CPU to another process, in which case it will execute code to save the run-time state of the current process in its process control block so that it can be continued later, and then execute code to load the run-time state of another chosen process for the CPU to continue executing instead.
Q2: The Service System
The service time may be fixed or may follow a distribution pattern - e.g. Exponential Probability Distribution The service rate μ describes the number of tasks serviced during a particular time period, and the service time indicates the amount of time needed to service a task. One is the reciprocal of the other. So if a processor can service 5 tasks in 1 second the service rate is 5 tasks per second and the service time is 0.2 seconds (1/5) per task on average.
Q4 Scheduling Algorithms - Seek Time
The slowest part of accessing a disk block is physically moving the head to the correct track. This is called the seek time. In a multitasking system, requests to access different parts of the disk arrive from different processes or a file's blocks may be scattered across a platter. Correct scheduling of these requests can reduce the average seek time by reducing the average distance the head has to travel. Native Command Queuing (NCQ) is an extension of the Serial ATA protocol allowing hard disk drives to internally optimize the order in which received read and write commands are executed.
Q4 Hard Disk Drives :magnetic tracks
The surface of each platter is organised as a concentric group of magnetic tracks on which data can be stored. Each track is divided into a number of blocks of fixed size (usually 512 bytes) called sectors in which the data is stored.
2 ways of Interprocess Communication
There are two basic ways of implementing interprocess communication: By utilising a shared region of memory accessible to all the communicating parties By using explicit message passing primitives provided by a communication subsystem of the operating system.
L10: Advantages of Threads
These lightweight thread structures share the environment of the containing process and so are quick to create and can be managed as schedulable entities by the Kernel. Improved program performance on multicore architectures and improved responsiveness for GUI based applications. Less problems with network protocols due to server responsiveness
Q4. Solid State Drives
These storage drives have energy and performance benefits over hard drives but are more expensive and generally have smaller capacity. Windows may boot up in under 30 seconds & file opening speeds maybe 20-40x faster than a standard HDD.
A general software solution for N processes is given below:-
This algorithm is known as the bakery algorithm, and is a commonly used queue servicing approach. A thread chooses a ticket, from an ordered set of numbers, which determines its position in the queue for the critical section. /* Shared structures */ boolean[] choosing; /* An array of n elements initially false */ int[] number; /* An array of n elements initially 0 */ /* Thread code for access to critical section */ /* This thread is thread i */ /* Choose a ticket */ choosing[i] = true; number[i]=Max(number[0],number[1], ...,number[n-1])+1; choosing[i] = false; for (j = 0; j<n; j++) { /* Check the ticket of each other thread against this thread's ticket */ while choosing[j] { /* Wait while a thread is choosing, in case its ticket is smaller */ } while ((number[j] != 0) && ((number[j],j) < (number[i],i))) { /* Wait if a smaller ticket exists */ } } Critical Section /* Not seeking to enter critical section anymore */ number[i] = 0; Remainder Section NB: In the code above the comparison ((number[j], j) < (number[i],i)) is expressed this way for simplicity and is not valid code. It may be interpreted as follows: The purpose is to find out if thread j has a lower ticket number than thread i. This is true if number[j] < number[i]. However, it is possible that two threads may have chosen their tickets at the same time and may in fact have been assigned the same ticket numbers. In this case, to obtain a deterministic ordering for the threads, we use the thread identifier to sequence them. That is, if two threads j & i hold the same ticket then if j < i, j will go first.
L10: User Space Threads
This implementation does not require any operating system support for threads. Invoking a function in the library to create or destroy a thread or schedule a thread can be handled very fast as a local function call in user space, which manipulates local data structures for controlling user defined threads and what the program is doing at a given moment. A context switch to the kernel would block all threads in the process, as the kernel is unaware of the existence of separate thread abstractions manipulated within the application context. Also, scheduling of threads by the user space thread library would be non-preemptive. And the application can't benefit from multicore processing.
L10:Kernel Multithreaded Design
To achieve greater responsiveness, the kernel itself could be implemented as a multithreaded process. E.g. The scheduler, the IPC and I/O handling could all be separate threads. In this way the kernel does not block all processes requiring kernel services while a system call is in progress. This requires careful design of the kernel data structures and algorithms to allow for synchronisation of multithreaded activity. It is a necessary kernel design especially if the underlying hardware has a multiprocessor architecture.
L12 Two Thread Software Solutions
Two Thread Software Solutions Let's say we have two threads, 0 and 1 and the following code is executed by thread i say, where i and j can have the values 0 or 1:- i represents this thread, j represents the other thread. int turn; /* a shared variable which can store the value 0 or 1. */ while (turn != i) { /* While it's not my turn, do nothing */ } Critical Section turn = j; Remainder Section This will solve the mutual exclusion element of our problem as the variable turn can only have one value, either 1 or 0 and so either thread i or thread j can proceed. However the execution is lockstep. One thread cannot proceed if it is the other thread's turn even if that thread doesn't require the critical section. Another approach is given below in an attempt to avoid this problem:- /* Shared boolean array */ boolean[] flag = {false, false}; /* Thread i entry code to critical section */ flag[i] = true; /* set my flag, I want in */ while flag[j] { /* while the other thread's flag is set, do nothing */} Critical Section flag[i] = false; Remainder Section Here, thread i tests the flag of the other process and if the flag is set it waits until j is finished with the critical section. It then enters. J cannot enter again until flag[i] is set to false. Note that if both processes come along simultaneously and test each others flags, that both flags could be true, so both would be blocked forever.
Q2: Performance Issues with Multiprocessing
Using more processors seems an obvious way to increase overall system throughput but doubling processors does not usually double performance. The scheduling problem is more complex and again there is no single best solution optimising processor utilisation for all cases. Contention for the bus, I/O, shared memory, operating system code and maintaining cache coherency can cause some performance lag.
Shared Memory Communication
Usually, the address space accessible to independent processes is separate. Shared memory communication would require the processes to use the operating system to establish a shared region of memory between them. Usually communication requires processes to be on the same host, they are usually cooperative parts of the same application. Model is application oriented, suits cooperating processes willing to share memory. Implicit communication through read/write operations. Highly efficient, no communication protocols. Need synchronisation mechanisms.
Q2 Task Switching
When a process makes a system call or when its time quantum on the processor expires, the resulting software or hardware interrupt causes the CPU to stop fetching instructions from the currently assigned process and switch to designated code in the kernel for handling the interrupt.
Q2: Non Preemptive algorithms. Highest Response Ratio Next (HRN)
With FCFS, long jobs hold up short jobs. While SJF solves this, but continually arriving short jobs block long jobs. It may be better that, the longer a job is in the system waiting for the CPU, the greater chance it has of being scheduled. The (HRN) highest response ratio next algorithm endeavours to meet this objective. Type of priority based algorithm. The Response Ratio of a job is calculated as follows:- Response Ratio = (Waiting Time) / (Service Time) The Response Ratio determines the ordering of the jobs. As the job waits in the ready queue, its priority increases.