1. Trang chủ
  2. » Công Nghệ Thông Tin

Learning unix and C slide

49 187 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 49
Dung lượng 1,1 MB

Nội dung

1 Learning Unix and C Software Project – Winter 2007 / 2008 2 Administration 3 Teaching Assistant  T.A.: Michal Ozery-Flato  E-mail: ozery@post.tau.ac.il  Office Hours: by appointment  Location: Schreiber 223  T.A. Website: http://www.cs.tau.ac.il/~ozery/courses/soft-p roject08/ 4 The goals of the course  Learn C  Learn (a bit) Unix  Practice software development:  Understanding software requirements  Implementation  Testing  Deployment (i.e. installation, setting permission, verification)  Working in small teams (submission is in pairs) 5 Course grade  Final grade is based on:  Exam  Assignments and final project:  “Black box” tests: automatic tests that run the program and check its output  “White box” tests: 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. Users Application User Interface Program User Interface OS Kernal Hardware 9 The Unix OS  Unix: multi-user, multi-tasking OS; open source.  History:  1969 – Initial version by Thompson & Ritchie at AT&T Bell Labs.  70’s – Rewritten in C (enables portability).  80’s – System-V (AT&T) and BSD (Berkeley) versions.  90’s – Linux by Linus Torvalds.  For basic introduction and commands - see course web-page (unix.doc) 10 Basic commands in Unix shells Command Short explanation ls -l prints the content of a directory pwd prints the name of the current directory cd change directory mkdir creates a new directory cp copies a file mv moves a file/directory rm removes (deletes) a file rmdir removes an empty directory man help (manual) on a command [...]... the printing function (declared in stdio.h) 17 C programming process C Libraries Edit Hello .c Compile Source code (High-Level Language) Hello.o Link Object file (Machine Language) Hello Run Hello World! Executable Output 18 Basic tools in UNIX 19 Compiling and linking  Compiling and linking   Only compiling (creating hello.o)   gcc c hello .c Only linking   gcc hello .c –o hello gcc hello.o –o hello... PATH to contain c: \cygwin (or your alternative path) CDT: http://www.eclipse.org/cdt/ No support from course staff / helpdesk for installations 24 Create a new workspace /a/home/cc/students/cs/ozery/soft-proj08 25 Create a new project-1 (Linux lab) 26 Create a new project -2 (Linux Lab) 27 create a new project (windows) 28 Add source file 29 Add makefile (a file named “makefile”) 30 Build the project in... Additional common flags to gcc:   -g – allows debugging -l - linking with external libraries 20 Make and makefiles (in short)   makefile: a collection of rules to make targets make: a utility that “executes” makefiles target name dependencies command all: hello clean: -rm hello.o hello hello: hello.o gcc -g hello.o -o hello hello.o: hello .c gcc -c -g hello .c rule Makefiles will be covered... – write permission x – execute (file)/ can cd (directory) changing permissions: chmod   chmod go+rx a.out chmod –R 755 mydir 12 Editing text files in Unix  Common text editors:   vi, vim   pico - simple but very basic, similar to notepad emacs, xemacs (GUI) - see course webpage for a simple tutorial More info: man pico, man vi, man vim man emacs 13 Pipes and redirections to/from files  Pipe:... “makefile”) 30 Build the project in each save (LINUX Lab) 31 Project properties (windows) 32 Build the project 33 Running and Debugging (LINUX lab)  Right click on the executable file (with the bug icon ):    Run As->Local C/ C++ Application Debug As->Local C/ C++ Application Set debugger to “GDB Debugger” 34 Debugging under Windows+cygwin Console in a new window 35 Microsoft Visual Studio 36 ... 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 15 Development environments for C 16 Printing "Hello World” in C #include Include the standard Include the standard function declaration function declaration int main(void) { printf(“Hello world!\n”); return 0; } Call the printing function (declared in stdio.h) Call the...Additional Unix commands  cat – concatenate files and print to standard output       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   cat file1 cat file1 file2 file3 find –name... in the course In the meanwhile, makefiles will be supplied 21 gdb – the GNU debugger  Running gdb: gdb  Useful commands: help, quit, n, s, b / 22 Eclipse 23 Availability  Installed in the CS School LINUX lab (Linux)   Including C/ C++ projects Working at home (Windows)   Code requires porting to LINUX Relatively complicated installation  Cygwin: http://www.cygwin.com/ ... 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 11 File and directory permissions in Unix permissions  permissions = bits 2-10 (bit 1: “d”=directory, “-” = file)      bit 1 = whether is a directory (d) or not (-) bits 2-4: owner permissions... output of prog1 is redirected to the input of prog2   Output redirection to file      Example: ls –l | less prog > foo.out :may cause an error if foo.out exists prog >! foo.out :truncates foo.out if exists prog >> foo.out :may cause error if foo.out does NOT exist prog >>! foo.out :does not check whether foo.out exists Input redirection (read from file)  prog < foo.in 14 Comparing files (program . Language) Object file (Machine Language) Executable Output 19 Basic tools in UNIX 20 Compiling and linking  Compiling and linking  gcc hello .c –o hello  Only compiling (creating hello.o)  gcc c hello .c  Only. (unix. doc) 10 Basic commands in Unix shells Command Short explanation ls -l prints the content of a directory pwd prints the name of the current directory cd change directory mkdir creates a new directory cp. in C #include <stdio.h> int main(void) { printf(“Hello world! ”); return 0; } Include the standard function declaration Include the standard function declaration Call the printing function

Ngày đăng: 24/10/2014, 10:53