Skip navigation.

Eleanor

computer information, linux, optimization ...

GNU and UNIX commands

COMMAND LINE
- the bash shell is one of several shells available for linux
- shell is a program that executes commands (many commands on linux system are scripts)
- shells use standard I/O streams (stdin,strout,strerr)
- if a line contains a # character, then all remaining characters on the line are ignored
[ian@echidna ian]$ echo -n No new line
No new line[ian@echidna ian]$ echo -e "No new line\c"
No new line[ian@echidna ian]$ echo "A line with a typed
> return"
A line with a typed
return
[ian@echidna ian]$ echo -e "A line with an escaped\nreturn"
A line with an escaped
return
[ian@echidna ian]$ echo "A line with an escaped\nreturn but no -e option"
A line with an escaped\nreturn but no -e option
[ian@echidna ian]$ echo -e Doubly escaped\\n\\tmetacharacters
Doubly escaped
        metacharacters
[ian@echidna ian]$ echo Backslash \
> followed by newline \
> serves as line continuation.
Backslash followed by newline serves as line continuation.

- bash displays a special prompt (>) when you type a line with unmatched quotes


- bash has several metacharacters: besides a blank, these are '|', '&', ';', '(', ')', '<', and '>'
- if you want to include it in part of your text it must be quoted or escaped using a baskslash

[ian@echidna ian]$ echo line 1;echo line 2; echo line 3
line 1
line 2
line 3
[ian@echidna ian]$ echo line 1&&echo line 2&&echo line 3
line 1
line 2
line 3
[ian@echidna ian]$ echo line 1||echo line 2; echo line 3
line 1
line 3

- && se izvede samo, ce je prvi ukaz uspesno zakljucil
- || se izvede samo, ce je prvi ukaz neuspesno zakljucil

- you can terminate a shell using "exit" command (if running a window, the window will close)


ENVIRONMENT VARIABLES
- when you are running in a bash shell, many things constitute your environment (form or your prompt...)
- your environment includes many variables that may have been set by bash or by you
- bash shell also allows you to have shell variables, which you may export to your environment

