Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more.
Course Hero has millions of course specific materials providing students with the best way to expand
their education.
Below is a small sample set of documents:
Purdue - CS - 354
Disk SchedulingWhich disk request should the OS service first?FCFS Shortest seek time first Elevator (SCAN) LOOK C-SCAN (Circular SCAN) C-LOOK1 1/31/12Looks familiar?FIFO (FCFS) orderMethodFirst come first serve053199ProsFairness among reques
Purdue - CS - 354
DL MallocThe memory allocator you are building is based on Doug Lea's malloc implementation that is public domain: This allocator is the standard allocator in Linuxhttp:/g.oswego.edu/dl/html/malloc.htmlMemory Allocation ErrorsExplicit Memory Allocatio
Purdue - CS - 354
Explicit Memory ManagementIn explicit memory management a program frees objects by calling free/delete explicitly The program uses a "malloc library" usually provided by the C standard library libc. Memory is requested from the OS and added to a free lis
Purdue - CS - 354
External FragmentationExternal Fragmentation is the waste of memory in the free list due to small noncontiguous blocks that cannot satisfy a large request. 40 64 160x110p = malloc(100);0x40000x8000100 bytes object + 8 bytes header = 108 bytes total
Purdue - CS - 354
Fence PostsIf the object freed is at the beginning of the heap, it is likely that your allocator will try erroneously to coalesce memory beyond the beginning of the heap. Also other libraries may call sbrk() causing a hole in the heap.Fence PostsTo pre
Purdue - CS - 354
File Operationsstruct file_operations cfw_ struct module *owner; loff_t(*llseek) (struct file *, loff_t, int); ssize_t(*read) (struct file *, char _user *, size_t, loff_t *); ssize_t(*aio_read) (struct kiocb *, char _user *, size_t, loff_t); *); ssize_t(
Purdue - CS - 354
Heap CheckYou can implement also a heapCheck function that checks for the sanity of the heap and prints the free and allocated blocks. You can call it during debugging before and after suspicious free/malloc calls. Starting from the header at the beginni
Purdue - CS - 354
How does VMs work?They use "Trap" and "Emulate" A processor can be virtualized if all instructions that access a privileged state cause a trap or interrupt.Trap = interruptThe VM will catch the trap and emulate what the OS in that VM tries to do.Memor
Purdue - CS - 354
Implementation of LRUTo implement LRU we would need to have a timestamp in each page to know when was the last time page was accessed. This timestamp is approximated using the accessed and modified bits.Clock Algorithm (Second Chance Algorithm)Initiall
Purdue - CS - 354
Implementation of PagingPaging adds an extra indirection to memory access. This indirection is implemented in hardware, so it does not have excessive execution overhead. The Memory Management Unit (MMU) translates Virtual Memory Addresses (vmaddr) to phy
Purdue - CS - 354
I-node informationAn i-node represents a file in disk. Each i-node contains: ModeRead, Write, Execute (for Owner/Group/All) RWX RWX RWX Userid, Groupid Creation time, Access Time, Modification Time. Size of file in bytes Reference count with the number
Purdue - CS - 354
Input /Output DevicesDevicesDevicesStorage devices (disk, tapes) Transmission devices (network card, modem) Human interface devices (screen, keyboard, mouse) Specialized device (joystick)1/31/122Device-Computer/Device-Device CommunicationPhysically
Purdue - CS - 354
InterruptsAn interrupt is an event that requires immediate attention. In hardware, a device sets the interrupt line to high. When an interrupt is received, the CPU will stop whatever it is doing and it will jump to to the 'interrupt handler' that handles
Purdue - CS - 354
Introduction to Operating SystemsWhat is an Operating SystemIt is a program that sits between the hardware and the application programs. The program starts running at boot time. It is compiled with a normal compiler.What does an Operating System Offer?
Purdue - CS - 354
Introduction to the Linux KernelKernel ModulesA Kernel Module is a piece of code that can be loaded and unloaded on demand. Kernel modules extend the functionality of the kernel without the need of recompilation Without a kernel module you would have a
Purdue - CS - 354
Kernel Loadable ModulesV-NodesV-Nodes or also called "Virtual Nodes" is the abstract data structure used to represent a device/files in the UNIX kernel A V-Node has the following methods:Open Close Read Write Ioctl (Any functionality that is not of the
Purdue - CS - 354
Linux Linked Liststruct list_head cfw_ struct list_head *next, *prev; ;#define LIST_HEAD_INIT(name) cfw_ &(name), &(name) #define LIST_HEAD(name) \ struct list_head name = LIST_HEAD_INIT(name)#define INIT_LIST_HEAD(ptr) do cfw_ \ (ptr)->next = (ptr);
Purdue - CS - 354
Loading a ProgramThe loader is a program that is used to run an executable file in a process. Before the program starts running, the loader allocates space for all the sections of the executable file (text, data, bss etc) It loads into memory the executa
Purdue - CS - 354
Making System Call Table Exportable and Readable Starting Linux 2.6, the sys_call_table is no longer exportable to KLMs. To be able to modify it you need to:5. In /usr/src/linux-3./arch/x86/kernel/entry_32.S make the sys_call_table writable so it can b
Purdue - CS - 354
Malloc ImplementationThere are several data structures that can be used for memory allocation:Single Free list Segregated Free Lists Cartesian Tree Boundary tagsMalloc Single Free ListIn this implementation of malloc all the free memory is stored in a
Purdue - CS - 354
Mark and Sweep Garbage CollectionThe Garbage Collector determines what objects are reachable from the "roots",Roots: memory that is not dynamic such as stack, global variables, registers etc. and then frees the unreachable objects. Every object has a
Purdue - CS - 354
Memory of a ProgramA program sees memory as an array of bytes that goes from address 0 to 232-1 (0 to 4GB-1) That is assuming a 32-bit architecture.(4GB-1) 23210Memory SectionsThe memory is organized into sections called "memory mappings".232-1Stac
Purdue - CS - 354
Memory SmashingMemory Smashing happens when less memory is allocated than the memory that will be used. This causes overwriting the header of the object that immediately follows, corrupting the free list. Subsequent calls to malloc/free may crash Sometim
Purdue - CS - 354
Modular KernelModern Operating Systems have a modular architecture The modern kernels only gives a small functionality such as scheduling and inter-process communication. Other functionality is added with modules loaded at boot time or later in the execu
Purdue - CS - 354
Multilevel Feedback-Queue SchedulingProblem: If you have processes of higher priority, low priority processes will never run. Solution: Use Process Aging: The longer a process stays in a queue, the priority is artificially increased. The process will be
Purdue - CS - 354
Multi-threaded Program Example #include <pthread.h>void prstr( char *s )cfw_ while( 1 )cfw_ int main()cfw_ / thread 2 pthread_create( NULL, NULL, prstr, "b\n" ); / thread 3 pthread_create(NULL, NULL, prstr, "c\n" ); / thread 1 prstr( "a\n" ); printf(
Purdue - CS - 354
Mutex Lock implementationTwo approaches:Disable Interrupts Do not allow context switches to happen. Available only in Kernel mode Other interrupts may be lost. Only used in kernel programming Slow if used in a machine with more than 1 processor Spin l
Purdue - CS - 354
Mutual ExclusionMutex Locks also enforce the mutual exclusion of two or more sections of code.Mutex_lock(&m) D E F Mutex_unlock(&m)Mutex_lock(&m) A B C Mutex_unlock(&m)Mutual ExclusionThis means that the sequence ABC, DEF, can be executed as an atomi
Purdue - CS - 354
Pointer to functions: A generic array mapper that works for pointers of any type. /a generic function type typedef void (*Funcptr)(void*); /This function will call FuncPtr for every element in the array void genericArrayMapper(void *a, int n, int elemsize
Purdue - CS - 354
Notes on Synchronized List ClassWe need the mutex lock to enforce atomicity in the critical sections a) b) and c) d). The semaphore is not enough to enforce atomicity.Notes on Synchronized List Class>N N 1int MTList:remove()cfw_ ListEntry *tmp; sema_w
Purdue - CS - 354
1/11/05 CS354 OS Gustavo Rodriguez Rivera grr@cs.purdue.edu Office hours by appointment arrange in class or by email http:/www.cs.purdue.edu/homes/cs354 Mailing list log in to CS machine type: mailer add me to CS354-PSO# where # is the number of your PSO
Purdue - CS - 354
1/25/2005 1/27/2005-1/25/2005 -Grid: A collection of inexpensive computers across the internet.- People donate idle time of their computers to be used in the grid. - Example: SETI@home (Search for extra-terrestrial intelligence) data + You can download
Purdue - CS - 354
InterruptsTuesday, February 1, 2005 I. Definition: An interrupt is an event that requires immediate attention from the CPU. II. Examples: mouse move, key press, network packet arrival III. Steps of an interrupt: A. OS receives interrupt B. saves register
Purdue - CS - 354
1) Interrupts a) An interrupt is an even that requires immediate attention from the CPU. b) When an interrupt is received, the CPU will stop whatever it is doing and it will jump to the "interrupt handler" that handles that specific interrupt. After execu
Purdue - CS - 354
System Calls A way for program to get services from the operating system Software interrupts generated by the program itself. During the system call, the OS o checks arguments validity o enforces policy and security o performs the service requested Exampl
Purdue - CS - 354
Bounded Buffer -problem: create producer threads and consumer threads that communicate using a circular buffer-new entries are added at tail and entries are removed from the head. New entries wrap around to beginning when the end of the array is reached.
Purdue - CS - 354
2/8/04 System Calls - the way a user program gets services from the operating system - system calls use software interrupts. These are interrupts generated by the program itself - during the system call the OS: + checks argument validity + enforces policy
Purdue - CS - 354
CS 354 Yashjeet Kaur Start by creating a new process for each command in the pipeline and having the shell wait for the last command to finish. No redirection for now, A|B|C create a process and exec for A,B,C and wait for C execute() for( each command in
Purdue - CS - 354
Threads A thread is an execution path inside a process. By default, a program has 1 thread that executes the main() procedure. A thread can be created using the unix call : pthread_create(proc, args, .) Windows call : CreateThread(proc, args); proc is poi
Purdue - CS - 354
Counter example (renew) Two threads increase a counter simultaneiously and some of the increments are lost. Solution: Use mutex locks to enforce the code that increments to be atomic.#include <pthread.h> int main() cfw_ int n = 1000000; int count = 0; th
Purdue - CS - 354
How mutex locks are implemented - Most modern CPU's have a "test_and_set" assembly instruction (or an equivalent) that is guaranteed to be executed atomically. This is the pseudocode in "c", that is done by the CPU atomicallyint test_and_set(int *v)cfw_
Purdue - CS - 354
Semaphores: generalization of mutexes initial count >= 0 pseudocode: sema_wait(sem) cfw_ sem>count; if(sem>count < 0) cfw_ /wait sema_post(sem) cfw_ sem>count+; /wake up one thread waiting on semaphore if any three ways of using semaphores: n = 0 make
Purdue - CS - 354
Lab 5client process->(RPCShared)<-server process Shared Memory RPCServer : RPCServer ( fileName ) cfw_ /open file with O_RDWR | O_CREAT | O_TRUNC use MOD 0666 or 0664 /mental note to self not sure about the trunc /fd is file descriptor /fill the file of
Purdue - CS - 354
Deadlock and starvation Deadlock It is a situation where one or more threads will block forever waiting for a resource (mutex or semaphore) that will never be available. You break a deadlock is by "bouncing" (kill and restart) the system. Best way is to p
Purdue - CS - 354
Condition Variables cond_init . initializes the condition variables cond_wait . waits until a cond_signal is called on this variable . cond. vars. have always a mutex associated with it . cond_wait has to be called in the following way mutex_lock(&cond_mu
Purdue - CS - 354
IntroductionVirtual Memory is a a system that allows the use of storage in hard drives, etc. as though they wer part of physical memory (RAM). The CPU uses a "Virtual Memory Address" while RAM uses a "Physical Memory Address." There is a device called an
Purdue - CS - 354
- Page fault is an interrupt created by the MMU when page is not resident - load it from disk to RAM - if RAM is full, find a good candidate page that can be replaced - which page should be replaced : 1. FIFO policy - replace the page that has been in RAM
Purdue - CS - 354
OS Notes For April 26th and 28th Uses of VM and mmap 1. Memory map text segment of an executable or shared library. It will load pages on demand. - Faster startup - Save in the use of RAM - Shared libraries and executably files in RAM can be shared across
Purdue - CS - 354
On-Disk CachingMethodPut RAM on disk controller to cache blocks Seagate ATA disk has .5MB, IBM Ultra160 SCSI has 16MB Some of the RAM space stores "firmware" (an OS)Blocks are replaced usually in LRU order Good for reads if you have locality Expensiv
Purdue - CS - 354
Page BitsEach entry in the page table needs only 20 bits to store the page number. The remaining 12 bits are used to store characteristics of the page.Resident Bit:Page is resident in RAM instead of swap space/file.Modified Bit:Page has been modified
Purdue - CS - 354
Page Replacement PoliciesDuring a page fault for a non-resident pageFind an empty page in physical memory If RAM is full, find a page that can be replaced. Load the non-resident page from disk into RAM FIFO - First In First OutWhat page to replace? Two
Purdue - CS - 354
PagingImplementation of VM used by modern operating systems. The unit of memory that is swapped in and out is a page Paging divides the memory in pages of fixed size. Usually the size of a page is 4KB in the Pentium (x86) architecture and 8KB in the Spar
Purdue - CS - 354
Passing Arguments to ModulesArguments can be passed to a loadable module at the time of loading. For example: To get the parameters. Define the variables as follows:sudo insmod ./second-mod.ko intParam=7 strParam="Hello"static int intParam = 5; static
Purdue - CS - 354
Personal ComputersPersonal Computers One computer one user This was possible at the end of the 70s thanks to the arrival of the microprocessor that allowed inexpensive computers. The first widely available PC was the Apple ][ with a 6502 CPU (16 bits)
Purdue - CS - 354
Part 8: Interprocess RPCLab5: Interprocess RPCRPC- Remote Procedure CallServer exports procedures that a remote client can execute. Client sends to server the arguments and the name of the procedure to run remotely. Then it waits for a result The serve
Purdue - CS - 354
File SystemsFile SystemsThe storage can be classified from fastest to slowest in the followingRegisters Cache RAM Flash Memory Disk CD/DVD Tape Network storageDisk File SystemsThe disk is a an electromagnetic and mechanical device that is used to sto
Purdue - CS - 354
Memory AllocationDynamic Memory AllocationWhy do we need dynamic memory allocation?We do not know how the program will be used and the memory requirements of the program until it is used. We could define variables statically using a maximum limit but:
Purdue - CS - 354
Process SchedulingFrom the user's point of view, an OS allows running multiple processes simultaneously. In reality, the OS runs one process after another to give the illusion that multiple processes run simultaneously. The Process Scheduler is the OS su
Purdue - CS - 354
Process TableEach process will be represented with an entry in the process table. The Process Table is one of the most important data structures in the kernel. The maximum number of entries in the process table determines the maximum number of processes
Purdue - CS - 354
Processeses and Threads ReviewProcesses A process is a program in execution A program may have multiple processes running the same program. E.g. csh running for multiple users or multiple times for the same user. Each process will be a different instan
Purdue - CS - 354
Program LoadingAssuming a simple program like:brastius 723 % cat hello.c #include <stdio.h> main() cfw_ printf("Hello World\n"); brastius 724 % gcc -o hello hello.cbrastius 725 % ./hello Hello World brastius 726 %Now we can examine the system calls i