Operating Systems Cheat Sheet

OS Functions

FunctionDescriptionExample
Process ManagementManage processes and threadsProcess creation, scheduling, synchronization
Memory ManagementManage primary memory allocationVirtual memory, paging, segmentation
File System ManagementManage files and directoriesFile creation, deletion, access control
I/O ManagementManage input/output devicesDevice drivers, buffering, spooling
Security and ProtectionProtect system and user dataAccess control, authentication, encryption
NetworkingManage network communicationNetwork protocols, data transmission
Error DetectionDetect and handle system errorsHardware failure detection, error recovery

Process States

StateDescriptionTransition Trigger
NewProcess being createdProcess creation request
ReadyProcess waiting for CPU allocationAdmitted by OS, waiting for scheduler
RunningProcess currently executingScheduled by CPU scheduler
WaitingProcess waiting for I/O or eventWaiting for I/O completion, resource, signal
TerminatedProcess finished executionProcess completed or killed
BlockedProcess waiting for resourceWaiting for unavailable resource

CPU Scheduling Algorithms

AlgorithmStrategyAdvantagesDisadvantagesUse Case
FCFS (First-Come, First-Served)First arrived, first servedSimple, fairConvoy effect, poor average waiting timeBatch systems
SJF (Shortest Job First)Shortest job executes firstMinimum average waiting timeStarvation, hard to predict job lengthTheoretical optimization
SRTF (Shortest Remaining Time First)Preemptive version of SJFOptimal average waiting timeStarvation, overheadReal-time systems
Round RobinFixed time quantum per processGood response time, fairContext switching overheadTime-sharing systems
Priority SchedulingHigher priority executes firstFlexible, can prioritizeStarvation possibleReal-time systems
Multilevel QueueProcesses in different priority queuesDifferent scheduling for different typesPotential starvationMultiple process types
Multilevel Feedback QueueDynamic priority adjustmentPrevents starvation, responsiveComplex implementationGeneral-purpose systems

Memory Management

ConceptDescriptionAdvantagesDisadvantages
Contiguous AllocationEach process gets contiguous memory blockSimple, efficientExternal fragmentation, memory waste
PagingDivide memory into fixed-size pagesNo external fragmentation, efficientInternal fragmentation, page table overhead
SegmentationDivide memory into variable-size segmentsNatural program structure, sharing possibleExternal fragmentation, complex
Virtual MemoryExtend physical memory with disk spaceLarger logical address space, process isolationPerformance overhead, complexity
Page ReplacementReplace pages when memory is fullEfficient memory utilizationPage fault overhead

Page Replacement Algorithms

AlgorithmStrategyAdvantagesDisadvantages
Optimal (OPT)Replace page used farthest in futureTheoretical minimum page faultsImpractical, requires future knowledge
FIFO (First In, First Out)Replace oldest pageSimple implementationBelady's anomaly possible
LRU (Least Recently Used)Replace least recently used pageGood performance, stack algorithmImplementation overhead
LFU (Least Frequently Used)Replace least frequently used pageConsiders frequencyMay keep old popular pages
Clock AlgorithmApproximation of LRU using reference bitGood performance, simpleApproximation of LRU
Second ChanceFIFO with reference bit checkBetter than FIFOStill FIFO-based

Process Synchronization

ConceptDescriptionImplementationUse Case
Critical SectionCode segment accessing shared resourcesEntry/exit protocolsShared resource access
MutexMutual exclusion lockBinary semaphoreExclusive access to resource
SemaphoreInteger variable for synchronizationWait and signal operationsResource counting, synchronization
MonitorHigh-level synchronization constructCondition variables, locksStructured synchronization
Producer-ConsumerCoordination between processesBuffer, semaphoresData sharing between processes
Reader-WriterMultiple readers, single writerRead-write locksDatabase access, file sharing
Dining PhilosophersResource allocation problemResource ordering, deadlock preventionDeadlock avoidance

Deadlock Conditions

ConditionDescriptionHow to HandleExample
Mutual ExclusionResource cannot be sharedResource sharing where possiblePrinter cannot be shared
Hold and WaitProcess holds resources while waitingRequest all resources at onceProcess holds disk, waits for printer
No PreemptionResources cannot be forcibly takenAllow resource preemptionCannot take resources from process
Circular WaitCycle of processes waiting for each otherResource orderingP1 waits for P2, P2 waits for P1

File System Concepts

ConceptDescriptionAdvantagesDisadvantages
Contiguous AllocationFile stored in contiguous blocksFast access, simpleExternal fragmentation, difficult to grow
Linked AllocationFile stored as linked list of blocksNo external fragmentation, easy to growNo random access, pointer overhead
Indexed AllocationIndex block contains pointers to file blocksRandom access, no external fragmentationIndex block overhead
Free Space ManagementTrack available disk spaceEfficient space utilizationManagement overhead
Virtual File SystemAbstraction layer for different file systemsMultiple file system supportAdditional complexity

Security Concepts

ConceptDescriptionImplementationExample
AuthenticationVerifying user identityPasswords, biometrics, certificatesLogin with username/password
AuthorizationGranting access rightsAccess control lists, capabilitiesFile permissions
Access ControlControlling resource accessDiscretionary, mandatory, role-basedFile read/write permissions
EncryptionProtecting data confidentialitySymmetric, asymmetric encryptionFile encryption
AuditingMonitoring security-related eventsLog security eventsAccess logs, system logs

System Calls

CategorySystem CallPurposeExample
Process Controlfork(), exec(), wait(), exit()Create, execute, wait, terminate processesCreate child process
File Managementopen(), read(), write(), close()File operationsRead from file
Device Managementioctl(), read(), write()Device operationsRead from device
Information Maintenancegetpid(), time(), getuid()Get system informationGet process ID
Communicationspipe(), shmget(), mmap()Process communicationCreate pipe for IPC
Protectionchmod(), umask(), chown()Set access permissionsChange file permissions

Virtualization Concepts

ConceptDescriptionAdvantagesDisadvantages
Full VirtualizationComplete simulation of hardwareRuns unmodified OS, good isolationPerformance overhead
Para-virtualizationGuest OS modified to work with hypervisorBetter performance than full virtualizationRequires guest OS modification
Hardware-assisted VirtualizationHardware support for virtualizationGood performance, securityRequires special hardware
ContainerizationOS-level virtualizationLightweight, fast, efficientLess isolation than full VM