- some of the common variables are:
USER  The name of the logged-in user
  UID  The numeric user id of the logged-in user
  HOME  The user's home directory
  PWD  The current working directory
  SHELL  The name of the shell
  $  The process id (or PIDof the running bash shell (or other) process
  PPID  The process id of the process that started this process (that is, the id of the parent process)
  ?  The exit code of the last command

- variables are case sensitive
- when you create a shell variable, you want to export it to the environment so it will be available to other processes that you start from this shell (variables that you export are not available to a prent shell)

- there is a difference between single and double quotes
- The shell expands shell variables that are between double quotes ($quot;), but expansion is not done when single quotes (') are used.
[ian@echidna ian]$ echo "$SHELL" '$SHELL' "$$" '$$'
/bin/bash $SHELL 19244 $$


ENV
- the env command displays the current environment variables
- the -i option clears the current environment before running the command, while the -u option usets variables that you do not want to pass
- you can use unset command to unset a variable and remove it from the shell variable list

EXEC
- exec command runs another program that replaces the current shell

[ian@echidna ian]$ echo $$
22985
[ian@echidna ian]$ bash
[ian@echidna ian]$ echo $$
25063
[ian@echidna ian]$ exec ksh
$ echo $$
25063
$ exit
[ian@echidna ian]$ echo $$
22985

- starts a child bash shell and then uses exec to replace it with a Korn shell. Upon exit from the Korn shell, you are back at the original bash shell (PID 22985, in this example).

COMMAND HISTORY
- If you are typing in commands as you read, you may notice that you often use a command many times, either exactly the same, or with slight changes.
- The good news is that the bash shell can maintain a history of your commands. By default, history is on
- You can turn it off using the command set +o history and turn it back on using set -o history
- an envoronment variable HISTSIZE tells bash how many history lines to keep

- some of the commands that you can use with the history facility are:
history
Displays the entire history
history N 
Displays the last N lines of your history
history -d N 
Deletes line N form your history; you might do this if the line contains a password, for example
!!
Your most recent command
!N 
The Nth history command
!-N 
The command that is N commands back in the history (!-1 is equivalent to !!)
!#
The current command you are typing
!string 
The most recent command that starts with string 
!?string?
The most recent command that containsstring


- By default, the keys and key combinations used to move through the history or edit lines are similar to those used in the GNU Emacs editor. Emacs keystroke combinations are usually expressed as C-x or M-x, where x is a regular key and C and M are the Control and Meta keys, respectively. On a typical PC system, the Ctrl key serves as the Emacs Control key, and the Alt key serves as the Meta key.
- history editing:
C-f  Right arrow  Move one space to the right
  C-b  Left arrow  Move one space to the left
  M-f  Alt-f  Move to beginning of next word; GUI environments usually take this key combination to open the File menu of the window
  M-b  Alt-b  Move to beginning of previous word
  C-a  Home  Move to beginning of line
  C-e  End  Move to end of line
  Backspace  Backspace  Delete the character preceding the cursor
  C-d  Del  Delete the character under the cursor (Del and Backspace functions may be configured with opposite meanings)
  C-k  Ctrl-k  Delete (kill) to end of line and save removed text for later use
  M-d  Alt-d  Delete (kill) to end of word and save removed text for later use
  C-y  Ctrl-y  Yank back text removed with a kill command

- If you prefer to manipulate the history using a vi-like editing mode, use the command set -o vi to switch to vi mode. Switch back to emacs mode using set -o emacs.


PATHS
- where does the shell find commands?
- if you type a command name, then bash looks for that command on your PATH variable, which is a colon separated list
- If you want to know what command will be executed if you type a particular string, use the which or type command

- Try running dircolors --print-database to see how the color codings are controlled and which colors are used for what kind of file.

- If you use cd with no parameters, the change will be to your home directory. A single hyphen (-) as a parameter means to change to the previous working directory.
- Your home directory is stored in the HOME environment variable, and the previous directory is stored in the OLDPWD variable, so cd alone is equivalent to cd $HOME and cd - is equivalent to cd $OLDPWD


Command substitution
- The bash shell has an extremely powerful capability that allows the results of one command to be used as input to another; this is called command substitution. This can be done by enclosing the command whose results you wish to use in backticks (`). This is still common, but a way that is easier to use with multiply nested commands is to enclose the command between $( and ).
- this shows an example of how to get the absolute path of a directory from a relative path, how to find which RPM provides the /bin/echo command, and how (as root) to list the labels of three partitions on a hard drive. The last one uses the seq command to generate a sequence of integers.

[ian@echidna ian]$ echo '../../usr/bin' dir is $(cd ../../usr/bin;pwd)
../../usr/bin dir is /usr/bin
[ian@echidna ian]$ which echo
/bin/echo
[ian@echidna ian]$ rpm -qf `which echo`
sh-utils-2.0.12-3
[ian@echidna ian]$ su -
Password:
[root@echidna root]# for n in $(seq 7 9); do echo p$n `e2label /dev/hda$n`;done
p7 RH73
p8 SUSE81
p9 IMAGES


MAN
- The primary (and traditional) source of documentation is the manual pages, which you can access using the man command.
- Two important commands related to man are whatis and apropos. The whatis command searches man pages for the name you give and displays the name information from the appropriate manual pages. The apropos command does a keyword search of manual pages and lists ones containing your keyword.

[ian@lyrebird ian]$ whatis man
man                  (1)  - format and display the on-line manual pages
man                  (7)  - macros to format man pages
man [manpath]        (1)  - format and display the on-line manual pages
man.conf [man]       (5)  - configuration data for man
[ian@lyrebird ian]$ whatis mkdir
mkdir                (1)  - make directories
mkdir                (2)  - create a directory
[ian@lyrebird ian]$ apropos mkdir
mkdir                (1)  - make directories
mkdir                (2)  - create a directory
mkdirhier            (1x)  - makes a directory hierarchy



Text streams and filters
- Text filtering is the process of taking an input stream of text and performing some conversion on the text before sending it to an output stream.
- Although either the input or the output can come from a file, in the Linux and UNIX environments, filtering is most often done by constructing a pipeline of commands where the output from one command is piped or redirected to be used as input to the next

Piping with |
- shell use 3 standard I/O streams: stdin,stdout,stderr

piping output from command1 to input of command2
command1 | command2
- either command may have options and arguments

Output redirection with >
- While it is nice to be able to create a pipeline of several commands and see the output on your terminal, there are times when you want to save the output in a file. You do this with the output redirection operator (>).

Cat, tac, od, and split
- displaying contents with cat
[ian@echidna lpi103]$ cat text1
1 apple
2 pear
3 banana

- creating a text file with cat
[ian@echidna lpi103]$ cat>text2
9       plum
3       banana
10      apple

- in this case cat keep reading from stdin

Occasionally, you might want to display a file in reverse order. Naturally, there is a text filter for that too, called tac (reverse of cat).

- Now, suppose you display the two text files using cat or tac and notice alignment differences. To learn what causes this, you need to look at the control characters that are in the file. Since these are acted upon in text display output rather than having some representation of the control character itself displayed, we need to dump the file in a format that allows you to find and interpret these special characters. The GNU text utilities include an od (or Octal Dump) command for this purpose.
- There are several options to od, such as the -A option to control the radix of the file offsets and -t to control the form of the displayed file contents. The radix may be specified as o, (octal - the default), d (decimal), x (hexadecimal), or n (no offsets displayed). You can display output as octal, hex, decimal, floating point, ASCII with backslash escapes or named characters (nl for newline, ht for horizontal tab, etc.).

bash-3.1# od test
0000000 060553 067553 071440 005151 060553 005152 060544 062556
0000020 005163
0000022
bash-3.1# od -A d -t c test
0000000   k   a   k   o       s   i  \n   k   a   j  \n   d   a   n   e
0000016   s  \n
0000018

- The -A option of cat provides an alternate way of seeing where your tabs and line endings are.

- Our sample files are very small, but sometimes you will have large files that you need to split into smaller pieces. For example, you might want to break a large file into CD-sized chunks so you can write it to CD for sending through the mail to someone who could create a DVD for you. The split command will do this in such a way that the cat command can be used to recreate the file easily. By default, the files resulting from the split command have a prefix in their name of 'x' followed by a suffix of 'aa', 'ab', 'ac', ..., 'ba', 'bb', etc. Options permit you to change these defaults. You can also control the size of the output files and whether the resulting files contain whole lines or just byte counts

bash-3.1# split -l 2 test
bash-3.1# ls
test  xaa  xab  xorg.conf.new
bash-3.1# cat xaa
kako si
kaj
bash-3.1# cat xab
danes
bash-3.1# cat x*
kako si
kaj
danes


Wc, head, and tail
- wc (word count) command - to see how big the file is (it displays the number of lines, words and bytes in a file)
- you can also find the number of bytes using ls -l
- Two commands allow you to display either the first part (head) or last part (tail). These commands are the head and tail commands. They can be used as filters,or they can take a file name as an augument. By default they display the first (or last) 10 lines of the file or stream
- you ca use:
----> dmesg | tail
----> dmesg | head
----> dmesg | wc

Expand, unexpand, and tr
- sometimes in your files you want to swap tabs for spaces or vice versa. The expand and unexpand commands do this.
- expand: Convert tabs in each FILE to spaces, writing to standard output
- unexpand: convert spaces in FILE to tabs (requires at least 2 spaces to convert to tab)
- tr: Translate, squeeze, and/or delete characters from standard input

bash-3.1# cat test
kako si         kaj
danes
bash-3.1# expand -t 1 test
kako si  kaj
danes
bash-3.1# expand -t 2 test
bash-3.1# unexpand  test
kako si         kaj
  danes
bash-3.1# unexpand -t 1 test
kako si         kaj
                danes
bash-3.1#



Pr, nl, and fmt
- pr: format file for printing (the default header includes the file name and the dile creation date and time along with page number and two lines of blank footer)
-nl: numbers lines (cat -n would do the same)
- fmt: formats text so it fits within margins (you can join several short lines as well as split long ones)

Sort and uniq
- sort: sorts the input using the collating sequence for the locale (LC_COLLATE). It can also merge already sorted files and check wheter a file is sorted or not
- uniq: removes the identical lines from any file

Cut, paste, and join
- cut: extracts fields from text files (the default field delimiter is the tab character)
- paste: pastes lines from two or more files side-by-side
- join: joins file based on a matching field

SED
- is a stream editor (can work as a filter, can take its input from a file...)
- sed has many commands

bash-3.1# cat test
kako si
kaaj
daneaaas
bash-3.1# sed 's/a/A/' test
kAko si
kAaj
dAneaaas
bash-3.1# sed 's/a/A/g' test
kAko si
kAAj
dAneAAAs
bash-3.1# sed '2d;$s/a/A/g' test
kako si
dAneAAAs

- in the first example we use s(substitute) command to substitute an upper case for lowe case on each line. This replaces only the first a, so in the second example we add the g(global) falg to cause sed to chande all occurances
- In the third script, we introduce the d (delete) command to delete a line. In our example, we use an address of 2 to indicate that only line 2 should be deleted. We separate commands using a semi-colon (:wink:

- in addition to operating on individual lines, sed can operate on a range of lines.
- The beginning and end of the range are separated by a comma (,) and may be specified as a line number, a caret (^) for beginning of file, or a dollar sign ($) for end of file. Given an address or a range of addresses, you can group several commands between curly braces ({ and }) to have these commands operate only on lines selected by the range.
- -e option to add commands to the pattern space. When using braces, we must separate commands in this way.

[ian@echidna lpi103]$ sed -e '2,${' -e 's/a/A/g' -e '}' text1
1 apple
2 peAr
3 bAnAnA
[ian@echidna lpi103]$ sed -e '/pear/,/bana/{' -e 's/a/A/g' -e '}' text1
1 apple
2 peAr
3 bAnAnA


Listing details
- On a storage device, a file or directory is contained in a collection of blocks. Information about a file is contained in an inode which records information such as the owner, when the file was last accessed, how large it is, whether it is a directory or not, and who can read or write it. The inode number is also known as the file serial number and is unique within a particular filesystem.

-rw-rw-r-- 1 root root 22 Jul 24 19:26 test

- the second value (1) is a number which tells us the number of hard links to the file. We said that the inode contains information about the file. The file's directory entry contains a hard link (or pointer) to the inode for the file, so every entry listed should have at least one hard link. Directory entries have an additional one for the . entry and one for each subdirectory's .. entry
- The -i option of the ls command will display the inode numbers for you.

Wildcards and globbing
- a string containing any of the characters '?', '*' or '[', is a wildcard pattern. Globbing is the process by which the shell (or possibly another program) expands these patterns into a list of pathnames matching the pattern. The matching is done as follows.

?
matches any single character.
*
matches any string, including an empty string.
[
introduces a character class. A character class is a non-empty string, terminated by a ']'. A match means matching any single character enclosed by the brackets. There are a few special considerations.

- The '-' character between two others represents a range which includes the two other characters and all between in the collating sequence. For example, [0-9a-fA-F] represents any upper or lower case hexadecimal digit. You can match a '-' by putting it either first or last within a range.
- The '!' character specified as the first character of a range complements the range so that it matches any character except the remaining characters. For example [!0-9] means any character except the digits 0 through 9

- Globbing is applied separately to each component of a path name. You cannot match a '/', nor include one in a range.

sh-3.1$ touch text1       text2       text3  text5
sh-3.1$ ls text[2-4]
text2  text3


TOUCHING FILES
- touch: can update file access and modification times or create empty files
- The touch command with no options takes one or more filenames as parameters and updates the modification time of the files.
sh-3.1$ echo "pojdi spat">file; ls -l file ;sleep 60; touch file ; ls -l file
-rw-rw-r-- 1 eleanor eleanor 11 Jul 24 20:58 file
-rw-rw-r-- 1 eleanor eleanor 11 Jul 24 20:59 file

- if you specify a filename that does not exist, then touch will normally create an empty file unless you use -c option (then it will not create that file)
- you can also set a files mtime to a specific date and time using -d or -t option. The -d is very flexible in the date and time formats that it will accept, while the -t option needs at least an MMDDhhmm time with optional year and seconds values (date command resolves the same kind of date formats than touch can)

Finding files
- it will search for files using all or part of the name, or by other search criteria: size, type, owner, creation date...
find . -name "*[1k]*"

- search in current directory where for all files that have either a '1' or a 'k' in their name
- If you want to find a file or directory whose name begins with a dot, such as .bashrc or the current directory (.), then you must specify a leading dot as part of the pattern.
- Use the -type parameter along with one-letter type to restrict the search. Use 'f' for regular files, 'd' for directories, and 'l' for symbolic links.
find . -type d

- We can also search by file size, either for a specific size (n) or for files that are either larger (+n) or smaller than a given value (-n). By using both upper and lower size bounds, we can find files whose size is within a given range.
find . -size -26c -size +23c -print

- -print option which is an example of an action that may be taken on the results returned by the search. In the bash shell, this is the default action if no action is specified. On some systems and some shells, an action is required, otherwise there is no output.
- Other actions include -ls which prints file information equivalent to that from the ls -lids command, or -exec which executes a command for each file. The -exec must be terminated by a semi-colon which must be escaped to avoid the shell interpreting it first. Also specify {} wherever you want the returned file used in the command

find . -size -26c -size +23c -ls
find . -size -26c -size +23c -exec ls -l '{}' \;
//this removes all the files in a directory tree
find . -empty -exec rm '{}' \; 
//this renames all .htm files to .html files
find . -name "*.htm" -exec mv '{}' '{}l' \;


- When used with -mtime -2, the find command finds all files modified within the last two days. A day in this case is a 24-hour period relative to the current date and time. Note that you would use -atime if you wanted to find files based on access time rather than modification time.


Streams, pipes, and redirects
-

QT

HELLO QT

1 #include <QApplication> 
2 #include <QLabel> 
3 int main(int argc, char *argv[]) 
4 { 
5     QApplication app(argc, argv); 
6     QLabel *label = new QLabel("Hello Qt!"); 
7     label->show(); 
8     return app.exec(); 
9 }


5 -> creates a QApplication object to manage application-wide resources (it requires argc and argv, because it supports a few command-line arguments of it's own)
- widget is visual element in a user interface (most of the Apps use the QMainWindow or QDialog for the application window, but any widget can be a window)

7 -> makes a label visible.
- widgets are always created hidden, so we can customize them before showing them (to avoid flicker)

8 -> passes control of the application on to Qt (program enters an event loop -> program waits for user actions such as mouse clicks and key presses)
- here we don't call delete on Qlabel since it's a small program (the memory will be reclaimed by the OS when the program terminates)

COMPILING THE PROGRAM

qmake -project
-> to make platform-independent project file (*.pro)

qmake
-> to create platform specific makefile from project file

make
-> to build the program


MAKING CONNECTIONS

 1 #include <QApplication>  2 #include <QPushButton> 
 3 int main(int argc, char *argv[]) 
 4 { 
 5     QApplication app(argc, argv); 
 6     QPushButton *button = new QPushButton("Quit"); 
 7     QObject::connect(button, SIGNAL(clicked()), 
 8                      &app, SLOT(quit())); 
 9     button->show(); 
10     return app.exec(); 
11 } 


- Qt's widgets emit signals to indicate that a user action has occured (QPushButton emits a clicked() signal when the user clicks the button)
- a signal can be connected to a slot (so when a signal is emitted the slot is automatically executed)

LAYING OUT WIDGETS

 1 #include <QApplication>  
 2 #include <QHBoxLayout> 
 3 #include <QSlider> 
 4 #include <QSpinBox> 
 5 int main(int argc, char *argv[]) 
 6 { 
 7     QApplication app(argc, argv); 
 8     QWidget *window = new QWidget; 
 9     window->setWindowTitle("Enter Your Age"); 
10     QSpinBox *spinBox = new QSpinBox; 
11     QSlider *slider = new QSlider(Qt::Horizontal); 
12     spinBox->setRange(0, 130); 
13     slider->setRange(0, 130); 
14     QObject::connect(spinBox, SIGNAL(valueChanged(int)), 
15                      slider, SLOT(setValue(int))); 
16     QObject::connect(slider, SIGNAL(valueChanged(int)), 
17                      spinBox, SLOT(setValue(int))); 
18     spinBox->setValue(35); 
19     QHBoxLayout *layout = new QHBoxLayout; 
20     layout->addWidget(spinBox); 
21     layout->addWidget(slider); 
22     window->setLayout(layout); 
23     window->show(); 
24     return app.exec(); 
25 } 


- QWidget serves as the application's main window (it's a top level window)

QHBoxLayout -> horizontally from left to right
QVBoxLayout -> vertically from top to bottom
QGridLayout -> in a grid

- QWidget::setLayout() installs the layout manager on the window
- behind the scenes the QSpinBox and QSlider are reparented to be children of the widget on which layout is installed
- layouts automatically take care of sizing and positioning


SUBCLASSING QDIALOG


- #ifndef, #define, #endif protect header file against multiple inclusions
- QDialog inherits QWidget

- class QLabel; is a forward declarations of Qt (this tells the C++ compiler that a class exists, without giving all the detail that a class definition provides. This is possible because they are all pointers and we don't access them in the header file, so the compiler dosn't need the full class definitions...==> FASTER COMPILING)

class FindDialog : public QDialog { -> we define FindDialog as a subclass of QDialog

- Q_OBJECT macro at the beginning of the class definition is necessary for all classes that define signals and slots

FindDialog(QWidget *parent = 0);
-> the FindDialog constructor is typical Qt constructor. The parent parameter specifies the parent widget. The default is null pointer (so the dialog has no parent)

#include <QtGui>
- is a header file that contains the definitian of Qt's GUI classes (contains all the definitions of all the classes that are part od the QtCOre and QtGui modules ... it's a really big header file...slower compiling)

- In the string literals, we use ampersands ('&') to indicate shortcut keys.
- The tr() function calls around the string literals mark them for translation to other languages.
- it's a good habit to surround user-visible strings with tr(), even if you don't have immediate plans for translating

setDefault(true)
- the defautl widget that is pressed when we press enter

setEnables(false)
- so that widget is grayed out

- since QObject is one of the FindDialog's ancestors, we can omit the QObject:: prefix in front of the connect() calls


- layout manager classes are not widgets -> they inherit QLayout (which inherits QObject)
- in this figure, widgets are represented by solid outlines and layouts are represented by dashed outlines (so widgets are visible and layouts are invisible in application)

QWidget::sizeHint() returns a function's ideal size

- Qt automatically deletes child objects then the parent is destroyed

- if Qt inclused Q_OBJECT the Makefile generated by qmake will include special rules to run moc (qt's meta-object compiler)
- classes that use the Q_OBJECT macro must have moc run on them. This isn't the problem because qmake automatically adds the necessary rules to the makefile


QWIDGET
- QWidget class is the base class of all user interface objects
- every widget's constructor accepts one or two standars arguments
1) QWidget *parent = 0
- is the parent of the new widget
- if it is 0 (the default), the new widget will be a window
- if not, it will be a child of parent
2) Qt::WindowFlags f = 0
- set's the window flags
- the defalt is suitable for all widgets, but to get a window without a window system frame, you must use special flags


MAINWINDOW.H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>

class MainWindow : public QWidget {
  public:
MainWindow();
~MainWindow();
};
#endif


MAINWINDOW.CPP
#include "mainwindow.h"
#include <iostream.h>
#include <QWidget>

MainWindow::MainWindow() {
cout << "Kako si kaj danes\n";

}



MAIN.CPP
#include <QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[]) {
QApplication app(argc,argv);
MainWindow main;
main.show();
return app.exec();
}




QT DESIGNER

- design your programs more easily and quickly
- open "designer" and click widget
- now your window is "Untitled"

1) create child widgets and place them on the form
2) when done, save everything as something.ui
3) create main.cpp in same directory using a text editor
#include <QApplication> 
#include <QDialog> 
#include "ui_something.h" 
int main(int argc, char *argv[]) 
{ 
    QApplication app(argc, argv); 
    //Something is the objectName of the form (entire window)
    Ui::Something ui; 
    QDialog *dialog = new QDialog; 
    ui.setupUi(dialog); 
    dialog->show(); 
    return app.exec(); 
} 

4) run qmake -project && qmake -> qmake is smart enough to detect the user interface file something.ui and to generate the appropriate makefile rules to invoke uic (Qt's user interface compiler)
- the uic tool converts something.ui into c++ and puts the result in ui_something.h
- the generated ui_something.h contains the definition of the Ui::Something class, which is a c++ equivalent to the something.ui file
- the class declares member variables that store the form's child widgets and layouts and a setupUi() function that initializes the form
- generated class looks like this

class Ui::Something { 
public: 
    QLabel *label; 
    QLineEdit *lineEdit; 
    QSpacerItem *spacerItem; 
    QPushButton *okButton; 
    QPushButton *cancelButton; 
    ... 
    void setupUi(QWidget *widget) { 
        ... 
    } 
}; 

- the generated class doesn't inherit any Qt class. When we use the form in main.cpp, we create a QDialog and pass it to setupUi()


- if I want to add functionallity I must:
-> create a new class that inherits both QDialog and Ui::Something
-> let's give that class the same name as Ui::Something but without the Ui:: prefix

SOMETHING.H
#ifndef SOMETHING_H 
#define SOMETHING_H 
#include <QDialog> 
#include "ui_something.h" 
class GoToCellDialog : public QDialog, public Ui::Something 
{ 
    Q_OBJECT 
public: 
    Something(QWidget *parent = 0); 
private slots: 
    void on_lineEdit_textChanged(); 
}; 
#endif


SOMETHING.CPP
#include <QtGui> 
#include "something.h" 
Something::Something(QWidget *parent) : QDialog(parent) 
{ 
    setupUi(this); 
    QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}"); 
    lineEdit->setValidator(new QRegExpValidator(regExp, this)); 
    connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); 
    connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); 
} 
void Something::on_lineEdit_textChanged() 
{ 
    okButton->setEnabled(lineEdit->hasAcceptableInput()); 
} 

- in constructor we call setupUi() to initialize the form
- thanks to inheriance we can access the Ui::Something's memebers directly

- Qt's parentchild mechanism is implemented in QObject. When we create an object with a parent, the parent adds the object to the list of it's children. When the parent is deleted, it walks through it's list of children and deletes each child (the children then delete all of their children)
- this greatly simplifies the memory management and reduces the risk of memory leaks
- child widgets are shown within the parent's area

- we can now rewrite the main.cpp
#include <QApplication> 
#include "gotocelldialog.h" 
int main(int argc, char *argv[]) 
{ 
    QApplication app(argc, argv); 
    Something *dialog = new Something; 
    dialog->show(); 
    return app.exec(); 
}



THIS example
MainWindow::MainWindow() {
//ce bi tu napisal this.setTitle("Norec"); 
        //bi se skliceval na metodo setTitle, ki je definirana 
        //v razredu MainWIndow (kjer imam this se metoda sklicuje na razred v katerem jo imam)
setWindowTitle("DX-Ball");
}



SIGNALS AND SLOTS
- slots are identical to ordinary c++ member functions (can be virtual, overloaded, public, protected, private and their parameters can be of any type)

connect(sender,SIGNAL(signal()),receiver,SLOT(slot()));

- sender and receiver are pointers to QObjects

- one signal can be connected to many slots
- many signals can be connected to the same slot
- a signal canbe conncted to another signal
- connections can be removed with disconnect (Qt automatically removes all connections when object is deleted)
- if a signal has more parameters than the slot it is connected to, the additional parameters are simply ignored
- you can emit signals like: emit signal();




C++ summary

GENERAL INFORMATION

- a c++ program consist of .cpp file (or many of them) --> the compiler generates .obj or .o files from them (object file)
- the object file is a binary file that contains machine code for the architecture on which the program will run
- once all the .cpp files have been compiled we can combine the object files together to create an executable using a special program called the linker

SCHEME
[compiling] [linking]
program.cpp -------------> program.obj ---------------> program.exe

- when building a program, exactly one .cpp file must contain main() function that serves as the program's entry point. This function doesn't belong to any class...it's a global function

-> cout - standard output stream
-> cerr - standard error stream
-> endl - end of line marker

NAMESPACES

-> using namespace std;
------> tells the compiler that we want to import all identifiers declared in the std namespace into the global namespace

// namespaces
#include <iostream>
using namespace std;

namespace first
{
  int var = 5;
}

namespace second
{
  double var = 3.1416;
}

int main () {
  cout << first::var << endl;
  cout << second::var << endl;
  return 0;
}

- output is: 5 and 3.1416
- to access variables from outside the namespace use the ::
- In this case, there are two global variables with the same name: var. One is defined within the namespace first and the other one in second. No redefinition errors happen thanks to namespaces.
- keyword "using" is used to be able to access variables without namespace:: in from of it (using first::x == x)
- the keyword "using" can be also used to be able to access the entire namespace (using namespace std;)
- using and using namespace have validity only in the same block in which they are stated or in the entire code if they are used directly in the global scope.
- all the files in the standard c++ library(all iostream functions) is declared in std namespace (using namespace std;)


HEADER FILES
#ifndef SQUARE_H
#define SQUARE_H 
/*...*/ 
#endif 

- header files usually includes preprocessor directives (ensure that the header file is processed only once, even if the header file is included several times in the same .cpp file)


PREPROCESSOR DIRECTIVES
- are lines included in out program that are not program statements but directoves for the preprocessor (always begin with # and does not end with ; )
- the preprocessor is executed before the actuall compilation of code begins

MACRO DEFINITIONS
- to define processor macros use #define
#define identifier replacement
#define TABLE_SIZE 100
#define getmax(a,b) a>b?a:b

- when preprocessor encounters this directive it replaces any occurrence of identifier by replacement
- a macro lasts until it is undefined with the #undef preprocessor directive

CONDITIONAL INCLUSIONS
- these directives allow to include/discard part of the code of a program if a certain condition is met
- #ifdef allows a section of a program to be compiled only if the macro that is specified as the parameter has been defined, no matter which its value is
#ifdef TABLE_SIZE
int table[TABLE_SIZE];
#endif

- the second line is only compiled if #define TABLE_SIZE is present in the program (if it's not the line will not be included in the compilation)

- the code between #ifndef and #endif is only compiled if the specified identifier has not been previously defined


- the #if, #else and #elif (i.e., "else if") directives serve to specify some condition to be met in order for the portion of code they surround to be compiled.
#if TABLE_SIZE>200
#undef TABLE_SIZE
#define TABLE_SIZE 200
 
#elif TABLE_SIZE<50
#undef TABLE_SIZE
#define TABLE_SIZE 50
 
#else
#undef TABLE_SIZE
#define TABLE_SIZE 100
#endif
 
int table[TABLE_SIZE]; 



- #include
- this directive has also been used assiduously in other sections of this tutorial. When the preprocessor finds an #include directive it replaces it by the entire content of the specified file


PREDEFINED MACRO NAMES
- the following macro names are defined at any time
__LINE__  Integer value representing the current line in the source code file being compiled.
  __FILE__  A string literal containing the presumed name of the source file being compiled.
  __DATE__  A string literal in the form "Mmm dd yyyy" containing the date in which the compilation process began.
  __TIME__  A string literal in the form "hh:mm:ss" containing the time at which the compilation process began.
  __cplusplus  An integer value. All C++ compilers have this constant defined to some value. If the compiler is fully compliant with the C++ standard its value is equal or greater than 199711L depending on the version of the standard they comply.


// standard macro names
#include <iostream>
using namespace std;

int main()
{
  cout << "This is the line number " << __LINE__;
  cout << " of file " << __FILE__ << ".\n";
  cout << "Its compilation began " << __DATE__;
  cout << " at " << __TIME__ << ".\n";
  cout << "The compiler gives a __cplusplus value of " << __cplusplus;
  return 0;
}




(19:55:13) (B) Scott (B): so lets say you have some code that load a header file, ok
(19:55:42) (B) Scott (B): so the compiler see the ifndef and since this is the first time we read the file, the compiler reads the file
(19:56:10) (B) Scott (B): so the compiler learns the variables, function definitions, etc
(19:56:35) (B) Scott (B): then it sets that #define variable MYHEADER_H for example
(19:57:53) Eleanor: it sets MYHEADER_H to what?
(20:00:03) (B) Scott (B): #define MY_VARIABLE 100 means that before your code is compiled, all occurrences of MY_VARIABLE are replace by 100
(20:01:24) Eleanor: so what does the #deinfe MY_WINDOW does?
(20:04:33) (B) Scott (B): just means that word is defined, no value, just it exists
(19:57:58) (B) Scott (B): so lets say some other piece of your code needs that header also
(20:05:38) (B) Scott (B): So the compiler know not to re-read all that info again since it knows it already



PRIMITIVE DATA TYPES

- bool -> boolean value
- char -> 8 bit integer
- short -> 16 bit integer
- int -> 32 bit integer
- long -> 32/64 bit integer
- float -> 32 bit floating point value
- double -> 64 bit floating point value

CLASSES
- it can hold data & functions
- the scope operator (::smile: specifies the class to which the member being declared belongs

CONSTRUCTOR AND DESTRUCTOR
- constructor is avtomatically called whenever a new object is created
- constructor cannot be called explicitly as if they were regular member functions
- destructor is avtomatically called when an object is destroyed:
------> out of scope (because it's a local objectdefined in function)
------> with delete keyword

OVERLOADING CONSTRUCTORS
- same name but different types of parameters
- the right constructor(the one that matches the arguments list) is called when an object is created

// overloading class constructors
#include <iostream>
using namespace std;

class CRectangle {
    int width, height;
  public:
    CRectangle ();
    CRectangle (int,int);
    int area (void) {return (width*height);}
};

CRectangle::CRectangle () {
  width = 5;
  height = 5;
}

CRectangle::CRectangle (int a, int b) {
  width = a;
  height = b;
}

int main () {
  CRectangle rect (3,4);
  CRectangle rectb;
  cout << "rect area: " << rect.area() << endl;
  cout << "rectb area: " << rectb.area() << endl;
  return 0;
}

- rectb was declared without any arguments(so it has been initialized with the constructor that has no parameters)
- if we declare a new object and we want to use it's default constructor (the one without parameters), we do not include parantheses ()

CRectangle rectb;   // right
CRectangle rectb(); // wrong!

- dont't use () when creating an object except you have your own constructor (and it takes no parameters)

- as soon as you declare your own constructor the compiler no longer provides an implicit default constructor.


KEYWORD THIS
- it represents a pointer to the object whose member function is being executed
- it's a pointer to the object itself

STATIC MEMBERS
- Static data members of a class are also known as "class variables", because there is only one unique value for all the objects of that same class. Their content is not different from one object of this class to another.


INHERITANCE
- Inheritance allows to create classes which are derived from other classes, so that they automatically include some of its "parent's" members, plus its own
- Classes that are derived from others inherit all the accessible members of the base class. That means that if a base class includes a member A and we derive it to another class with another member called B, the derived class will contain both members A and B.
- In order to derive a class from another, we use a colon (:smile: in the declaration of the derived class using the following format:
 class derived_class_name: public base_class_name
{ /*...*/ };


WHAT IS INHERITED FROM THE BASE CLASS
- it inherits all variables and functions except constructor, destructor, friends
- although the constructor/destructor of the base class are not inherited themselves it's default constructor/destructor (the one without any parameters) are always called when a new object of derived class is created
- if the base class has no default constructor or you want to call overloaded constructor you can specify it in each constructor definition of the derived class:
derived_constructor_name (parameters) : base_constructor_name (parameters) {...}


// constructors and derived classes
#include <iostream>
using namespace std;

class mother {
  public:
    mother() { cout << "mother: no parameters\n"; }
    mother(int a) { cout << "mother: int parameter\n"; }
};

class daughter : public mother {
  public:
    daughter(int a) { cout << "daughter: int parameter\n\n"; }
};

class son : public mother {
  public:
    son(int a) : mother (a) { cout << "son: int parameter\n\n"; }
};

int main () {
  daughter cynthia(0);
  son daniel(0);
  
  return 0;
}




MULTIPLE INHERITANCE
- separate different base classes with commas
class CRectangle: public CPolygon, public COutput;
class CTriangle: public CPolygon, public COutput;



POINTERS
- is a variable that stores the memory address of an object
- as soon as we declare a variable, the amount of memory needed is assigned for it at a specific location in memory (it's memory address)
- operating system automatically decides the exact location of the variable in the memory

- the address that locates a variable within memory is waht we call a reference to that variable (& == address of)

eleanor = &evangeline

- this would assign to eleanor the address of variable evangeline

- & is the reference operator and can be read as "address of"
- * is the dereference operator and can be read as "value pointed by"

- The pointer terry points to a sequence of characters and can be read as if it was an array (remember that an array is just like a constant pointer). For example, we can access the fifth element of the array with any of these two expression:
*(terry+4)
terry[4]


- Suppose that we define three pointers in this compiler:
char *mychar;
short *myshort;
long *mylong;

mychar++;
myshort++;
mylong++;

- mychar, as you may expect, would contain the value 1001. But not so obviously, myshort would contain the value 2002, and mylong would contain 3004, even though they have each been increased only once. The reason is that when adding one to a pointer we are making it to point to the following element of the same type with which it has been defined, and therefore the size in bytes of the type pointed is added to the pointer.

VOID POINTERS
- The void type of pointer is a special type of pointer. In C++, void represents the absence of type, so void pointers are pointers that point to a value that has no type (and thus also an undetermined length and undetermined dereference properties).
- This allows void pointers to point to any data type, from an integer value or a float to a string of characters. But in exchange they have a great limitation: the data pointed by them cannot be directly dereferenced (which is logical, since we have no type to dereference to), and for that reason we will always have to cast the address in the void pointer to some other pointer type that points to a concrete data type before dereferencing it.

NULL POINTER
- A null pointer is a regular pointer of any pointer type which has a special value that indicates that it is not pointing to any valid reference or memory address. This value is the result of type-casting the integer value zero to any pointer type.


ENUMERATIONS
- enum is for declaring a set of named constants
enum DayOfWeek { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; 

- put this in a header file
- this is equivalent to the:
const int Sunday    = 0; 
const int Monday    = 1; 
const int Tuesday   = 2; 
const int Wednesday = 3; 
const int Thursday  = 4; 
const int Friday    = 5; 
const int Saturday  = 6;

- Notice that to refer to the Sunday constant from the DayOfWeek enum, we simply write Sunday, not DayOfWeek::Sunday.



TYPEDEFS
- C++ lets us give an alias to a data type using the typedef keyword
- typedef unsigned long int INTEGER

Manage shared libraries

STATIC AND DYNAMIC EXECUTABLES
linux system have 2 types of executable program:
1) statically linked executables contain all the library functions that they need to execute (they are complete programs -> they will work without installing prerequisites)
2) dynamically linked executables are much smaller programs that are incomplete (they require functions from external shared libraries in order to run)
- besides being smaller, dynamic linking permits a package to specify prerequisite libraries without needint to incude the libraries in the package. The use of dynamic linking also allows many running programs to share one copy of a library rather than occupying memory with many copies of the same code.

- ln commands creates link between files, wither hard links or soft(symbolic) links

LDD COMMAND
- apart from knowing that a statically linked program is likely to be large, how do we tell wheter a program is statically linked?
- and if it is dynamically linked, how do we know wat libraries it needs?
- answer is: ldd command which displays information about the library requirements of an executable

localhost eleanor # ldd /bin/ln
        linux-gate.so.1 =>  (0xb7f16000)
        libc.so.6 => /lib/libc.so.6 (0xb7dd9000)
        /lib/ld-linux.so.2 (0xb7f17000)

localhost eleanor # ldd /usr/bin/opera
        not a dynamic executable


- .so means that these are SHARED OBJECTS or DYNAMIC LIBRARIES


DYNAMIC LOADING
- ld-linux.so is an executable which is responsible for dynamically loading. It reads the header information from the executable which is in the ELF (executable and linking format) format. From this information it determines what libraries are required and which ones need to be loaded. It then performs dynamic linking to fix all the address pointers in your executable and the loaded libraries so that the program will run.

ld-linux.so.2 --list /bin/ln == ldd /bin/ln

DYNAMIC LIBRARY CONFIGURATION
- how does the dynamic loader know where to look for executables?
- there is a configuration file: /etc/ld.so.conf and /etc/ld.so.cache

- loading of programs needs to be fast, so the ld.so.conf file is processed ti the ldconfig command to process all the libraries from ld.so.conf.
- the dynamic lonker uses ld.conf.cache to locate files that are to be dynamically loaded and linked (so if you change ld.so.conf you must run ldconfig to rebuild your ld.so.cache file)

- ldconfig -p displays the contents of ld.so.cache
- just as you can set the PATH vatiable to specify a search path for executables, you can set LD_LIBRARY_PATH variable to a colon separated list of directories that should be searceh for shared libraries before the system ones specified in ld.so.cache





DEBIAN PACKAGE MANAGEMENT
- if apt-get notices that the package you are trying to install depends on other packages, it will automatically fetch and install those as well

Package Resource List: apt-setup
- apt-get read a package list from somewhere: /etc/apt/sources.list
- you can edit it youorself or use: apt-setup command
- this command knows the location of the main APT reporsitories

useful commands:
- apt-get update (refresh information about available packages)
- apt-get remove
- apt-get upgrade (upgrades all installed packages)
- apt-cache (search for packages on your system)


Make and install programs

Why might you want to install a program from source?
- you need a program that is not part of your distribution
- you need a program that is only available as source
- you need some features of a program that is only available by rebuilding the program from source
- you want to learn more about how a program works or you want to participate in it's development

DOWNLOAD AND UNPACK
- tarballs (tar == Tape ARchive)
- the tar command does not compress the data, it just stores it in a form from which the original files, permissions and directory structures can be restored.
- the tar command can be used in conjunction with a compression program (gzip or bzip2) to create a compressed archive which saves storage space as well as transmission time. (such a compressed archive is tarbal)

- besides simple tarballs, source for a particular program may be packaged for your distribution in a soource package, such as RPM

- for a particulat program, check to see if you need other packages in order to build it (you will also need to install sevedal libraries and perhaps development tools before you can successfully build your program)

- packages will usually have name that ends like:
tar
tar.gz      (gz extension -> file is compressed with gzip)
tar.Z
tgz
tar.bz2


- let say we have drgeo-1.1.0.tar.gz
- to just extract the tar archive we use the gunzip command
  uncompress drgeo-1.1.0.tar.Z 
  gunzip drgeo-1.1.0.tar.Z 
  gunzip drgeo-1.1.0.tar.gz 
  gunzip drgeo-1.1.0.tgz 
  bunzip2 drgeo-1.1.0.tar.bz2 

- our .tar.gz file has now been replaced by plain .tar file.

- to extract the files from the tar archive use tar command
- usual form: tar -xvf filename.tar
----> x option = extract the files
----> v optoon = verbose
----> f option = what archive to extract files from
----> check with -t option instead of -y to see wheter or not your program will create a new directory or not (not good it it dumps a lot of files over your home directory)

- now, let's do this in 1 command
tar -zxvf drgeo-1.1.0.tgz --> z = gzip archives
tar -jxvf drgeo-1.1.0.tar.bz2 --> j == bzip2 archives

BUILD THE PROGRAM
- look for installation documents in the directory you just unpacked (README or INSTALL)

CONFIGURE SCRIPT
- you will ofter find a configure script in the main source directory. This script is designed to set up a Makefile that is customized to your system. The configure script will probe your system to determine its capabilities. The resulting Makefile will build the project on your particular system
- a configuration script may check many aspects of your system, including things such as processor type (32 bit / 64 but...)
- if you don't hhave a file called configure in your main project directory, check your documentation to see if there is some alternative method (so the Makefile is already there with options that will work on most platforms) If you do run "./configure --help"
- this will give you some help on available configuration options

- configure scripts are likely to have a --prefix option to specify the install location (specify man and info pages with --mandir or --infodir)

- When you run configure, You will usually see messages indicating what type of system you have and what required tools are present or not present. If all goes well, you should have a Makefile built at the end of the configure process.


- when your configure scpript completes, it will store information about the configuration in a file called config.cache (in the same directory)

- if you need to run ./configure script again be sure to remove your config.cache file first (with rm), as configure will use the settings from config.cache if it's present and will not recheck your system.

MAKE AND MAKEFILE
- once a configuration step is complete, you should have a Makefile in your project directory
- it contains rules, which are the instructions that tell the make program how to build things (the file also contains targets, which tell the make program what to build)
- make file targets will usually be available for several functions, such as:
----> make -> just build the program
----> make install -> we install the program you built (need root authority if you are installing in /usr/local)
----> male clean -> will erase files created by the make process
----> make all -> is sometimes used to perform the bulk of the make file's function with a single target.

INSTALLATION
- as well as copying files, make install should aslo make sute the installed files have the correct ownership and permissions

Boot managers

HOW A PC BOOTS/STARTS
- code, called bios is stored in ROM and when a PC is turned on or rebooted, this code is executed
- usually it performs a power-on self test (POST) to check the machine
- finally it loads the first sector from the master boot record (MBR) on the boot drive

- MBR also contains the partition table, so the amount of executable code in mbr is less than 512 bytes
- every disk (even floppy) contains executable code in its mbr, even if the code is only enough to put out the message: "non-bootable disk in drive A:".
- this code that is loaded by BIOS from this first sector is called the first stage boot loader (or the stage 1 boot loader)
- The standard hard drive MBR used by MS DOS, PC DOS, and Windows operating systems checks the partition table to find a primary partition on the boot drive that is marked as active, loads the first sector from that partition, and passes control to the beginning of the loaded code. This new piece of code is also known as the partition boot record. The partition boot record is actually another stage 1 boot loader, but this one has just enough intelligence to load a set of blocks from the partition. This new code is called the stage 2 boot loader. As used by MS-DOS and PC-DOS, the stage 2 loader proceedes directly to load the rest of operating system. This is how your operating system pulls itself up by the bootstraps until it is up and running.
- This works fine for a system with a single operating system. What happens if you want multiple operating systems, say Windows 98, Windows XP, and three different Linux distributions? You could use some program (such as the DOS FDISK program) to change the active partition and reboot. This is cumbersome. Furthermore, a disk can have only four primary partitions, and the standard MBR can boot only a primary partition
- The solution lies in using some special code that allows a user to choose which operating system to boot. Examples include: grub, lilo... (stage 2 loader)
- evidently, if you can get control of the system into a program that has more than 512 bytes of code to accomplish its task, then it isn't too hard to allow booting from logical partitions, or booting from partitions that are not on the boot drive.
- However, LILO and GRUB differ significantly in that a change to the system requires you to use a command to recreate the LILO boot setup whenever you upgrade a kernel or make certain other changes to your system, while GRUB can accomplish this through a configuration text file that you can edit.

LILO (linux loader)
- can be installed int o the mbr of your bootable hard drive or into the partition boot record of a partition
- the primary function of lilo command is to write a stage 1 boot record and create a map file /boot/map using configuration information that is normally in /etc/lilo.conf

GLOBAL OPTIONS OF LILO
- prompt -> forces a boot prompt to be displayer
- timeout -> timeout before the default system will be automatically loaded
- compact -> speeds up load time and keeps the map smaller
- default -> which OS should be loaded by default (starting at 0)
- boot -> specifies where lilo will be installed (to install in the MBR of the first hard drive specify boot=/dev/hda, to install it on /dev/hda8 partition do boot=/dev/hda8)
- map -> specifies the location of the map file that lilo uses to provide user prompts and load the OS (default is /boot/map)
- install -> specifies the new file to install as the boot sector (default is /boot/boot.b)
- message -> specifies the message that is displayed before the boot prompt (must be less than 65535 bytes in length)
- lba 32 -> specifies that lilo should use LBA32 mode for the disk rather than CHS addressing
- password -> specifies the password that must be entered before booting an image (plain text --> so permit the file to be viewed only by root)
- resticted -> relayes the password requirement so that a password is only required if a user tries to privede additional parameters during boot

IMAGE OPTIONS FOR LILO
- image -> specifies that this section is for linux system that should be loaded from a file (the file is the linux kernel image)
- label -> is a name of the image
- initrd -> is the name of initial RAM disk which contains modules needed by the kernel before your file systems are mounted
- read-only -> root filesystem should be mounted as read-only (later stages of boot will usually remount it read-write after it has been checked)
- append -> specifies options to be passed to the kernel

- Remember also that with LILO you must run the lilo command whenever you update the configuration file (/etc/lilo.conf). You should also run the lilo command if you add, move, or remove partitions or make any other changes that might invalidate the generated boot loader.


GRUB (GRand unifood boot loader)
- can be installed into the MBR of your bootable hard drive, or into the partition boot record of a partition
- configuration file: /boot/grub/grub.conf (/boot/grub/menu.lst is a symbolic link to /boot/grub/grub.conf)

GLOBAL OPTIONS OF GRUB
- defalut -> specifies which system to load if the user does not make a choice within a timeout
- timeout
- splashimage -> specifies the background image to be displayed with the boot menu
- password -> grub permits passwords to be stored as an MD5 digest

IMAGE OPTIONS FOR GRUB
- title
- root -> specifies the partition that will be booted
- kernel -> specifies the kernel image to be loaded
- initrd -> is the name of the initial RAM disk which contains modules needed by the kernel before your file systems are mounted
- savedefault -> if the menu command "default=saved" is specified and the savedefault command is specified for an OS, then booting that OS will cause it to become the default until another OS with savedefault specified is booted.
- boot -> is an optional parameter that instructs GRUB to boot the selected OS
- lock -> the system will boot into single user mode which permits a user to make modifications to a system
- rootnoverify -> similar to root, except that grub does not attempt to mount the filesystem or verify its parameters. This is usually used for filesystems such as NTFS that are not supported by GRUB
- chainloader -> specifies that another file will be loaded as a stage 1 file. The value "+1" is equivalent to 0+1 which means to load one sector starting at sector 0, that is, load the first sector from the device specified by root or rootnoverify

ANOTHER INSTALL DESTROYS YOUR MBR
- sometimes you will install another OS and inadvertently ovrwrite your MBR
- some systems, such as DOS and windows always install their own MBR

grub> find /boot/grub/grub.conf
 (hd0,1)

grub>

- in this example, we have found that there are GRUB config files on one partition on our first hard drive



SCOTT
(01:23:58) (B) Scott (B): the menu you see in grub, that is the first stage. It doesn't load the OS.
(01:24:26) (B) Scott (B): after you pick, a second stage if loaded that does the actuall loading of the OS
(01:24:28) Eleanor: well does MBR first load grub menu?
(01:25:00) (B) Scott (B): the first stage of grub is stored in the MBR
(01:25:25) (B) Scott (B): that space is very small, that is why it has to be split into parts (stage 1 and stage 2)
(01:26:44) (B) Scott (B): the code that is takes to display that menu
(01:27:12) (B) Scott (B): grub can read many disk formats
(01:27:45) (B) Scott (B): all that code to do all those things is way to big to fit in the MBR. So its all smaller program in there, that loads the second stage of GRUB

Linux installation and package management

HARD DISK LAYOUT
- a linux filesystem contains files that are arranged on a disk or other block storage device in directories
- as with many other systems, directories on linux may contain other directories called subdirectories
- unlike windows with a concept of separate file systems on different drive letters (A:, C:...), a linux filesystem is a single tree with the / directory as it's root directory.

- each block device (hard drive partition, cd-rom, floppy...) has a filesystem on it
- you create the single tree view of the filesystems by mounting the filesystems on different devices at a point in the tree called mount point

- while the mount process actually mounts the filesystem on some device, it is common to say that you "mount the device" instead of "mount the filesystem on the device"

- here are the directories required in / by FHS (filesystem hierarchy standard)
- The Filesystem Hierarchy Standard (FHS) defines the main directories and their contents in Linux and other Unix-like computer operating systems.

Directory     Description
bin           Essential command binaries
boot          Static files of the boot loader
dev           Device files
etc           Host-specific system configuration
lib           Essential shared libraries and kernel modules
media         Mount point for removable media
mnt           Mount point for mounting a filesystem temporarily
opt           Add-on application software packages
sbin          Essential system binaries
srv           Data for services provided by this system
tmp           Temporary files
usr           Secondary hierarchy
var           Variable data



PARTITIONS
- the first IDE hard drive on linux is /dev/hda


- picture above has 2 platters

- a hard drive is formatted into 512 byte sectors
- all the sectors on a disk platter(pladenj) that can be read without moving the head constitute a track
- disks usually have more than one platter
- the collections of tracks on the various platters that can be read without moving the head is called a cylinder

SCOTT
- hard drive is made of metal platters
- (22:34:46) Eleanor: how do you know how much metal platters there is in a hard drive?
(22:35:07) (B) Scott (B): you don't unless they tell you
- for every side of each platter that can store information you have a head that read/writes to it
- so for a single platter there is probably two heads, 1 for each side
- each side is broken down into sectors
- think of it as a circle around the disk broken in pieces. Sectors on the outside are bigger than sectors on the inside but they hold the same amount of data
- Hard disk use something called CLV = Constant Linear Velocity
- that means that the hard disk always spins at the same speed, so when it is writing, the disk spins by faster on the outside
- it always spins the same speed, but the farther you are from the center, the platter surface area is moving by the read/write head faster.
- CDs use CAV = Constant Angular Velocity. When data is being read from the outside of a CD, the CD drive slows down. That is why CD drives make noise changing speeds all the time

(22:46:37) Eleanor: but how can disk have constant speed (CLV) if there is an option in MAC to only use disk when they are needed (and when they aren't they are asleep) ... and the noise is louder too
(22:47:47) (B) Scott (B): usually when you hear a hard drive it is the head moving back and forth due to fragmentation
(22:53:21) (B) Scott (B): Are you curious why they are different if the way CDs do it better?
(22:53:28) Eleanor: yes
(22:54:18) (B) Scott (B): a couple reasons. hard drives spin a lot faster so changing at those speeds would be harder
(22:55:01) (B) Scott (B): hard drive read/write heads actually just float over the platter so changing speeds could cause the platter to shake and hit the head
(22:55:23) (B) Scott (B): and its faster to just keep one speed even if it wastes space on the platter. Look at that picture again. Both a hard drive and CD hold the same amount of data in a sector, but the sector take more physical room on the platter on a hard drive. (so it uses more space) (They are not the same physical size, they hold the same about of data.)
(23:00:44) Eleanor: why is the sector size on the hard drives and cd the same?
(23:01:41) (B) Scott (B): technically they aren't, but to understand the concept you have to pretend they do or you won't understand


(23:05:45) (B) Scott (B): so you see you have these rings?
(23:05:55) Eleanor: around the center yes
(23:06:09) (B) Scott (B): and each ring is broken into equal sections?
(23:06:16) (B) Scott (B): equal for that ring
(23:06:21) Eleanor: yes
(23:06:26) (B) Scott (B): that is a sector
(23:06:32) Eleanor: aha
(23:06:38) (B) Scott (B): so all sectors along one ring are the same size.
(23:06:54) Eleanor: aha:)
(23:06:58) (B) Scott (B): as you move out from the center, sectors get bigger along each ring

(23:08:42) Eleanor: can you explain what's a head ?
(23:09:01) (B) Scott (B): the parts that read and writes data onto the platter.
(23:09:15) Eleanor: yes yes...I mean how does it look like
(23:09:18) (B) Scott (B): Its the hard drive equivalent of the laser on a CD
(23:09:39) (B) Scott (B): no way to explain what it looks like.
(23:09:51) (B) Scott (B): Its so small, just looks like a square piece of metal
(23:10:01) Eleanor: it's a metal stick?
(23:10:09) (B) Scott (B): yes.

(23:07:59) (B) Scott (B): So lets say you spin the disk a some speed. (doesn't matter)
(23:08:28) (B) Scott (B): so we look at the ring closest to the center and pretend the read/write head is over that ring
(23:57:05) (B) Scott (B): so lets assume at the speed our disk is spinning, that the surface of the platter is moving by the read/write head at 1 inch/sec
(23:58:18) (B) Scott (B): lets say our read/write head can right 8 bytes a second, so on this track, it 1 inch is storing 8 bytes. OK?
(23:59:14) (B) Scott (B): so now lets pretend that the read/write has moved to the outer most track
(23:59:40) Eleanor: so head has changed?
(23:59:48) (B) Scott (B): the head moves in and out
(00:00:31) (B) Scott (B): so when the head is on this track, the surface of the platter is moving by the read/write head at 2 inches/sec. OK?
(00:01:44) (B) Scott (B): The read/write always writes at the same speed, which is 8 bytes/sec, so in 1 second we have written 8 bytes again, but the platter surface has moved 2 inches
(00:02:33) (B) Scott (B): So you can see that it takes more physical space on the platter on the outside
(00:03:02) (B) Scott (B): So assuming in this example a sector = 8 bytes, the sector on the outside are twice as big as the sector on the inner most ring
(00:04:11) (B) Scott (B): So on CD/DVDs, the disc spins slower when reading or writing on the outside so the surface area is always moving by the read/write head at the same speed
(00:05:08) (B) Scott (B): so a hard disk can have several platters and each side has its own read/write head. OK?
(00:05:41) (B) Scott (B): the arm that moves each read/write head are all connected and move together. (not independently). (think of the arms like they were a comb (glavnik)- they are all connected and have to move together)
(00:07:33) (B) Scott (B): so a cylinder means all the same track number from each platter (each platter is identical - so if the first one has 80 tracks and 16 sectors a track, so do all the others)
(00:10:41) (B) Scott (B): cylinders are important, because each of those heads can be reading/writing at the same time.

(00:10:47) Eleanor: I still don't know what cylinder is
(00:11:22) (B) Scott (B): if you have a hard disk, lets say it has 3 platters and we only use the top side of each platter.
(00:11:42) (B) Scott (B): and lets assume each platter has 80 tracks with track 1 closest to the center
(00:12:19) (B) Scott (B): a cylinder would be track 1 on platter A, track 1 on platter B, and track 1 on platter C (same for track 80 on each platter.)
(00:13:47) (B) Scott (B): So technically, a disk with more platters is usually faster
(00:14:01) (B) Scott (B): since it can read/write more at the same time

(00:21:17) Eleanor: are there any math calculation connected to hard drives and cylinders, heads, sectors?
(00:21:28) (B) Scott (B): sure.
(00:21:33) Eleanor: which ones?
(00:22:06) (B) Scott (B): tons, depends on what you want to do. Usually if you know 2 of those things you can calculate the third
(00:22:31) Eleanor: well if I want the size of the disk for example?
(00:23:00) (B) Scott (B): you can't figure that out unless you know how much can be stored in a sector
(00:23:07) Eleanor: aha
(00:23:14) Eleanor: is there a way to figure that out?
(00:23:20) (B) Scott (B): no, not unless you already know the size
(00:25:56) (B) Scott (B): you know (tracks * sectors/track * number of heads * size of 1 sector) = full size of disc
so just use math to find size of 1 sector if you know the rest
----> tracks -> how many tracks a platter (remember cylinders is the same as tracks)
----> sectors/track -> sectors per track
----> number of heads -> 1 platter usually has 2 heads

- (00:42:08) (B) Scott (B): so the total number of sectors on a disk is tracks x sectors/track x heads
- sectors almost always are 512 bytes. (on any hard drive)
- (00:46:08) (B) Scott (B): its not always exact for several reasons
----> marketing terms. 1k = 1000 to marketing, but in computer terms 1k = 1024
----> and some parts of disk are reserved for other uses and not used directly by the consumer (things like every hard drive keeps a growing list of bad sectors. The user can't directly edit those sectors --> by those sectors I mean where the list is stored, not the bad sectors themselves)

(00:37:37) Eleanor: hm, it says there 255 heads...but 1 platter has 2 heads, and that's not right then...
(00:38:46) (B) Scott (B): like I said, they can do thinks like but multiple heads on 1 arm which complicates things


you can see the multiple platters and the little metal tip is read/write head


RPM's
- You will often see hard drives advertised as being capable of a certain RPM (Revolutions Per Minute), this figure (as the name suggests) refers to how many times the spindle makes a complete 360º turn in any single minute
- The higher the RPM, the faster the data can be read from the platters, which increases overall performance
- hdparm tests just calculates how much data it can read per second.
- all RPM means is how many complete rotations the platter does in 1 minute
- But just because a disk spins faster, DOESN'T mean it can read or write any faster.
- The faster spinning disk will be faster to rotate so we can read the second byte, but the actual read/write data rate is the same.
- So even though 7200 RPMs seems almost 50% faster than 5400 RPM, in practical terms it is only a small difference
- So it can be faster, things like seeking to a specific sector, or reading a second sector if you missed it and need to rotate to get it again

(01:10:04) (B) Scott (B): lets say we are reading on some track, doesn't matter which
(01:10:29) (B) Scott (B): the hard drive gets the command to read a byte and does and send it to the cpu
(01:10:54) (B) Scott (B): the hard drive gets a second command to read the next byte
(01:11:27) (B) Scott (B): the hard drive has already rotated past the second byte and needs to rotate 1 complete turn to get back to it
(01:12:00) (B) Scott (B): lets say it takes a 5400 RPM hard drive 100 ms to make 1 complete rotation on this track
(01:12:41) (B) Scott (B): now lets assume a 7200 RPM hard drive takes 75 ms to make 1 complete rotation on this track
(01:13:03) (B) Scott (B): see the 7200 RPM will rotate back to that sector faster and then we can read the second byte
(01:13:44) (B) Scott (B): so its seems faster. But, most hard drives read bytes in large batches so these type situations are avoided



HARD DISK DRIVE DESIGN
- HDD works with technology called magnetic recording
- the drive channel electronics receive data in binary form from the computer and convert them into a current in the head coil. The currect in the coil reveres at each 1 and remains the same at each 0



- today's magnetic head typically consist of an MR (magneto-resistive) or GMR (gianr MR) reading head and a thin-film inductive write head. MR head design is based on the ability of metals to change their resistivity in the presence of a magnetic field (the alloy of Ni and Fe (81%/19%) is widely used in MR heads.
- inductive thin film heads generate strong magnetic fields at the gap between the poles, thereby magnetizing areas of the media.
- modern magnetic media is called "thin-film media" and consists of very thin layers with a total thickness about 50nm.
- Amazingly, but year after year, this super-thin structure gets thinner and thinner to keep the magnetic head flying lower and lower to decrease that magnetic spacing loss...

BASIC DRIVE DESIGN
- every hard drive has:
----> one or many platters (which store magnetic data)
----> usually twice as many sliders with magnetic heads (to read or write data)
----> an actuator arm (to hold the suspension with the slider at the end)
----> a voice-coil actuator (to move the actuator when the head is accessing data)
- the drive is connected to the computer via the interface connector



- in order to keep the magnetic head as close to the disk surface as possible, a self-pressurized air-bearing design is used for the sliders.
- the slider rests on the landing zone of the disk when the power is off.
- when the drive is turned on, the disk starts spinning and air pressure builds up between the slider and the disk
- eventually the slider starts flying at the atitude (flying height) of a few dozen nm.

BASIC DRIVE CONCEPTS
- TRACK == a concentric set of magnetic bits on the disk is called a track
- each track is divided into 512 bytes
- SECTOR == a part of each track defined with magnetic marking and an ID number. Sectors have a sector hrader and an error correction code. In modern drives sectors are numbered sequentially.
- CYLINDER == a group of tracks with the same radius is called a cylinder (red tracks on the picture belong to 1 cylinder)
- DATA ADDRESSING:
----> there are two methods for drive's addressing: CHS (cylinder-head-sector) and LBA (logical block address)
----> CHS is used on most IDE drives, while LBA is used on SCSI drives
----> CHS locates addresses data by simply specifying the cylinder(radius), head(platters side) and sector(angular position)
----> LBA assigns each sector of the drive a sequential number, which is simpler.
----> if you look into BIOS, you'll find listed the number of cylinders, heads and sectors for each drive you have
----> modern OS's access data using LBA directly without the help of the BIOS-> this reduces incompatibilities.

CACHE OR BUFFER
- to improve performance and increase data rate, HDD's utilize a small amount of fast-state memory to store the most frequently used data. This memory is called 'cache' or 'buffer'. There are two types of cache memory organization: look-ahead and write/read

FORMATTING
1) low level formatting
- formatting is the first step in making the drive ready for data storage and retrieval. At this stage, the drive is being physically divided into tracks and sectors. Low-level formatting stays unchanged for the entire life of the drive unless the drive is re-formatted.
- today, drives are usually sold with low level formatting already done

2) partitioning
- partitioning divides the drive into logical drives
- every drive has at least one primary partition and may have many extended partitions
- the primary partition contains drive booting information in the MBR (master boot record) and also keeps a record of all other partitions
- use fdisk.ece for that

3) high-level formatting
- high-level formatting prepares drive partitions for the operating system by creating a root directory and creating a FAT (file allocation table), which keeps track of all information on the disks and all the relationships between different peices of information.
- use format.exe for that

FILE SYSTEM
- is a high-level environment allowing the user to interact with the data stored in the files. It allows the user to actually address data as files by keeping track of the file location, name, length...
- a primary filesystem at IBM:
----> FAT16 (dos and windows 3.x)
----> FAT32 (windows 95 and higher)
----> NTFS (windows NT)
- the main problem with FAT16 is that it is unable to address more than 2.1GB of data on each logical drive of the hard disk (you are forced to partition hard drive of not more than 2.1GB for each partition)
- Another problem is with the way FAT16 divides sectors into clusters: the cluster size is only 2 KB for logical disks less than 128 MB and 32 KB when the disk size exceeds 1 GB. This means that the system will allocate 32 KB for even the smallest files of 1 KB.
- There is no problem with addressing data with the FAT32 and NTSF systems. Problems won't appear until about 4 TB). The minimum cluster size for FAT32 is reduced to 16 KB.
- The main problem here is that the FAT32 and NTFS systems can not read each other's disk partitions, which requires reformatting (FDISK and FORMAT) the drive when the system is changed.



- the space on the hard drives is divided (or partitioned) into partitions.
- space that is not allocated to a partiton is called a free space
- IDE drives are limited to 63 partitions, while SCSI drives are limited to 15
- If two different partitioning programs have different understandings of the nominal disk geometry, it is possible for one partitioning program to report an error or possible problem with partitions created by another partitioning program.

localhost eleanor # cat /proc/ide/hda/geometry
physical     17475/15/63
logical      65535/16/63


- there are 3 types of partitions: primary, logical, extended
- the partiton table is located in the maste boot record (MBR)
- the MBR is th first sector on the dist, so the partition table is not a very large part of it. This limits the number of 4 primary partitions on a disk. When more than 4 partitions are required, on primary partition must become extended. A disk may contain only 1 extended partition
- an extended partition is nothing more than a container for logical partitions

localhost eleanor # parted
GNU Parted 1.7.1
Using /dev/hda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p

Disk /dev/hda: 80.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
 1      32.3kB  8011MB  8011MB  primary   reiserfs
 2      8011MB  18.0GB  10.0GB  primary   reiserfs
 4      19.1GB  61.0GB  41.9GB  primary   hfs+         boot
 3      61.0GB  80.0GB  19.0GB  extended
 5      61.0GB  61.9GB  872MB   logical   linux-swap
 6      61.9GB  80.0GB  18.1GB  logical   ext3


- good reasons for separating filesystems include:
----> boot files: some files must be accessible to the BIOS or boot loader at boot time
----> multiple hard drives
----> sharable files (home directory to many linux distros)
----> potential overflow (If a filesystem might fill to 100 percent of its capacity, it is usually a good idea to separate this from files that are needed to run the system)

USB devices

- USB (universal serial bus)
- the usb design allows devices to be hot-plugged and uses standard connectors for connecting devices
- usb devices include: keyboards, mice, printers, scanners, hard drives, flash memory drives, cameras, modems...

- a computer system may provide one or more controllers or hubs to which either USB devices or another (external) hub may be connected.



- the usb system is a layered system:
1) BUS INTERFACE - provides physical, signaling and packet connectivity between hosts and devices, providing data transfer between the host and device
2) The Device layer is used by the system software to do generic USB operations with a device over the bus. This allows the host to determine characteristics of the device, including device class, vendor name, device name, power requirements, and many capabilities such as device speed or USB level supported.
3) The Function layer provides additional capabilities that are specific to the device. Matched host and device software layers permit use device-specific functions.

- the earlier USB (1.0 and 1.1) support speeds up to 12Mbps while newer 2.0 usb support speeds up to 480Mbps

- the usb cable is thin, 4 wire cable with two signals lines plus power and ground. The end plugged into a hub has a flat rectangular connector (A connector) while the end plugged into a device or diwnstream hub has a small more square connector (B connector)
- usb devices or hubs may draw power from usb bus or may be self powered

LINUX USB MODULE SUPPORT
- support is usually provided through kernel modules
- do "lspci | grep -i usb" to show usb related devices

localhost eleanor # lspci | grep -i usb
00:1d.0 USB Controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB UHCI
00:1d.1 USB Controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB UHCI
00:1d.2 USB Controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB UHCI
00:1d.3 USB Controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB UHCI
00:1d.7 USB Controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB2 EHCI


- there are four USB controllers in this system.
- the UHCI and EHCI fields indicate the driver module required to support the controller

linux usb drivers
Driver Chipset
  EHCI  USB 2.0 Support - requires one of UHCI, OHCI or JE
  UHCI  Intel and VIA chipsets
  JE  This is an alternate to UHCI for 2.4 kernels. If UHCI does not work, and you have an Intel or VIA chipset, try JE
  OHCI  Compaq, most PowerMacs, iMacs, and PowerBooks, OPTi, SiS, ALi



DISPLAYING USB INFORMATION
- /proc/bus/usb --> what usb devices are attached to our system
- /proc/bus/usb/devices --> summary for currently attached usb devices

localhost eleanor # cat /proc/bus/usb/devices

T:  Bus=05 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.21-gentoo-r3 uhci_hcd
S:  Product=UHCI Host Controller
S:  SerialNumber=0000:00:1d.3
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=  0mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms

- spd=480 --> this is a USB 2.0 bus
- spd=12 --> this is a USB 1.1/1.0 bus

- there is a "lsusb" information to help you display this info
- you can get a tree view of you usb devices by using the -t option
- option -v for verbose view
- with -d option you can get info about a specific device
localhost eleanor # lsusb -t
Bus#  5
`-Dev#   1 Vendor 0x0000 Product 0x0000
Bus#  4
`-Dev#   1 Vendor 0x0000 Product 0x0000
Bus#  3
`-Dev#   1 Vendor 0x0000 Product 0x0000
Bus#  2
`-Dev#   1 Vendor 0x0000 Product 0x0000
  `-Dev#   6 Vendor 0x046d Product 0xc040
Bus#  1
`-Dev#   1 Vendor 0x0000 Product 0x0000
localhost eleanor # lsusb -d 0x046d:0xc040
Bus 002 Device 006: ID 046d:c040 Logitech, Inc.


- One more piece of information that is available to us now that we know the bus and device ids of your USB devices is a way to determine which modules are required for a particular device.

[root@lyrebird root]# usbmodules --device /proc/bus/usb/004/003
usb-storage
[root@lyrebird root]# usbmodules --device /proc/bus/usb/004/007
usb-storage
hid



HOT PLUGGING
- there are 2 commands that your system might use to handle hot plugging of USB devices: usbmgr and hotplug
- according to which you are using you will find configuration files in /etc/usbmgr and /etc/hotplug

Hot plugging for USB (and also PC cards) involves users plugging in devices while a system is running. The system then has to:
- determine the device type and find a driver to run it
- bind the driver to the device
- notify other subsystems about the device (this allows disks to be mounted)

SCSI devices

- SCSI (small computer system interface) is an interface designed for connecting streaming devices (like: tapes, printers, scanners, block storage devices: disks, cdroms, dvds...)
- it was designed to allow multiple devices on the bus (and one device: controller has the responsibility for managing the bus)
- SCSI devices may be internal/external



SCSI Ids
- how the system manages many devices on one cable?
- every device, including the controller, has an ID, represented by a number (for narrow 8-bit SCSI, the ID numbers range from 0 trough 7)

Linux names and files for SCSI devices
- first device is /dev/sda then /dev/sdb ...
- the numbering is redone at reboot
- /proc/scsi/scsi --> info about SCSI devices
- use "sdsi_info /dev/sda" if you want to know which real device corresponds to /dev/sda

Modems and sound cards

MODEM

- A modem is a device for converting the digital signals used in computers to a serial stream of analog data that is transmitted over a telephone lines.
- modems used to be external devices that were attached to a serial port.
- now modems are implemented on cards that could be installed inside the computer (reduced cost and power, no need for a cable between a serial port and modem)
- most external/internal modems will work under linux with no problem
- if you have an ISA modem, you will need to ensure that ports, IRQs and DMA channels do not conflict with other devices

- when communicating using modem, you need to set the speed of communication between your system and the modem (set it to the max supported speed by your serial port chipset and your modem)
- one way to set/view the modem parameters that will be used by the serial driver is with the "setserial" program

[root@attic4 ~]# setserial /dev/ttyS0
/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
[root@attic4 ~]# setserial -G /dev/ttyS0
/dev/ttyS0 uart 16550A port 0x03f8 irq 4 baud_base 115200 spd_normal skip_test



- if you wish to set up a PPP connection, the "kppp" program will come in handy.
- the "wvdial" commands provides a command line tool for setting up dial connections


SOUNDCARD
- today most of the cards use the PCI bus
- many motherboards even provide a sound chip with SOund Blaster compatibility on board
- sound devices may also be attached through USB connections

CONFIGURING LINUX SOUND SUPPORT
- there is support for a variety of sound devices in kernel
- use "lspci" with PCI devices to display info about a device
- use "pnpdump" with ISA devices to display info about a device

- the module configuration is stored in /etc/modprobe.conf
- "lsmod" == cat /proc/modules

- sound support on older systems (2.4 and earlier) is provided by OSS (oen sound system)
- many systems today use ALSA (advanced linux sound architecture)
December 2009
M T W T F S S
November 2009January 2010
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31