












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













Spring 2009 CS5523: Operating System: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 1
a Basic concepts of process ¾ Representation: process control block (PCB) ¾ Execution environment: address space a Basic operations for process management ¾ Process creation/termination a States of process: different queues ¾ ready, running, or wait etc ¾ Context switch: multiple hardware running contexts a Scheduling of process: CPU scheduling ¾ Basic scheduling algorithms: FIFO, SJF etc a Inter process communication ¾ shared memory and message
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 3
¾ stored in files ¾ a passive entity
¾ Running of a program ¾ A program counter: what the next instruction is ¾ A set of associated resources (memory, open file handles) ¾ Dynamic concept
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 7
¾ code section (text segment), ¾ data section (global variables), ¾ stack (temporary data Æ local variables and return address etc) ¾ Auxiliary : environment variables and command line arguments ¾ Heap: memory for dynamically allocated data items
Stack
Text
Heap
Auxiliary regions
0
2 N
a Special CPU registers ¾ Base register: start of the process’s memory partition ¾ Limit register: length of the process’s memory partition ¾ Access limited to system mode a Address generation ¾ Logical address: location from the process’s point of view ¾ Physical address: location in actual memory ¾ Physical = base + logical address ¾ Logical address larger than limit Æ error
P
OS 0
0xFFFF
Limit
Base
0x
0x
Logical address: 0x Physical address: 0x1204+0x9000 = 0xa
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 9
a Each process has its own base and limit registers
a Memory allocation: no overlap for protection
P
OS 0
0xFFFF
Limit
Base
0x
0x
P
Limit
Base
0x
0xC
Virtual Æ physical address translation?
¾ System initialization ¾ User request to create a new process (run a program) ¾ A running process use system call for process creation
¾ Hierarchy of processes
¾ Will the parent and child execute ”concurrently”? ¾ How their address spaces are related? ¾ Will/should the parent and child share some resources?
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 13
pid = 26
UNIX kernel
Text
Process Status
Stack
Data
FileFile
Stack
ResourcesResources Data
<…> int cpid = fork( ); if (cpid = = 0) {
Text
<…> int cpid = fork( ); if (cpid = = 0) {
Process Status
pid = 25
cpid = 26 (^) cpid = 0
void main (){ int pid; pid = fork(); if (pid < 0) {error_msg} else if (pid == 0) {/ child process / execlp(“/bin/ls”, “ls”, NULL); }else { / parent process / / parent will wait for the child to complete / wait(NULL); exit(0); } }
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 15
a Bursts of CPU usage alternate with periods of I/O wait a Some processes are CPU-bound : they don’t make many I/O requests a Other processes are I/O-bound and make many kernel requests
CPU bound
I/O bound
CPU bursts I/O waits
Total I/O usage
Total CPU usage
Time
Ready (^) Running
Waiting
New Terminated
Event wait
Event occurs
Scheduler Exit Dispatch
Timeout
Admit
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 19
¾ Ready queue – processes in main memory, ready and waiting to execute ¾ Wait queue – processes waiting for signals/interrupts ¾ Device queues – processes waiting for I/O operations
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 21
¾ Common in batch systems ¾ Two types of batch scheduling 9 Submission of a new job causes the scheduler to run 9 Scheduling only done when a job voluntarily gives up the CPU ( i.e. , while waiting for an I/O request)
¾ Necessary for interactive systems ¾ May also be used for batch systems ¾ Scheduling algorithms at each interrupt, and picks the next process from the pool of “ready” processes
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 25
¾ Long computation process proceeds SSH console?
¾ Optimal in term of waiting time
¾ Processes take turns, e.g., 10ms
¾ Real-time systems: earliest deadline first (EDF)
¾ System processes >faculty processes >student processes
a Goal: do jobs in the order they arrive ¾ Fair in the same way a bank teller line is fair a Simple algorithm! a Problem: long jobs delay every job after them ¾ Many processes may wait for a single long job
A B C D
4 3 6 3
Current job queue
Execution order
FCFS scheduler
A B C D
4 3 6 3
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 27
a Goal: do the shortest job first ¾ Short jobs complete first ¾ Long jobs delay every job after them a Jobs sorted in increasing order of execution time ¾ Ordering of ties doesn’t matter a Shortest Remaining Time First (SRTF): preemptive form of SJF a Problem: how does the scheduler know how long a job will take?
A B C D
4 3 6 3
B D A C
3 3 4 6
Current job queue
Execution order
SJF scheduler
a Round Robin scheduling ¾ Give each process a fixed time slot ( quantum ) ¾ Rotate through “ready” processes ¾ Each process makes some progress a What’s a good quantum? ¾ Too short: many process switches hurt efficiency ¾ Too long: poor response to interactive requests ¾ Typical length: 10–50 ms
A B C D E
Time
A
B
C
D
E
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 31
CPU
Main memory
CPU scheduler
Memory scheduler
Job scheduler Input queue
Arriving jobs
a Jobs held in input queue until moved into memory ¾ Pick “complementary jobs”: small & large, CPU- & I/O-intensive ¾ Jobs move into memory when admitted a CPU scheduler picks next job to run a Memory scheduler picks some jobs from main memory and moves them to disk if insufficient memory space
¾ Mechanism allows 9 Priorities to be assigned to processes 9 CPU to select processes with high priorities ¾ Policy set by what priorities are assigned to processes
¾ Mechanism in the kernel ¾ Priorities assigned in the kernel or by users
¾ Don’t allow a user process to take over the system! ¾ Allow a user process to voluntarily lower its own priority ¾ Allow a user process to assign priority to its threads
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 33
¾ Slave CPUs: execute assigned processes
¾ Simultaneously multithreading (SMT): multiple function units and running context (registers), more inst./cycle ¾ Chip-Multiprocessors (CMP): multiple simple CPUs (cores) on single chip
Message Passing (^) Shared Memory
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 37
*int main(int argc, char argv[]) { int shmid; char * data; … … / setup the shared segment: / if ( (cpid = fork())==0 ){//child process sprintf(data, “Child: using SM!”); sleep(1); //give parent a chance printf(“%s\n”, data); exit(0); }else if (cpid >0){ //parent process sleep(1); //let child first sprintf(data, “Parent: chaning SM”); wait(cpid); //wait child to finish } shmdt(data); shmctl(shmid, IPC_RMID, NULL); return 0; }
a Message system – processes communicate with each other without resorting to shared variables.
a A message-passing facility provides at least two operations: ¾ send ( message ) ¾ receive ( message ) ¾ These operations can be either blocking (synchronous) or non- blocking (asynchronous).
a What should we do for processes running on different computers (e.g., in distributed system)?
Shared memory vs. message passing?
Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 39
¾ Server 9 Create a socket with the socket() 9 Bind the socket to an address using the bind() 9 Listen for connections with the listen() 9 Accept a connection with the accept() system call. ¾ Client 9 Create a socket with the socket() system call 9 Connect to server using the connect() system call 9 read() and write()
¾ Server: ServerSocket ¾ Client: Socket
¾ Representation: process control block (PCB) ¾ Execution environment: address space
¾ Process creation/termination
¾ ready, running, or wait etc ¾ Context switch: multiple hardware running contexts
¾ Basic scheduling algorithms: FIFO, SJF etc