Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review.

Similar presentations


Presentation on theme: "Review."— Presentation transcript:

1 Review

2 UNIX Features Multiple users access a system at the same time
Support file management and process management Provide a directory hierarchy Share CPUs, memory, and disk space Allow processes and peripherals to talk to each other Standard utilities System calls A portable operating system

3 Common UNIX utilities pwd cat , more, page, head, tail ls, cd
mv, cp, rm mkdir, rmdir file, wc , lp vi groups, chgrp, chmod

4 Grep Filtering patterns: egrep, fgrep, grep
grep -hilnvw pattern {fileName}* displays lines from files that match the pattern pattern : regular expression -h : do not list file names if many files are specified -i : ignore case -l : displays list of files containing pattern -n : display line numbers v : displays lines that do not match the pattern -w : matches only whole words only

5 Grep variations fgrep : pattern must be fixed string
egrep : pattern can be extended regular expression -x option in fgrep: displays only lines that are exactly equal to string extended regular expressions: + matches one or more of the single preceding character ? matches zero or one of the single preceding character | either or (ex. a* | b*)‏ () *, +, ? operate on entire subexpression not just on preceding character; ex. (ab | ba)*

6 Sort sort -tc -r [+POS1 [-POS2]] {sortField -bfMn}* {fileName}*
-tc separator is c instead of blank -r descending instead of ascending -b ignore leading blanks -f ignore case -M month sort (3 letter month abbreviation)‏ -n numeric sort +POS1 [-POS2] key positions start [up to end]

7 find Utility awk tar Utility Stream Editor (sed)

8 Environment Variables
$HOME : full pathname of home directory $PATH : list of directories to search for commands $MAIL : the full pathname of mailbox $USER : your username $SHELL : the full pathname of login shell $TERM : the type of your terminal

9 Built-In Variables $$ the process ID of the shell
$0 the name of the shell script $1..$9 $n refers to the nth command line argument $* a list of all command-line arguments

10 Test Command test expression
[ expression ] (equivalent form on some UNIX: if it’s built-in) Returns a zero if expression evaluates to true Otherwise, returns a nonzero status. Examples: $ test 2 -eq 3; $ test -e for.sh; $ test abc = abc;

11 Case Structure case expression in pattern)‏ list ;; pattern2)‏ list2
... *) # default list_n esac

12 Control Structures: for .. do .. done
for name [in {word}* ] do list done Loops the value of name through each word in the word list, evaluates commands in the list at each iteration. If no word list is supplied, is used. break : terminate the loop immediately. continue : jump to the next iteration.

13 Control Structures: if .. then .. fi
if list1 then list2 elif list #may be repeated several times list4 else #may occur zero or one time list5 fi Commands in list1 are executed. If last command succeeds, the list2 is executed. Otherwise, a successful command list in elif causes the associated then to be executed.

14 Control Structures: until .. do .. done
until list1 do list2 done Executes list1 If the last command in list1 succeeds, it ends. Otherwise, list2 is executed and the process is repeated. If list2 is empty, the do keyword should be omitted. break continue

15 Control Structures: while .. done
while list1 do list2 done Executes list1. If the last command in list1 fails, it ends Otherwise, list2 is executed and the process is repeated. If list2 is empty, the do keyword should be omitted. break continue

16 C programming Operator precedence and associativity
Pointers arithmetic Relationship between array and pointers Linked List operations

17 if … else Statement if (expression) statement
if (expression) statement else statement Statement can be compound: { statements} if (i==0) vs if (i=0) if (expression) statement else if (expression) else

18 Conditional Expression
expr1 ? expr2: expr3 int i, j, k; i = 1; j = 2; k = i > j ? i : j ; k = (i > 0 ? i : 0) + j ; return (i > j ? i : j); printf (“%d\n”, i > j ? i : j);

19 switch Statement switch ( expression ){
case constant-expression: statements default: statements } Controlling expression should be an integer expression (characters) Constant expression can’t contain variables or function calls. Statements do not require {}. Usually, the last statement is break.

20 while Loop while (expression) statement Statement can be compound: {}
while (i>0) printf (“%d\n”, i--); while (i>0) { printf (“%d\n”, i); i--; } Infinite loops: while(1) Break, goto, return

21 do Loop do statement while (expression); Statement can be compound: {}
do printf (“%d\n”, i--); while (i>0) ; do { printf (“%d\n”, i); i--; } while (i>0);

22 for Loop for (expr1; expr2; expr3) statement
Statement can be compound: {} expr1; while (expr2) { statement expr3; } Infinite loop: for (;;) break statement continue statement

23 Functions return type function-name (parameters) { declarations
statements } Function can not return array Pass-by-value Pass-by-reference

24 Declaring Structures (struct)
Engineering H192 Winter 2005 Declaring Structures (struct) struct date { int day; char month[3]; char year[4]; } ; /* The name “date" is called a structure tag */ Struct date date1; Struct date date2 = {3,”Jan”,”1912”}; Struct { int day; char month[3]; char year[4]; } my_date ; my_date date3 = {2,”Jul”,”2010”}; Instructor: A structure can be defined in two ways. The first method gives the compiler the layout or structure of the struct, but does not actually create one for use. This is useful when the programmer wishes to create global definitions for structs that he or she wishes to use later. The second method varies only in that a variable name now exists after the closing brace of the structure. This variable is now a struct which contains all the variables within the struct definition. Accessing the data in this variable will be discussed in a few slides. Lecture 23

25 Compiling and Linking

26 Example of Makefile main1: main.o power.o cc power.o main.o -o main1
main.o: main.c power.h cc -c main.c power.o: power.c power.h cc -c power.c

27 Error Handling errno perror()

28 File Management open read/write lseek close Stat Fcntl chmod

29 Process Management fork()‏ getpid()‏ getppid()‏ exit()‏ wait()‏ exec()


Download ppt "Review."

Similar presentations


Ads by Google