0% found this document useful (0 votes)
14 views

lecture03

Uploaded by

gabriel44992
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

lecture03

Uploaded by

gabriel44992
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Section 1 of the manual covers the general commands.

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

Inside a POSIX compliant system, strerror(3) and perror(3) are used in


order to lookup constant error values and their meaning.

$# Stores the number of command-line arguments that


were passed to the shell program.
$? Stores the exit value of the last command that was
executed.
$0 Stores the first word of the entered command (the
name of the shell program).
$* Stores all the arguments that were entered on the
command line ($1 $2 ...).
"$@" Stores all the arguments that were entered
on the command line, individually quoted ("$1" "$2" ...).

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

find /usr/src/usr.bin -name '*.[ch]' -print | xargs cat | wc -l => count


the number of lines in files ending in .c or .h, optimized, because it
calls cat alot less (only once instead of for each file).

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

You might also like