Title: Introduction: Unix
1Introduction Unix
- Software Project Spring 2009
2Administration
3Teaching 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
4The 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)
5Course grade
- Exam (30)
- Assignments and final project (70)
- Black box tests automatic tests that run the
program and check its output - Code review
6Overview (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
7Introduction to UNIX
8Operating 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
9The 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)
10Basic commands in Unix shells
11Additional 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
12File 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
13Editing 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
14Pipes 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
15Comparing 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
16Working 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
17Development environments for C
18Printing "Hello World in C
include ltstdio.hgt int main(void) printf(Hell
o world!\n) return 0
19C programming process
Hello.c
Edit
Hello World!
Source code (High-level language)
Object file (Machine code)
Executable
Output
20Basic tools in UNIX
21Compiling 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))
22Make 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
23How 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
24gdb the GNU debugger
- Running gdb gdb ltexegt
- Useful commands help, quit, next, step,
breakpoint ltfunctiongt/ltlinegt, backtrace (bt, up,
down, seg faults), list, print
25Eclipse
26Availability
- 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
27Create a new workspace
28Create a new project-1 (Linux lab)
29Create a new project -2 (Linux Lab)
30create a new project (windows)
31Add source file
32Add makefile (a file named makefile)
33Build the project in each save. (LINUX Lab)
34Project properties (windows)
35Build the project
36Running 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
37Debugging under Windowscygwin
Console in a new window
38Microsoft Visual Studio
39Advantages / 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/
40Creating a project (and a solution)
41Adding new source files
- Right click on project name Add-gtNew Item
Write file name, including the .c suffix (e.g.
file.c)
42Build project
43Compiling with debug information
44Removing optimization
45Linking with debug information
46Debugging
47Submission of assignments and project
48Submission 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!
49How 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)
50Grading 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!
51Appeals
- 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