Introduction to Linux What is Linux Why Not

  • Slides: 29
Download presentation
Introduction to Linux • • What is Linux? Why [Not] Linux? Linux Distributions Shells

Introduction to Linux • • What is Linux? Why [Not] Linux? Linux Distributions Shells Editors Commands Creating a makefile Supplementary Slides 2 1

What is Linux? • Unix-like operating system • Primarily a command-line OS requiring user

What is Linux? • Unix-like operating system • Primarily a command-line OS requiring user to enter commands on the keyboard – Has a GUI called X Windows that operates similarly to MS Windows • Traditionally designed for more technical, hands-on computer users – High performance and system flexibility are major concerns – Rapidly joining the group of OS for the general consumer • More often used as a filer server, Web server, or email server than as a desktop OS. Supplementary Slides 2 2

Origins of Unix/Linux • 1969: Initial version of Unix written in assembly language –

Origins of Unix/Linux • 1969: Initial version of Unix written in assembly language – By Ken Thompson and D. Ritchie at AT&T Bell Labs • Later rewritten in C for easier modification – Also to increase the number of mainframe and minicomputers on which Unix can run • 1974: Unix licensed to interested universities as a development tool • Students at licensed universities began developing and sharing utility programs to perform small but important tasks – some of these programs still part of the Unix kernel • Kernel: part of the OS code closest to the machine and activates h/w components directly or through another s/w layer Supplementary Slides 2 3

Origins of Unix/Linux (cont’d) • Many universities began to use Unix to share research

Origins of Unix/Linux (cont’d) • Many universities began to use Unix to share research data with other universities and industry over telephone lines – marked the beginning of the Internet and Internet Protocols (IP) • Unix "clones" developed over the years – typically modified Unix to make it accessible to the desktop user • One such successful clones resulted in the Linux OS – Initiated by Linus Torvalds, then a student at the Univ. of Helsinki Supplementary Slides 2 4

Linux Strengths • Stability – Linux rarely crashes – Written by programmers writing for

Linux Strengths • Stability – Linux rarely crashes – Written by programmers writing for other programmers (no deadlines, show one’s ingenuity etc) – Designed to be upgraded and modified "on the fly" • Security – Interested developers help identify & fix security problems – Developers said to create software updates to fix problems within 24 hours! • Resource-use economy – Designed to use limited hardware resources efficiently – Makes better use of hardware than almost any other OS – Translates into speed when more extensive resources available • A Mutitasking, Multiuser, Multiprocessing System – Can run many programs at the same time through preemptive multitasking – Many users can log in to the same system over a network and run programs – Supports multiple CPUs on the same computer using symmetric multiprocessing Supplementary Slides 2 5

Linux Strengths (cont’d) • Flexibility, extensibility – Source code available to users – Allows

Linux Strengths (cont’d) • Flexibility, extensibility – Source code available to users – Allows technically able folks to modify and extend the system the way they want • Open source – Faster and better software testing and refinement process - large number of software authors and beta testers • Linux is “free” – Acquired with little amount money • Generally handles network connections better than Windows – Developed by a team of programmers over the Internet; networking features given high priority – Supports most of the major protocols, and quite a few of the minor ones Supplementary Slides 2 6

Linux Weaknesses • Is Linux trustworthy? – How can something that is free also

Linux Weaknesses • Is Linux trustworthy? – How can something that is free also be reliable? • Installation & use – Can be difficult to install particularly for users who are not familiar with Unix commands – Can be difficult for casual users to operate – Documentation can be spotty • Inconsistent User Interface – Because of different design goals, no consistency enforced among the various programs and utilities included in a standard Linux distribution. • Replication of packages – For example, a distribution may contain Mail Transfer Agents: sendmail, smail, qmail, and exim • Lack of commercial applications – Not many applications are available for Linux on the desktop Supplementary Slides 2 7

Linux Distributions • The Linux kernel does not provide the full functionality of a

Linux Distributions • The Linux kernel does not provide the full functionality of a commercial OS • A Linux distribution typically has the kernel as its core with many other tools like – – – Networking utilities System administration tools Installation and documentation packages Graphical user interfaces Etc • Most of the added system utilities are drawn from the GNU project of the FSF – Linux distributions often called GNU/Linux OS • There are many Linux distributions available Supplementary Slides 2 8

