Introduction: Unix - PowerPoint PPT Presentation

1 / 51
About This Presentation
Title:

Introduction: Unix

Description:

Common text editors: pico - simple but very basic. vi, vim - two modes: command / write ... Once your code is submitted do not touch it! ( we check time stamps) ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 52
Provided by: Fla67
Category:

less

Transcript and Presenter's Notes

Title: Introduction: Unix


1
Introduction Unix
  • Software Project Spring 2009

2
Administration
3
Teaching Assistants
  • Michal Ozery-Flato, Ben Riva
  • Website
  • http//www.cs.tau.ac.il/benriva/courses/soft-proj
    ect09b/
  • E-mail ozery,benriva_at_post.tau.ac.il
  • Office Hours by appointment

4
The goals of the course
  • Learning C
  • Learning (a bit) Unix
  • Practicing software development
  • Understanding software requirements
  • Implementation
  • Testing
  • Deployment (i.e. installation, setting
    permissions, verification)
  • Working in small teams (submission is in pairs)

5
Course grade
  • Exam (30)
  • Assignments and final project (70)
  • Black box tests automatic tests that run the
    program and check its output
  • Code review

6
Overview (for the rest of this lesson)
  • Introduction to Unix
  • Development environments for C
  • Basic tools in UNIX
  • Eclipse
  • Visual Studio
  • Submission of assignments and project

7
Introduction to UNIX
  • (and Linux)

8
Operating Systems
  • An operating system (OS) is a software that
  • manages the resources of a computer CPU, memory,
    devices
  • provides programmers and users with an interface
    to access those resources.
  • may support/provide multi-tasking, multi-users,
    GUI, security, etc.
  • Interfaces
  • Shell a user interface based on a command-line
    interpreter.

ApplicationUser Interface
ProgramUser Interface
OSKernal
Hardware
Users
9
The Unix OS
  • Unix multi-user, multi-tasking OS
    open source.
  • Case sensitive (commands, filenames...)
  • History
  • 1969 Initial version by Thompson Ritchie at
    ATT Bell Labs.
  • 70s Rewritten in C (enables portability).
  • 80s System-V (ATT) and BSD (Berkeley)
    versions. POSIX Standards.
  • 90s Linux by Linus Torvalds.
  • For basic introduction and commands - see course
    web-page (unix.doc)

10
Basic commands in Unix shells
11
Additional Unix commands
  • cat concatenate files and print to standard
    output
  • cat file1
  • cat file1 file2 file3
  • less file viewer (less is better than more)
  • which locate a command
  • groups prints the groups the user in
    (permission...)
  • grep prints lines matching to a pattern
  • grep i .lib. foo.bar
  • find search for a file in a directory
  • find . name .txt print
  • find / name .o -exec rm \
  • clear clears the terminal screen
  • finger prints information about a user
  • who shows who is logged in
  • whoami identifies the current user

12
File and directory permissions in Unix
group
permissions
  • permissions bits 2-10 (bit 1 ddirectory,
    - file)
  • bit 1 whether is a directory (d) or not (-)
  • bits 2-4 owner permissions
  • bits 5-7 group permissions
  • bits 8-10 other permissions
  • rwx
  • r read permission
  • w write permission
  • x execute (file)/ enter (cd directory)
  • changing permissions chmod
  • chmod gorx a.out
  • chmod R 755 mydir

13
Editing text files in Unix
  • Common text editors
  • pico - simple but very basic
  • vi, vim - two modes command / write
  • emacs, xemacs (GUI) - see course webpage for a
    simple tutorial
  • More info man pico, man vi, man vim
    man emacs

14
Pipes and redirections to/from files
  • Pipe prog1 prog2 the output of prog1 is
    redirected to the input of prog2
  • Example ls l less
  • Output redirection to file
  • prog gt foo.out may cause an error if foo.out
    exists
  • prog gt! foo.out truncates foo.out if exists
  • prog gtgt foo.out may cause error if foo.out does
    NOT exist
  • prog gtgt! foo.out does not check whether foo.out
    exists
  • Input redirection (read from file)
  • prog lt foo.in

15
Comparing files (program tests)
  • prog lt1.in gt! my1.out reading from 1.in and
    writing to 1.out
  • diff my1.out 1.out compares files line by line
  • Ignoring all whitespaces diff w my1.out 1.out

16
Working from home...
  • Putty - shell window
  • Winscp - copying files
  • Links
  • http//www.cs.tau.ac.il/faq/
  • http//www.cs.tau.ac.il/faq/index.php/D792D799
    D7A9D794_D79CD7A9D7A8D7AAD799D79D

