Partial preview of the text
Download Operating Systems Notes | Processes, Scheduling, Deadlocks, Paging & File Systems and more Study notes Operating Systems in PDF only on Docsity!
OPERATING SYSTEMS 1. PROCESSES A process is @ program tn of a program execution . Stack, heap and pregyam Counter. Process State A process changes state duxing dispatch ues lif etime- Tt ts an instance with ‘its own address space, data, code, exit (Wen) admit event Occurs Process Control Block (PCB) > ( Runnin 4 I/O or event wait PCB is a data structure maintained by OS fer @ach process . It contains all information about the process » Process ID (PID) Process State Example Program Counter CPU Registers CPU Scheduling Information Memory Management Information Accounting Information T/0 Status Information When we open Chrome, OS creates a process. Each tab Can be a Separate process . If Chrome is closed, the process is terminated . 2» THREADS A thread is the smallest unit process. Multiple threads of the CPU execution within a Same process Share code, data and resources but have separate stack and Ty, pes of Threads * User Level Threads (ULT) * Kernel Level Threads (KLT) a Hy brie Threads Program counter . Benefits + Improved vesponsiveness « Resource sharin * Economy (cheaper than processes) 2 Scalability on multiprocessor systems Example In a music player app, one thread can play music while another shows visuals. Code Data Files Code Data Files Stack Stack Stack Stack 3 ; 5 ; Single Thread Process Multi Thread Process 3. CPU SCHEDULING CPU scheduling is the process of selecting a process from the ready queue and allocating the CPU to it. Goals Scheduling Queues * CPU Utilization — Keep CPU busy as much as possible. New Queue ° Throughput — maximum number of processes completed per unit time. « Turnaround Time - total time taken from Submission to completion should be minimum. ° Waiting Time — total time a process spends in ready queue should be minimum. + Response Time - time from submission to first response should be minimum. a aren hrc | Re eee j Scheduding Criteria Terminated Queue ¢ CPU Utilization (Maximize » Watting Time (Minimize ee a ‘ Throughput (Maximize) + Response Time (Minimize) eiiemateerd) Tie (Miniaize) Scheduling Algorithms Algorithm Description Advantage Disadvantage Ae FCES Processes are executed in Simple and eas Convo lect, poor la 4 | P (First Come the order they arrive in to implement. average waiting time . First Serve.) the ready queue. BASIE Process with the smallest Minimum fee Need to know burst time (Shortest Job | burst time is selected waiting Hime tn advance. May cause First) first. starvation of long jobs. 3. Priovity Process with highest priovity| Flexible, important | Starvatfon of low Se ing is executed first. (Lower processes get CPU priority processes. number ~> higher priority) early . 4, Round Robin | Each process gets a fixed | Falr, good for Hme- | Tf time quantum is (RR) time quantum in egelic shawing system . small > context switch order . overhead Increases . 5, Multilevel Ready queue is divided Good response, Complex, fixed priority Q Into multiple queues. Each | different types of may cause starvation queue has tts own algorithm. processes handled . 6. Multilevel Processes can move between | More flexible , Complex to implement. a Queue | queues based on thelr PER vert behavior. Example Gantt Chart (FCFS) Using FCFS: Bevcece Arrival Time Burst Time ie ie fis les Py 0 5 to) 5 & 16 22 Waiting Time: Pe 4 3 a i ‘ ; Bee Average baiting Time i . Z ys eae = (04446413) /4 ‘i Fa 5) 8 25-16 = 5.95 units Py = 16-3 = 13 a 6. PAGING Paging isa memory management scheme in which the logical address space of a process is divided into fixed-size blocks called pages and physical memory is divided into blocks of the some size called frames. Key Points * Page size = Frame size « Eliminates external fragmentation . . May have internal fragmentation . Paging Model Logical Physical Address ji Space Frame O ce j Page femeat “s Table. ame xp i d Femelm Poge Table A page table stores the mapping from page numbers to frame numbers. 2A can be placed tn any free frame. Page Frome Peg le fee Number Number Address Translation o 2 Ss a eB oe Logical addvess = (page number, page offset 2 9 vps ag Pee Ge) : 7 memory if 4 7 P= number of bits for page number 5 = d= number of bits for page offeet : page is not Then ( - ; Logical address = p + d bits one! Physical address = (frame number, page. offset) Address Translation Example From page table, Pajetcice IRB S20 bat Suppose logical address = 110010 1010110010 je 50 is in frome 7. bake = 46 bits a : . ai ress = 16 bi! p C6 hts) ad (uo ue) ‘ysl adevess = (frome no effet) > p= 6 bits (for 64 pages) = (7, 690) > d= 10 bite (offset within page) page number = 110010, = 50,, ae number 7 in binary (for 6 frames) = 0111 t = 1010110010, = aS ae OH Prysical address = 0114, 1040410020 Advantages * Eliminates external fragmentation . © Allows noncontiguous allocation . © Supports virtual Lage (6 bits) (0 bits) Disadvantages ¢ Internal fragmentation (wasted space in last page). + Extra memory regutved. for page table. 2 EEE SY SmEMS: A file Gee is the part of an OS that manages files and directories on secondary storage. It provides methods for storing organizing and retrieving data. File Systeon Functions + File. creation and deletion . Divectory management + Support for file operations (read, write, update) + Mapping files te secondary storage * Backup and recovery + Access contvel and protection File Types * Regular files — text, binary, documents, ete . * Directory files ~ contain entries for files /subdivectovies. © Special files — represent I/O devices File Access Methods 1, Sequential Access — records are accessed in order. De Tee Eee — or 2. Direct Access - any record can be accessed directly . Lar ase eal v4 * 3. Indexed Access - an index is used to locate records. Ls ere (ele la [eT File System Structures Structure Description Single-level Divectory | All files ave in the same directory Two-Level Directory | Each user has thelr own aivectory . Tree-structured Divectory| Directories con contain files and other directories. Aeyelic Graph Divectory| Allows sharing of files and subdivectovies . F. FILE SYSTEMS (Contd.) File. Attributes (Metadata.) Directory Structure Example. Each file has attributes stored in its Root (/) divectory entry . Attribute Deseviption rally e = Name. Hunan—veadable file name Identifier Unique tag (tnede number) Type File type (text, binary , directory , etc.) user user2 | | config fg fog Location | Pointer to file's data on storage af F < - ae ; yey { Root directory is at the | See Chg SED Gee ee doc.tet || notes.c| | pie.jog | top. Each divectory can | Protection | Access permissfons (read/write /execute) | contain files and other | 1 + . i! Time, Date | Creation, last modification , last access AEE eee } File Allocation Methods File Operations Z i, : g Sees 1. Contiguous Allocation — Each file occupies Operation Description contiguous blocks on disk. Create Create a new file fle Bees lel le) Open Open an existing file for access File size = 3 blocks (starts at block 3) Read eget 2, Linked Allocation — File ts a Linked Uist of blocks Write Write data. to file scattered anywhere on disk. Append. Add dota ot the end of file [zt}->u ee aba} ] Close Clese the fle Directory entry stores pointer to first block . Delete Reraavel file fees jie fore 3. Indexed Allocation — An index block contains Renae Change the name of file pointers to all data blocks of the file . Truncate Reduce file size to zero or specified size Filer st 8 2 § 2 10 i0 File Systema Mounting Before a féle system can be accessed, it must be mounted . + Mounting makes the file system available at a mount point in the directory tree. + After use, it is unmounted . mount /dev/sdat mnt /data unmount mnt /date. le System Comparison Example : File System Examples (Types) + FAT32 — Used in removable devices, simple and. widely compatible. + NTFS — Windows file system, supports security , compression , large files . + ext4 — Common in Linux, journaling file system, high performance . * HFS+ / APFS — Used. in macdS. An Operating System manages precesses, threads and CPU scheduling to ensure efficient execution. It prevents deadlocks among competing processes. Memory management (including paging) provides efficient and secure use of memory. File systems organize data on Secondary storage and provide methods for storage, retrieval and. protection . ‘ Feature. FAT32 NTFS ext APFS Max File Size 4 GB 16 TB 16 TB. 16 EB Max Volume Size 2 7B 256 TB 1 EB 8 EB Security Basic Advanced (ACL) Unix Permissions Advanced Journaling No Yes Yes Yes Compression No Yes Yes Yes Typical Use. USB, SD Cards Windows Systems Linux Systems macOS Systems a aa ee eas Topics Covered ae Y Processes & Memory Management © Threads ical ace “o &% cru Scheduling o Fite Systems MY Deadlocks ff Noa pee a ee All topics covered! ©) fe)