| |
Motivation
|
Es ist sehr lehrreich, nicht nur aufzunehmen, was in Büchern
und Vorlesungsunterlagen steht, sondern zusätzlich auch
selbst relevanten Code zu studieren. Das ist auch mit wenig
Zeitaufwand und ohne tiefgreifende Vorkenntnisse möglich.
John Lions' Commentary und die Sechste Edition von Unix (aka. V6)
sind dazu eine hervorragende Grundlage.
Diese Seite bietet Einstiegspunkte zu interessanten Stellen mit
Bezug auf die Vorlesung.
|
| |
Links
|
John Lions: Commentary on the Sixth Edition Unix Operating System
|
| |
fork()
|
Datei
|
Zeile im Code
|
Kapitel im Buch
|
Inhalt
|
main.c
|
1589
|
6.5
|
proc[0] (Scheduler)
|
main.c
|
1627
|
6.6
|
init Prozess
|
slp.c
|
1826
|
7.13
|
newproc() == Internals von fork
|
sys1.c
|
3322
|
12.8
|
fork sys call
|
|
| |
exec(), exit(), wait()
|
Datei
|
Zeile im Code
|
Kapitel im Buch
|
Inhalt
|
sys1.c
|
3020
|
12.7
|
exec sys call (laed das neue Programmimage)
|
sys1.c
|
3219
|
13.18
|
exit sys call (Kommentar in 3213! Erzeugt Zombies.)
|
sys1.c
|
3270
|
13.20
|
wait sys call (Kommentar in 3264! Bettet Zombies zur Ruhe.)
|
Prozesse werden am Anfang von Kapitel 7 beschrieben.
Zu der in der Vorlesung angesprochenen close-on-exec Funktionalitaet von open(2) sagt dessen Manpage:
O_CLOEXEC (Since Linux 2.6.23)
Enable the close-on-exec flag for the new file descriptor.
Specifying this flag permits a program to avoid additional fcntl(2) F_SETFD
operations to set the FD_CLOEXEC flag. Additionally, use of
this flag is essential in some multithreaded programs since using a separate
fcntl(2) F_SETFD operation to set the FD_CLOEXEC flag does not suffice to avoid
race conditions where one thread opens a
file descriptor at the same time as another thread does a fork(2) plus execve(2).
|
| |
login shell
|
Bei Unix ist der Dateiname/Pfad und argv[0] unabhaening von einander.
Dies wurde bei den exec Funktionen angesprochen.
Das Beispiel war die Login-Shell die beispielsweise als ``-sh'' aufgerufen wird.
Dieses Verhalten kann man bei der
Heirloom Bourne Shell
studieren.
Bei heirloom-sh-050706 in main.c:
105 /*
106 * If the first character of the last path element of v[0] is "-"
107 * (ex. -sh, or /bin/-sh), this is a login shell
108 */
109 if (*simple(v[0]) == '-') {
110 signal(SIGXCPU, SIG_DFL);
111 signal(SIGXFSZ, SIG_DFL);
112
113 /*
114 * As the previous comment states, this is a login shell.
115 * Therefore, we set the login_shell flag to explicitly
116 * indicate this condition.
117 */
118 login_shell = TRUE;
119 }
Die Funktion simple() steckt in service.c:
126 unsigned char *
127 simple(unsigned char *s)
128 {
129 unsigned char *sname;
130
131 sname = s;
132 while (1) {
133 if (any('/', sname))
134 while (*sname++ != '/')
135 ;
136 else
137 return (sname);
138 }
139 }
Hier wird statt dem ueblichen Namen argv nur v verwendet.
v[0] ist also der Name unter dem das Programm aufgerufen wurde.
|
| |
Signale
|
Signale werden in Kapitel 13 beschrieben.
Sie werden im Buch ``Software Interrupts'' genannt.
Datei
|
Zeile im Code
|
Kapitel im Buch
|
Inhalt
|
param.h
|
0113
|
13
|
Anzahl und Namen der Signale
|
sys4.c
|
3614
|
13.1, 13.6, 13.10
|
signal sys call (implementiert durch ssig(), nicht durch signal()!) (``Erwartung'')
|
sys4.c
|
3630
|
13.2, 13.7, 13.11
|
kill sys call (``Verursachung'')
|
sig.c
|
3966
|
13.13
|
psignal() (Internals vom kill() sys call)
|
sig.c
|
3991, 4043
|
13.3, 13.8, 13.14, 13.15
|
issig() prueft ob ein Signal vorhanden ist und behandelt werden muss.
(Wird z.B. von clock(), also bei jedem Tick, aufgerufen.)
psig() fuehrt dann den definierten Signalhandler aus. (``Effekt'')
|
|
| |
|