NTPD – Network Time Protocol Daemon

Mittels NTPD können wir von einem gewünschten Server eine Zeit abfragen

Important

A Server ion GErmany could be : http://ptbtime1.ptb.de/

stratum : trust-worthiness of that servers data

Stratum Concept

Important

Beispiel ==MacOS== mittels sntp :
sntp -d [ntp1.rz.uni-saarland.de](http://ntp1.rz.uni-saarland.de/) [ntp2.rz.uni-saarland.de](http://ntp2.rz.uni-saarland.de/) [ntp3.rz.uni-saarland.de](http://ntp3.rz.uni-saarland.de/)

Shell Programming

  • scripts start with #!/bin/bash

  • call commands, programs, shell scripts

  • using control structures

  • environment variables

  • setting vars: VAR=value

  • reading vars: $value

  • parameters 1,…$9

  • return / exit value $?

  • all variables are strings
    may in conditions be interpreted as an integer

Conditions in Shell Programming : The Test command

Controll Structures

1. for ... do ... done
2. for ... in ... do ... done
3. while ... do ... done
4. until ... do ... done
5. if ... then ... else ... fi, see also elif
6. case ... esac
there is a break statement to leave loops

Shell Functions

#!/bin/sh
do_something()
{
if test -e $1 ; then
echo file $1 exists
return 0
else
echo file $1 "doesn’t" exist
return 1
fi
}
do_something /etc/passwd
do_something /etc/nothing
exit 0 # return sucessfully

Important

with at timed scripts are possible, crontab -e is used for periodically running scripts

  • What is a Process ?

    A Process is a program currently being executed by a processor

Important

Each process has a unique PID, created at the start

Important

the command fork( ) can be used to create an identical copy of a process.
This copy has the same memory and registers

  • parent process : fork( ) reuturns PID of child

  • child process : fork( ) returns 0

Context Switches

Ein Kontext Switch ist ein Wechsel der Aufgabe, entweder nach :

  • Ablauf der Bearbeitungszeit des Prozesses

  • nach einem System Interrupt

    Was gemacht wird :

    1. Speichern der Register des jetztigen Prozesses
    2. Laden der Register des nächsten Prozesses

Threads

  • Was ist ein Thread ?

    Threads sind Aufgaben, welche innerhalb eines Prozesses abgearbeitet werden.

Important

Threads innerhalb eines Prozesses teilen sich den gleichen Speicher (Shared Memory)

  • Warum Threads nutzen ?

    1. Threads sind einfach zu erstellen wie neue Prozesse

    2. Kontext Wechsel sind schneller → Caches werden verwendet

  • Welche Probleme können bei Threads auftreten ?

    1. Schreiben / Lesen auf gemeinsamen Speicher ist geblockt → ==DeadLocks==

    2. System Call könnten den ganzen Prozess blockieren → Alle Threads blockiert

Programming Threads

• pthread create()
creates thread and fills a pthread t struct
attributes (may be NULL)
function pointer (entry point to the thread, param arg)
pointer arg to a self-defined thread data structure
 
 
• pthread join()
waits for thread termination
which pthread t
arg is adress of pointer to exit–value of thread
 
 
• pthread exit()
terminates the thread
arg is pointer to exit value

Scheduler

Which Process is allowed to run ? → WE need a Round-Robin Scheduling algorithm

Priorities can be set by : nice , renice , setpriority( )

Possible Status of a Process [ ps → ==STAT column== ]

CodeMeaningDetails / Examples
RRunningAktuell auf CPU ausgeführt
SSleeping (< 20 s)Kurzschlaf durch sleep(), read(), accept(), …
IIdle / Long Sleeping (≥ 20 s)Länger inaktiv, z. B. wartend
DUninterruptible SleepMeist durch I/O-Operationen blockiert
TStopped / TracedAngehalten oder durch Debugger verfolgt
WSwappedAus dem Hauptspeicher ausgelagert
ZZombieBeendeter Prozess, dessen Parent den Exit-Status noch nicht abgeholt hat