Docsity

Scheduling Algorithms and Moving Averages in Operating Systems - Prof. Gustavo Rodriguez-R, Study notes of Operating Systems

Partial preview of the text

Download Scheduling Algorithms and Moving Averages in Operating Systems - Prof. Gustavo Rodriguez-R and more Study notes Operating Systems in PDF only on Docsity!

Additional Notes on Scheduling

Efficient Scheduling

Constant time, O(1)

Less efficient: O(n) where n is the number of

processes in the system

Scheduling becomes slower as there are more

processes

Question: Is the process aging technique

O(1) or O(n)?

Moving Average

Question: What is the starting value before

any data is known?

A: Anything reasonable.

Typically an operating system uses a full time

quantum as the initial estimated CPU burst

The book uses 10 ms in an example

Good question because it means you think about

border cases

Kinds of Moving Averages

The formula we saw is known more precisely

as an exponential moving average

There is also a linear moving average

Every data point has the same weigth

In the exponential version, older data points are

weighted less, newer data has a higher weight,

following a decaying exponential formula

Answer

Data Case A Case B

What if it started at 50

Data Case A Case B

Can you change the quantum?

Part 5. Unix System

Programming and The Shell

Project

Shell Interpreter

The shell project is divided into several

subsystems:

Parser : reads a command line and creates a

command table. One entry corresponds to a

component in the pipeline.

Example:

Command: ls –al | grep me > file

ls -al

grep me

In:dflt Out:file1 Err:dflt

Command Table

Shell Interpreter

Executor:

Creates new process for each entry in the

command table.

It also creates pipes to communicate the output

of one process to the input of the next one.

Also it redirects the stdinput, stdoutput, and

stderr.

A | b | c | d > out < in

•All pipe entries share the same stderr

Shell Project

Part 1: Shell Parser.

Read Command Line and print Command Table

Part 2: Executer:

Create Processes and communicate them with

pipes. Also do in/out/err redirection.

Part 3: Other Subsystems:

Wildcard, Envars, Subshells

Lex and Yacc

  • A parser is divided into a lexical analyzer that

separates the input into tokens and a parser that

parses the tokens according to a grammar.

  • The tokens are described in a file shell.l using

regular expressions.

The grammar is described in a file shell.y using

syntax expressions.

Shell.l is processed with a program called lex that

generates a lexical analyzer.

Shell.y is processed with a program called yacc

that generates a parser program

Shell Grammar

You need to implement the following grammar in shell.l

and shell.y

_cmd [arg] [ | cmd [arg] ]* [ [> filename]_**

[< filename] [ >& filename] [>>

_filename] [>>& filename] ] [&]_*

Currently, the grammar implemented is very simple

Examples of commands accepted by the new grammar.

ls –al

ls –al > out

ls –al | sort >& out

awk –f x.awk | sort –u < infile > outfile &

What does this do?

  • ./program_name </dev/null

>~/my_log.err 2>&

Dev/null is the “null device”

Everything written there is discarded

Used as input, it automatically ends it

  • “>” redirects output to a file
  • “2>&1” merges the “standard error” file descriptor (#2)

with the “standard output” file descriptor (#1)

Shortcut: in some shells just “>& myfile” does both “>

myfile” and “2>&1”