Popular Linux Distributions • Red Hat Linux - www. readhat. com – The most

Popular Linux Distributions • Red Hat Linux - www. readhat. com – The most widely used distribution in the world – Main goal was to provide an easy-to-install, pre-configured system that comes complete with many applications • Open. Linux - www. calderasystems. com – The first to provide a fully graphical installation procedure – Aimed at Business users. Produced by Caldera Systems • Mandrake - www. linux-mandrake. com – Built on Red Hat Linux – Additions include installation procedure in many languages • Stampede - www. stampede. com – A distribution optimized for speed Supplementary Slides 2 9

Popular Linux Distributions • Debian - www. debian. org – Debian does not have

Popular Linux Distributions • Debian - www. debian. org – Debian does not have company behind it: created and maintained by developers of free software – Primary goals are provision of an easy upgrade technique and high-secure components • Slackware - www. cdrom. com – One of the first Linux distributions; still maintained by its original creator, Patrick Volkerding – Probably the second-best known Linux distribution • Su. SE - www. Su. SE. com – The leading German distribution - with a huge collection of packages – Full installation requires > 4 GB Supplementary Slides 2 10

Which Distribution to Use? • All Linux distributions do more-or-less the same things •

Which Distribution to Use? • All Linux distributions do more-or-less the same things • Choice is sometimes a matter of preference • Linux newbies – Best served by Xandros, Su. SE, Fedora, Mandrake, or possibly Red Hat • Experienced administrators – Able to cope with any of the Linux distributions. • Non-x 86 computers – For a non-Intel computer, you must select an appropriate distribution. – For Power. PC (Macintosh) systems, your main choices are Mandrake 9. 1, Su. SE 7. 3, Debian 3. 0 Supplementary Slides 2 11

The Shell • While the kernel interacts with the hardware and other software, the

The Shell • While the kernel interacts with the hardware and other software, the shell interacts with the user and the kernel • A shell is a program that provides the traditional, textonly user interface for Unix-like operating systems. • Primary function: read and execute commands – Makes it easy for users to launch programs and work with files • The shell derives its name from the fact that it is an outer layer of an operating system. • Every Unix-like operating system has at least one shell program, and most have several. Supplementary Slides 2 12

Common Shells • sh (the Bourne Shell) is the original Unix shell, and it

Common Shells • sh (the Bourne Shell) is the original Unix shell, and it is still in widespread use today. – Written by Stephen Bourne at Bell Labs in 1974 – Missing functions expected: file name completion, command editing, command history etc • csh or C shell: the syntax of this shell resembles that of the – Syntax similar to that of the C programming language. – Sometimes asked for by programmers. • tcsh or Turbo C shell: – A superset of the common C shell – Enhancing user-friendliness and speed • ksh or the Korn shell: sometimes appreciated by people with a UNIX background. – A superset of the Bourne shell – Proprietary, written by David Korn • bash (Bourne-again shell) - the default shell on Linux. – Has many more commands than sh, making it a powerful tool for advanced users. Supplementary Slides 2 13

Editors • Everyone needs a text editor – Pick one and learn how to

Editors • Everyone needs a text editor – Pick one and learn how to use it well • People are fanatical about their editor – No single best editor? • Several choices available: – vi Standard UNIX editor – Emacs Extensible, Customizable Self. Documenting Display Editor – pico Simple display-oriented text editor – The XEDIT-like editor – Xedit X windows text editor – Nedit X windows Motif text editor Supplementary Slides 2 14

Commands • See P. Baumann slides Supplementary Slides 2 15

Commands • See P. Baumann slides Supplementary Slides 2 15

Introduction to Makefiles • Managing a project consisting of many source files can be

Introduction to Makefiles • Managing a project consisting of many source files can be tedious • For example, consider a project with tens of files – source files, header files and libraries all of which may change during development • How do we know which files to recompile or relink with when some files change? • Fortunately, Linux provides a tool, the make program, that greatly simplifies this • make keeps a record of dependencies between files – Recompiles/relink only those files that changed since the last update • Thus, instead of managing these tasks manually, make can be your automatic dependency manager – gives you more time to do other important things Supplementary Slides 2 16

