Systems Programming Welcome all! Visiting Card . . . some more ...
Systems Programming Welcome all! Visiting Card . . . some more ...
Systems Programming Welcome all! Visiting Card . . . some more ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Welcome</strong> <strong>all</strong>!<br />
<strong>Systems</strong> <strong>Programming</strong><br />
00. Introduction<br />
Alexander Holupirek<br />
Database and Information <strong>Systems</strong> Group<br />
Department of Computer & Information Science<br />
University of Konstanz<br />
Summer Term 2008<br />
c○ 1995 United Feature Syndicate, Inc. (NYC), scottadams@aol.com<br />
<strong>Visiting</strong> <strong>Card</strong><br />
. . . <strong>some</strong> <strong>more</strong> details<br />
Alexander Holupirek<br />
alexander.holupirek@uni-konstanz.de<br />
http://www.inf.uni-konstanz.de/~holupire<br />
¨ 88 4440 E 217<br />
◮ E-mail is the best way to reach me.<br />
◮ You are welcome in my office whenever you have a question<br />
(no need to make to make an appointment first).<br />
Database and Information <strong>Systems</strong> Group (DBIS)<br />
Wissenschaftlicher Angestellter (since 08/2006)<br />
Prof. Marc H. Scholl<br />
http://www.inf.uni-konstanz.de/dbis<br />
Studies: Bachelor & Master IE<br />
Private: married, 3 kids
Your Tutors<br />
Organizational Matters<br />
Jochen Oekonomopulos<br />
jochen.oekonomopulos@uni-konstanz.de<br />
Enrolled in master studies Information Engineering<br />
Thomas Zink<br />
thomas.zink@uni-konstanz.de<br />
Enrolled in master studies Information Engineering<br />
Website for this course<br />
◮ Please check this site regulary for latest information.<br />
http://www.inf.uni-konstanz.de/dbis/teaching/ss08/sys/<br />
Schedule (OK for everybody?)<br />
◮ Monday, 18:00-19:30, Room C 252<br />
◮ Tuesday, 18:00-19:30, Room D 247/Computer Pool<br />
How you will benefit most from this course<br />
How you will benefit most from this course (cont.)<br />
Assignments & Tutorials<br />
◮ Work on the weekly assignments (pass > 80%).<br />
◮ Hand them in on time.<br />
◮ Jochen and Thomas will revise them.<br />
◮ Attend the tutorials and discussion of solutions.<br />
◮ Tuesday, 18:00-19:30, Room D 247/Computer Pool<br />
Lecture Material<br />
◮ Use the material provided on the course website to prepare for<br />
the lectures.<br />
◮ Don’t hesitate to ask questions.<br />
◮ Let me know if I can improve the lecture material and/or its<br />
presentation
How you will benefit most from this course (cont.)<br />
How you will benefit most from this course (cont.)<br />
Account & Mailinglist<br />
◮ Use the “Account Tool” to register to the course<br />
◮ You will automagic<strong>all</strong>y become a member on the mailinglist<br />
sys S08@inf.uni-konstanz.de<br />
◮ Feel free to post and discuss problems, questions, comments<br />
on that list.<br />
◮ Make sure to receive the e-mails 1<br />
◮ Any information about changes etc. will be posted there.<br />
Examination and Credits<br />
◮ Pass the examination at the end of the semester<br />
◮ Examination date: July, 15th (pending)<br />
◮ 6 ECTS, Angewandte Informatik<br />
Have fun!<br />
1 These are sent to @inf.uni-konstanz.de<br />
Literature<br />
Literature<br />
The IEEE and The Open Group.<br />
Single UNIX Specification, Version 3, 2004 Edition.<br />
http://www.unix.org/single unix specification/<br />
Brian W. Kernighan, Dennis M. Ritchie.<br />
The C <strong>Programming</strong> Language.<br />
ISBN 0-13-110370-9, 1988, 41th Printing.<br />
Prentice H<strong>all</strong> Software Series<br />
W. Richard Stevens, Stephen A. Rago.<br />
Advanced <strong>Programming</strong> in the UNIX R○ Environment.<br />
ISBN 978-0201433074<br />
Addison-Wesley Professional; 2nd edition (June 27, 2005)
What is this course about?<br />
The UNIX System Interface<br />
<strong>Systems</strong> <strong>Programming</strong><br />
◮ With systems we mean operating systems<br />
◮ With programming we mean using the interface an operating<br />
system (OS) provides<br />
◮ With OS we mean UNIX-like OSs<br />
Operating System<br />
◮ Layer of software on top of bare hardware<br />
◮ Shields programmers from the complexity of the hardware<br />
◮ Presents an interface (of a virtual machine) that is easier to<br />
understand and program<br />
The UNIX operating system provides its services through a set of<br />
system c<strong>all</strong>s, which are in effect functions within the operating<br />
system that may be c<strong>all</strong>ed by user programs.<br />
◮ Sysc<strong>all</strong>s determine a direct interface to the kernel<br />
◮ Employed for maximum efficiency<br />
◮ Access <strong>some</strong> facility that is not the libraries<br />
◮ The service c<strong>all</strong>s available in the interface vary from OS to<br />
OS, however the underlying concepts tend to be similar<br />
◮ ANSI C library is (in many cases) modeled on UNIX facilities<br />
Standardization of the UNIX System Interface<br />
During the 1980s the proliferation of UNIX versions and differences<br />
between them led many large users (such as the U.S. government)<br />
to c<strong>all</strong> for standardization.<br />
◮ Among others ANSI 2 C and the IEEE 3 POSIX emerged<br />
◮ POSIX stands for Portable Operating System Interface<br />
◮ POSIX refers to a family of related standards 4<br />
◮ POSIX origin<strong>all</strong>y used as synonym for IEEE Std 1003.1-1988<br />
◮ POSIX.1 emerged as a preferred term<br />
◮ The latest version of POSIX.1 was published on April 30th 04<br />
◮ It is c<strong>all</strong>ed IEEE Std 1003.1, 2004 Edition (POSIX.1)<br />
<strong>Systems</strong> <strong>Programming</strong> with POSIX.1<br />
application using the API<br />
POSIX.1 system c<strong>all</strong> interface<br />
OS as “Black Box”<br />
Figure: POSIX.1 as interface to UNIX OSs<br />
2 American National Standards Institute<br />
3 Institute of Electrical and Electronics Engineers<br />
4 IEEE Std 1003.n (where n is a number) and the parts of ISO/IEC 9945
<strong>Systems</strong> vs. Kernel <strong>Programming</strong><br />
.<br />
◮ Black Box Modell is suitable for systems programming<br />
◮ Knowledge about the system’s internals, however, is beneficial<br />
to use the system properly and to not work against it<br />
◮ Providing the system services is (mostly) kernel programming<br />
The joint standard<br />
The latest version POSIX.1 has been jointly developed by the IEEE<br />
and The Open Group 5 . As such it is both an IEEE and an Open<br />
Group Technical Standard:<br />
application using the API<br />
POSIX.1 system c<strong>all</strong> interface<br />
application using the API<br />
POSIX.1 system c<strong>all</strong> interface<br />
◮ IEEE Std 1003.1, 2004 Edition<br />
◮ The Open Group Technical Standard Base Specifications, Issue 6<br />
◮ It is also an international standard ISO/IEC 9945:2003<br />
OS as “Black Box”<br />
OS kernel<br />
Figure: Black vs. White Box View of a UNIX System<br />
5 http://www.opengroup.org/overview/members/membership list.htm<br />
The Single UNIX Specification, Version 3<br />
The Single UNIX Specification (SUSv3)<br />
The standard is published free of charge on the web 6 as<br />
The Single UNIX Specification, Version 3, 2004 Edition<br />
Conceptu<strong>all</strong>y, this standard describes a set of<br />
fundamental services needed for the efficient construction<br />
of application programs. Access to these services has<br />
been provided by defining an interface, using the C<br />
programming language, a command interpreter, and<br />
common utility programs that establish standard<br />
semantics and syntax.<br />
[IEEE/The Open Group, 2004, Preface]<br />
The document is broken into four parts:<br />
◮ Part 1: Base Definitions (XBD)<br />
◮ Part 2: System Interfaces (XSH)<br />
◮ Part 3: Shell and Utilities (XCU)<br />
◮ Part 4: Rationale<br />
The System Interfaces volume (XSH) 7 describes a set of system<br />
interfaces offered to application programs by systems conformant<br />
to this part of the Single UNIX Specification. Readers are expected<br />
to be experienced C language programmers.<br />
http://www.opengroup.org/onlinepubs/009695399/functions/contents.html<br />
6 http://www.unix.org/single unix specification/<br />
7 http://www.unix.org/version3/xsh contents.html
Part 2: System Interfaces Volume (XSH)<br />
UNIX Architecture<br />
applications<br />
Because POSIX.1 specifies an interface and not an implementation,<br />
no distinction is made between system c<strong>all</strong>s and library functions.<br />
Example<br />
System Interface Table. Lists 1123 interfaces.<br />
http://www.opengroup.org/onlinepubs/009695399/functions/atoi.html<br />
http://www.opengroup.org/onlinepubs/009695399/functions/read.html<br />
shell<br />
system c<strong>all</strong>s<br />
kernel<br />
library routines<br />
System C<strong>all</strong>s - Section 2<br />
System C<strong>all</strong>s - Section 2<br />
The system c<strong>all</strong> interface has tradition<strong>all</strong>y been documented in<br />
Section 2 of the UNIX Programmer’s Manual.<br />
1 General commands (tools and utilities).<br />
2 System c<strong>all</strong>s and error numbers.<br />
3 Libraries.<br />
3p perl(1) programmer’s reference guide.<br />
4 Device drivers.<br />
5 File formats.<br />
6 Games.<br />
7 Miscellaneous.<br />
8 System maintenance and operation commands.<br />
9 Kernel internals.<br />
X11 An alias for X11R6.<br />
X11R6 X Window System.<br />
local Pages located in /usr/local.<br />
man(1) on OpenBSD<br />
The system c<strong>all</strong> interface has tradition<strong>all</strong>y been documented in<br />
Section 2 of the UNIX Programmer’s Manual.<br />
0 Header files (usu<strong>all</strong>y found in /usr/include)<br />
1 Executable programs or shell commands<br />
2 System c<strong>all</strong>s (functions provided by the kernel)<br />
3 Library c<strong>all</strong>s (functions within program libraries)<br />
4 Special files (usu<strong>all</strong>y found in /dev)<br />
5 File formats and conventions eg /etc/passwd<br />
6 Games<br />
7 Miscellaneous (including macro packages and<br />
conventions), e.g. man(7), groff(7)<br />
8 System administration commands (usu<strong>all</strong>y only for root)<br />
9 Kernel routines [Non standard]<br />
man(1) on Linux
System C<strong>all</strong> Definition & C library functions<br />
Library C<strong>all</strong>s - Section 3<br />
◮ Definition of the system c<strong>all</strong> interface is in the C language 8<br />
◮ A standard technique on UNIX systems is for each system c<strong>all</strong><br />
to have a function of the same name in the Standard C Library<br />
◮ Those functions invoke the apt kernel service, using whatever<br />
technique is required on the system<br />
◮ The function may put one or <strong>more</strong> of the C arguments into<br />
general registers and then execute <strong>some</strong> machine instruction<br />
that generates a software interrupt in the kernel<br />
◮ We can consider the system c<strong>all</strong>s as being C functions<br />
◮ Section 3 of the UNIX Programmer’s Manual defines the<br />
general purpose functions available to the programmers<br />
◮ These functions are not entry points into the kernel<br />
◮ May use kernel’s system c<strong>all</strong>s, however<br />
◮ printf(3) may invoke write(2) to perform output<br />
◮ atoi(3) (convert ASCII string to integer) no OS at <strong>all</strong><br />
◮ Implementor’s view (kernel programming): Distinction<br />
between system c<strong>all</strong> vs. library function is fundamental<br />
◮ User’s perspective (systems programming): Not as critical,<br />
both exist to provide services for application programs, but . . .<br />
8 Regardless of the actual implementation technique used to invoke a c<strong>all</strong><br />
System C<strong>all</strong>s vs. Library C<strong>all</strong>s<br />
Essentials<br />
Example to illustrate the difference: current time and date<br />
◮ Some OS have sysc<strong>all</strong>s to return the time and another to<br />
return the date. Special handling (switch to or from daylight<br />
saving) is handled by the kernel or requires human intervention<br />
◮ UNIX provides one sysc<strong>all</strong> (gettimeofday(2)) that returns<br />
the number of seconds since the Epoch 9<br />
◮ Any interpretation (local time zone, converting to<br />
human-readable time) is left to the user process<br />
◮ Sysc<strong>all</strong>s usu<strong>all</strong>y provide a minimal interface while library<br />
functions often provide <strong>more</strong> elaborate functionality<br />
◮ Good knowledge of C<br />
◮ Knowledge about the services an OS provides<br />
◮ system c<strong>all</strong>s<br />
◮ C libraries<br />
◮ Some knowledge about kernel’s internas<br />
◮ Some knowledge about operating system concepts<br />
◮ Some knowledge about the underlying hardware<br />
9 midnight, January 1, 1970, Coordinated Universal Time