Download presentation
Presentation is loading. Please wait.
Published byJonah Parker Modified over 8 years ago
1
CS703 - Advanced Operating Systems By Mr. Farhan Zaidi
2
Lecture No. 22
3
Mark and Sweep Collecting Before mark After mark After sweep root free Mark bit set free
4
Mark and Sweep ptr mark(ptr p) { if (!is_ptr(p)) return; // do nothing if not pointer if (markBitSet(p)) return // check if already marked setMarkBit(p); // set the mark bit for (i=0; i < length(p); i++) // mark all children mark(p[i]); return; } Mark using depth-first traversal of the memory graph Sweep using lengths to find next block ptr sweep(ptr p, ptr end) { while (p < end) { if markBitSet(p) clearMarkBit(); else if (allocateBitSet(p)) free(p); p += length(p); }
5
What is an operating system? Top-down view Bottom-up view Time multiplexing Space multiplexing
6
Type of Operating Systems Main frame operating systems Time-sharing systems Multiprocessor operating systems PC operating systems Real-time operating systems Embedded operating systems
7
Monolithic Design Layering Micro-kernel OS Structure
8
ELF Object File Format Elf header Program header table.text section.data section.bss section
9
Strong and Weak Symbols Program symbols are either strong or weak
10
Linker’s Symbol Rules Rule 1. A strong symbol can only appear once. Rule 2. A weak symbol can be overridden by a strong symbol of the same name. Rule 3. If there are multiple weak symbols, the linker can pick an arbitrary one.
11
Creating Static Libraries Translator atoi.c atoi.o Translator printf.c printf.o libc.a Archiver (ar)... Translator random.c random.o ar rs libc.a \ atoi.o printf.o … random.o C standard library
12
The Complete Picture Translator m.c m.o Translator a.c a.o libc.so Static Linker (ld) p Loader/Dynamic Linker (ld-linux.so) libwhatever.a p’ libm.so
13
Process A unit of activity characterized by the execution of a sequence of instructions, a current state, and an associated set of system instructions
14
Private Address Spaces kernel virtual memory (code, data, heap, stack) memory mapped region for shared libraries run-time heap (managed by malloc) user stack (created at runtime) unused 0 %esp (stack pointer) memory invisible to user code brk 0xc0000000 0x08048000 0x40000000 read/write segment (.data,.bss) read-only segment (.init,.text,.rodata) loaded from the executable file 0xffffffff
15
Asynchronous Exceptions (Interrupts) Caused by events external to the processor
16
Synchronous Exceptions Traps Faults Aborts
17
Process Creation Assign a unique process identifier Allocate space for the process Initialize process control block
18
Unix SVR4 Processes
19
Process Control Block Process state: e.g., running, ready, waiting, halted Priority Scheduling-related information Event
20
fork : Creating new processes int fork(void)
21
exit : Destroying Process void exit(int status)
22
Zombies Idea Reaping
23
exec : Running new programs int execl(char *path, char *arg0, char *arg1, …,0)
24
Safe and Unsafe Trajectories H1H1 L1L1 U1U1 S1S1 T1T1 H2H2 L2L2 U2U2 S2S2 T2T2 Thread 1 Thread 2 Unsafe region Unsafe trajectory Safe trajectory critical section wrt cnt
25
Semaphores semaphore = a synchronization primitive – higher level than locks – invented by Dijkstra in 1968, as part of the THE OS
26
Two uses of semaphores Mutual exclusion Scheduling constraints
27
Condition variables Condition variable: a queue of threads waiting for something inside a critical section. Wait() -- release lock, go to sleep, re-acquire lock Signal() -- wake up a waiter, if any Broadcast() -- wake up all waiters
28
Reentrant Functions Reentrant functions Thread-unsafe functions Thread-safe functions
29
Formal definition of a deadlock A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause
30
Conditions for deadlock Without all of these, can't have deadlock: 1. Mutual exclusion 2. No preemption 3. Hold and wait 4. Circular wait
31
Paradigms of thread usage (from Hauser et al paper) Defer work General pumps Slack processes Sleepers One-shots Deadlock avoidance Rejuvenation Serializers Encapsulated fork Exploiting parallelism
32
Scheduling: First come first served (FCFS or FIFO) Simplest scheduling algorithm: Run jobs in order that they arrive
33
Round robin (RR) Solution to job monopolizing CPU? Interrupt it. Run job for some “time slice,” when time is up, or it blocks, it moves to back of a FIFO queue
34
Priority scheduling Obvious: not all jobs are equal So: rank them.
35
A simple multi-level feedback queue priority
36
Summary FIFO: + simple - short jobs can get stuck behind long ones; poor I/O RR: + better for short jobs - poor when jobs are the same length STCF: + optimal (ave. response time, ave. time-to-completion) - hard to predict the future - unfair Multi-level feedback: + approximate STCF - unfair to long running jobs
37
Multiprocessor Thread Scheduling Dedicated processor assignment Dynamic scheduling
38
Gang Scheduling Simultaneous scheduling of threads that make up a single process
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.