Introduction to Makefiles (cont’d) • make is best suited for C programming – can

Introduction to Makefiles (cont’d) • make is best suited for C programming – can be used with any programming language whose compiler can be run with a shell command • It has knowledge of how compilers work and can sometimes figure things out for itself (see later) • make generates commands using a description file known as a makefile. – These commands are then executed by the shell • make expects the file name to be Makefile or makefile • The makefile is basically a set of rules for make to follow to do its job • The major elements of a makefile are: – – – Dependency lines or rules Targets Dependents Macros (user-defined and internal) Comments Supplementary Slides 2 17

A Sample Makefile CC = mpicc FC = mpif 77 # SOURCE CODE SRC=inner.

A Sample Makefile CC = mpicc FC = mpif 77 # SOURCE CODE SRC=inner. c OBJ=inner. o inner: $(OBJ) $(CC) -c $(SRC) $(CC) -o $@ $(OBJ) run: make inner mpirun -np 4 inner clean: rm -f *. o *% *~ a. out inner Supplementary Slides 2 18

Components of the Makefile • The first two and the last two of the

Components of the Makefile • The first two and the last two of the following lines are macros: CC = mpicc FC = mpif 77 # SOURCE CODE SRC=inner. c OBJ=inner. o • The middle line above, starting with #, indicate make comments • Macro names are traditionally given in uppercase letters – The macro value (at the right of the equality) can be a file name, a directory, a program to execute or just about anything • Macros can have empty right-hand sides (assigned the null string) – make ignores undefined macros and those with null string values • Macros are referenced by prefixing them with dollar sign, as in $(SRC) • Macros can include other macros as in: LFLAGS = -L$(PVM_ROOT)/lib/$(PVM_ARCH) Supplementary Slides 2 19

Components of the Makefile (cont’d) • A makefile consists of entries like: inner: $(OBJ)

Components of the Makefile (cont’d) • A makefile consists of entries like: inner: $(OBJ) $(CC) -c $(SRC) $(CC) -o $@ $(OBJ) • The first line of an entry is the dependency line consisting of a target and dependents – The target is at the left of the colon (inner in this example) and the dependents to the right (inner. c in this example) • The second line is one or more command lines, which tell make what to do if a dependent is newer than the target • The syntax of a makefile requires that each command line must be indented using a tab. • A dependency line can have a series of commands associated with it, like: run: make inner mpirun -np 4 inner Supplementary Slides 2 20

Using the Makefile • Given the above makefile and assuming you are in the

Using the Makefile • Given the above makefile and assuming you are in the directory where it was saved (as Makefile or makefile): sahalu@linux>make inner mpicc -c inner. c -o inner. o • The above command tells Linux that you want to create a new version of the executable program inner – Notice how the macros are expanded and the commands issued to the shell for execution • inner is referred to as the target of this make operation • The object file(s) that are linked together to create the executable are known as the dependents – The only object here is inner. o referenced as $(OBJ) • The source code files that are compiled to create an object files are also its indirect dependents – The only source file here is inner. c Supplementary Slides 2 21

Using the Makefile (cont’d) • Observe the targets run and clean carefully in our

Using the Makefile (cont’d) • Observe the targets run and clean carefully in our example makefile – They both have no dependents – run is used to call make and to initiate mpirun • When a target has no dependents, make executes the supplied commands – provided there is no file with the same name as the target in the current directory • If all the dependencies of a target, are up to date, make does nothing except inform you of the following: sahalu@linux>make target ‘target' is up to date • You can supply more than one target to make at the same time: sahalu@linux>make run clean • If you supply a target that does not exist, you get: sahalu@linux>make ics make: *** No rule to make target `ics'. Supplementary Slides 2 Stop. 22

Using Makefiles • Note that make executes each command line associated with a rule

