lecture03
lecture03
Sometimes,
utilities with the same name as library calls exist (e.g. printf), if not
specified,
man will bring up this section.
[System calls] are entry points into kernel code where theur functions are
implemented. They are documented in the section 2 of the manual pages.
(e.g. write(2)).
[Library calls] are transfers to user code which performs the desired
functions. They are documented in the section 3 of the manual pages.
(e.g. printf(3)).
Amongst other things, the sections of the manual pages are described in
the POSIX - Portable Operating System Interface (a standard which
defines the API, command line utilities, and interfaces for software
compatibility with variants of unix).
--Error handling--
errno variable
It is not good practice to call exit() with arbitrary values. See man
sysexits, (#include <sysexits.h>).
Unix philosophy:
Unix programs...
- are simple
- follow the element of least surprise
- accept input from STDIN
- generate output to STDOUT
- generate meaningful error messages to STDERR
- have meaningful exit codes
- have a man page
--File System--
The Unix filesystem is a tree structure with all partitions mounted
under the root (/).
All directories are special files that contain mappings between inodes
and filenames, called directory entries.
All processes have a current working directory which all relative paths
are specified. (Absolute paths start with a slash, relative paths do
not.)
find /usr/src/usr.bin/ -name '*.[ch]' -exec cat {} \; | wc -l => count the number
of lines in files ending in .c or .h
The kernel only provides UNBUFFERD I/O trough e.g. open(2), read(2),
write(2), lseek(2), close(2).
--Notes--
The first cat code example used unbufferd IO, the second one used
bufferd IO, behaviour is exactly the same, altough I expect it to be
faster while using bufferd IO.
--Homework--
- setup git repo for notes
- read intro(2) and intro(7)
- read chapters 1, 2 and 3 in Stevens as well as the linked chapter on UNIX
history and basics as you review Week1