17
Development environments for C
18
Printing "Hello World in C
include ltstdio.hgt int main(void) printf(Hell
o world!\n) return 0
19
C programming process
Hello.c
Edit
Hello World!
Source code (High-level language)
Object file (Machine code)
Executable
Output
20
Basic tools in UNIX
21
Compiling and linking
  • Compiling and linking
  • gcc hello.c o hello
  • Only compiling (creating hello.o)
  • gcc c hello.c
  • Only linking
  • gcc hello.o o hello
  • Additional common flags to gcc
  • -ansi -pedantic-errors - verifies that the code
    is ANSI C compliant
  • -g allows debugging
  • -lltlibrary-namegt - linking with external library
  • -lm - if a math function is called (e.g. pow(x))

22
Make and makefiles (in short)
  • makefile a file containing a collection of
    rules. Used for building applications
  • The default name of a filename "makefile"
  • make a utility for executing makefiles
  • Makefiles will be covered later in the course.
    Till then, makefiles will be supplied

all hello clean rm hello.o hello hello
hello.o gcc -g hello.o -o hello hello.o
hello.c gcc -ansi -pedantic-errors -g -c hello.c
target name
dependencies
command
rule
23
How to use makefiles
  • Copy the makefile into the appropriate directory
    (e.g. the directory containing the source files)
  • In a shell window (e.g. putty) change to the
    directory containing the makefile
  • Use the commands "make clean" "make all" to
    build the executable

24
gdb the GNU debugger
  • Running gdb gdb ltexegt
  • Useful commands help, quit, next, step,
    breakpoint ltfunctiongt/ltlinegt, backtrace (bt, up,
    down, seg faults), list, print

25
Eclipse
26
Availability
  • Installed in the CS School LINUX lab (Linux)
  • Including C/C projects
  • Working at home (Windows) - not recommended
  • Code requires porting to LINUX
  • Relatively complicated installation
  • Cygwin http//www.cygwin.com/
  • Update PATH to contain c\cygwin (or your
    alternative path)
  • CDT http//www.eclipse.org/cdt/
  • No support from course staff / helpdesk for
    installations

27
Create a new workspace
28
Create a new project-1 (Linux lab)
29
Create a new project -2 (Linux Lab)
30
create a new project (windows)
31
Add source file
32
Add makefile (a file named makefile)
33
Build the project in each save. (LINUX Lab)
34
Project properties (windows)
35
Build the project
36
Running and Debugging (LINUX lab)
  • Right click on the executable file (with the bug
    icon )
  • Run As-gtLocal C/C Application
  • Debug As-gtLocal C/C Application
  • Set debugger to GDB Debugger

37
Debugging under Windowscygwin
Console in a new window
38
Microsoft Visual Studio
39
Advantages / disadvantage, download info
  • Advantages
  • A common and friendly IDE for C/C.
  • Recommended for development under Windows
  • A relatively simple installation, good support in
    the internet
  • Disadvantage requires porting to Linux
  • Free download Visual Studio Express C (2008
    edition)
  • see http//msdn2.microsoft.com/visualc/

40
Creating a project (and a solution)
41
Adding new source files
  • Right click on project name Add-gtNew Item

Write file name, including the .c suffix (e.g.
file.c)
42
Build project
43
Compiling with debug information
44
Removing optimization
45
Linking with debug information
46
Debugging
47
Submission of assignments and project
48
Submission in pairs
  • The exercises and project are submitted in pairs
  • If you do not have a partner send me an e-mail
    (no single submissions)
  • The exercise must be submitted in the home
    directories of both partners.
  • The submitted directories of the two partners
    should be identical!

49
How to submit
  • Under /soft-proj09b/
  • Strictly follow the provided file framework for
    each assignments / project
  • Perform rebuild make clean make all
  • Verify correct run use given input/outfile
    diff.Output should be exactly as specified! (do
    not add unnecessary friendly printf commands!)
  • Before submission give permission chmod 755
    chmod -R 755 /soft-proj09b
  • Manual submission - one for each pair
  • printouts of code
  • Should include name, user-name, and id-number
    of both partners!
  • submitted to the checkers mail-box (details will
    be given later)

50
Grading policy
  • If you do not follow the submission guidelines
    and your exercise cannot be automatically checked
    ? your grade will be zero!
  • No appeals with submission/compilation/execution
    problems will be considered!

51
Appeals
  • Once your code is submitted do not touch it!
    (we check time stamps)
  • Appeals must be submitted within one week after
    grades publication.
  • To appeal resubmit to the checkers mail-box
  • The original printout (with the checkers
    comments).
  • A detailed description of your appeal
Write a Comment
User Comments (0)
About PowerShow.com