Using Makefiles • Note that make executes each command line associated with a rule as if the command had its own shell. • Thus, the command cd somewhere mv *. c anotherwhere may not behave the way you may have intended. • Use the following syntax to remedy such situations: dependency line command 1; command 2; command 3; . . . • or dependency line command 1; command 2; command 3; • Note that if you use a backslash to continue a line, as above, the backslash must be the last character before the end-of-line character. Supplementary Slides 2 23

Internal Macros • make has internal macros that it recognizes for commonly used commands.

Internal Macros • make has internal macros that it recognizes for commonly used commands. – The C compiler is defined by the CC macro, and – The flags that the C compiler uses are stored in the CFLAGS macro. • Two other internal macros are $@ and $? – The $@ macro always denotes the current target; – The $? macro refers to all the dependents that are newer than the current target. – Both of these macros can only be used within command lines. • make knows that C compilers compile files with. c suffixes, and generate files with. o suffixes. • This knowledge is encapsulated in a suffix rule: – make examines the suffix of a target or dependent to determine what it should do next. Supplementary Slides 2 24

Suffix Rules • The default suffix rules are as follows: . SUFFIXES: . o.

Suffix Rules • The default suffix rules are as follows: . SUFFIXES: . o. c. s. c. o: ${CC} ${CFLAGS} -c $<. s. o: ${AS} ${ASFLAGS} -o $@ $< • First line: a dependency line stating the suffixes that make should try to find rules for if none are explicitly written in the makefile. • Second line: compile each. c file whose corresponding object file (. o) is out of date. • Third rule is a similar directive to rule 2 but for assembler files. • The new macro $< has a similar role to that of the $? directive, but can only be used in a suffix rule. – It represents the dependency that the rule is currently being applied to. Supplementary Slides 2 25

Makefile 2 someonehappy: main. o dothis. o itquick. o  /usr/happy/lib/likeatree. a cc -o

Makefile 2 someonehappy: main. o dothis. o itquick. o /usr/happy/lib/likeatree. a cc -o someonehappy main. o dothis. o itquick. o /usr/happy/lib/likeatree. a main. o: main. c cc -c main. c dothis. o: dothis. c cc -c dothis. c itquick. o: itquick. s as -o itquick. s fresh: rm *. o maybe. h: yes. h no. h cp yes. h no. h /users/sue/ Supplementary Slides 2 26

Makefile 2 with Macros CC = /usr/bin/cc AS = /usr/bin/as OBJS = main. o

Makefile 2 with Macros CC = /usr/bin/cc AS = /usr/bin/as OBJS = main. o dothis. o itquick. o YN = yes. h no. h LIB_FILES = /usr/happy/lib/likeatree. a someonehappy: ${OBJS} ${LIB_FILES} ${CC} -o someonehappy ${OBJS} ${LIB_FILES} main. o: main. c cc -c main. c dothis. o: dothis. c cc -c dothis. c itquick. o: itquick. s ${AS} -o itquick. s fresh: rm *. o maybe. h: ${YN} cp yes. h no. h /users/sue/ Supplementary Slides 2 27

Makefile 2 with Internal Macros OBJS = main. o dothis. o itquick. o YN

Makefile 2 with Internal Macros OBJS = main. o dothis. o itquick. o YN = yes. h no. h LIB_FILES = /usr/happy/lib/likeatree. a someonehappy: ${OBJS} ${LIB_FILES} ${CC} -o $@ ${OBJS} ${LIB_FILES} main. o: main. c cc -c $? dothis. o: dothis. c cc -c $? itquick. o: itquick. s ${AS} -o $@ $? fresh: rm *. o maybe. h: ${YN} cp $? /users/sue/ Supplementary Slides 2 28

Makefile 2 with Suffix Rules OBJS = main. o dothis. o itquick. o YN

Makefile 2 with Suffix Rules OBJS = main. o dothis. o itquick. o YN = yes. h no. h LIB_FILES = /usr/happy/lib/likeatree. a someonehappy: ${OBJS} ${LIB_FILES} ${CC} -o $@ ${OBJS} ${LIB_FILES} fresh: rm *. o maybe. h: ${YN} cp $? /users/sue/ Supplementary Slides 2 29