Beruflich Dokumente
Kultur Dokumente
Operating System An Introduction History of Unix Unix fundamentals Text Processing Communication The Unix Environment Introduction to the Shell Programming Shell Variables Shell Meta characters Text Processing Program Development Tools Debugging Tools Programming Maintenance Tools
1.0
Introduction
An operating system is an important part of a computer system. You can view a computer system as being built from three general components: the hardware, the operating system, and the applications. The hardware includes pieces such as a central processing unit (CPU), a keyboard, a hard drive, and a printer. Applications are why you use computers; they use the rest of the system to perform the desired task (for example, play a game, edit a memo, send electronic mail). The operating system is the component that on one side manages and controls the hardware and on the other manages the applications. UNIX is an increasingly popular operating system. Traditionally used on minicomputers and workstations in the academic community, UNIX is now available on personal computers, and the business community has started to choose UNIX for its openness. Previous PC and mainframe users are now looking to UNIX as their operating system solution.
1.1
Objective
The objective of this lesson makes the learner aware of the fundamentals of UNIX operating system, which consists a broad range of topics from operating system and UNIX fundamentals. The fundamental concepts include text processing, communication, UNIX environment, and introduction to shell programming and program development and maintenance tools. Towards end of this lesson the student can get the basic knowledge about UNIX operating system.
1.2
1.2.1
Content
Operating System An Introduction
Page 1
Command Interpretation
Process Management
Operatin g System
Peripheral Management
Memory Management
1. Command Interpretation The Command Interpreter reads the commands entered by a user at the command prompt and translates the commands into instructions which the computers CPU can understand. 2. Process Management Process Management is required if CPU time. 3. Peripheral Management The Main function of the OS is the Peripheral Management, the communication between the peripheral devices and the CPU is overseen by the OS. 4. Memory Management The OS handles the job of allocating the memory for the various process running on the system. 1.2.2 History of UNIX a number of programs have to run parallelly. The OS has to ensure that no program gets more than its share of
Page 2
Distribution
of
The Unix Operating System can be broken down into three basic components, namely the Scheduler, the File System and the Shell. The Unix Scheduler The UNIX scheduler is a program that allows several users to access the system simultaneously. The scheduler shares computer resources among these users, allowing each a small slice of the computers processor. The UNIX Shell The shell is the UNIX systems command interpreter. It is a program that reads the lines typed in at the terminal and performs various operations. A shell performs two basic functions that is it acts as a command interpreter and as a programming language. As a command interpreter it is similar to DOS. As a programming interface it allows the user to process commands stored in shell scripts, this function is similar to batch files in DOS. The UNIX File System To organize data on to the disk, the UNIX operating system provides a File System. The File System allows grouping of similar files together, since if thousands of files are stored together it would be difficult to locate a single file. The Unix File System has a Hierarchical structure; therefore the files can be stored under directories. The directories are created to store files containing data of similar nature. The root directory will contain the bin, dev, var, etc, usr, home, and tmp directories. The following picture shows a sample file system:
Page 3
Figure 1.1: File System Getting Started In order to use the UNIX system, first the user has to login. To login to the Unix system the user needs to type in the user id in the login: prompt and then pressing the Enter key prompts for a password which the user has to type to enter into the Unix system. Login: test <ret> Password: **** $ Once the user has successfully logged in, the Unix system will indicate that it is ready to accept the command by displaying a dollar sign ($). If the user enters a wrong password then, the Unix system will prompt a message saying login incorrect and will display the login: prompt again for the user to re-enter the user id and password. Login: test Password : ****** Login incorrect Login: UNIX allows user to create their own files by using a command called cat. The cat command can also be used for appending content to an already existing file and also to view the content of a file. The following format is used for creating a file using cat command cat > filename To append text to an already existing file, the format is: cat >> filename To view the content of an already existing file, the format is: cat filename
Page 4
Text processing is one of the things which people spend most time doing on any computer. It is important to distinguish text editing from word processing. Normally word or WordPerfect are used for writing documents. UNIX has a word-like program called lyx, but most of the UNIX users do not use word processors. It is more common in the UNIX community to write all documents using a non formatting text editor. The user can edit a file by typing emacs myfile Emacs is the most powerful text editor that exists on any system. It is not a wordprocessor, it is not used for formatting printed documents, but it can be linked to almost any other program in order to format and print text. 1.2.5 Communication
Unix system allows a user at one terminal to interact with another user at some other terminal. Some of the commands used for interaction are discussed below. write command This command is used to send a message from one user to another user who is currently working on the system. This is a means of on-line communication because the recipient obtains the message immediately. write user [tty] The other users terminal beeps and displays a message. The other user can respond to the message, by invoking the write command and typing a message to the system. The conversation between the users can be terminated by pressing the ctrl+d command. news command Unix can communicate in off-line mode also by using the news command To send news to all users even if they are not logged in, the news command is useful. Only one file is created and all the users read that file. When the user logs on the contents of the news command are displayed on screen. news [-a][-n][-s][items] -a displays all items regardless of whether the message are already viewed or not. -n shows only the names of the current files. Page 5
mesg command The mesg command controls the display of messages on the screen. The user can decide whether a message can be received by the system or not. The syntax to restrict messages is mesg [n] [y] wall command This command is used to send messages to all users. The command is placed in the /etc directory. To invoke the wall command the full path name has to be specified. Example $/etc/wall Good morning every one message from administrator 1.2.6 Ctrl +d The UNIX Environment
UNIX operating systems structure consists of Kernel, Shell and tools and applications
H W Kernel Shell
Figure 1.1 Structure of UNIX System Kernel Kernel forms the core of the UNIX operating system. The Kernel interacts with the hardware. It is loaded into the memory when a system is booted. The functions of Kernel are: Managing the system resources. Allocating time for different users and processes. Deciding process priorities and performing them. Page 6
The shell is a command programming language that provides an interface to the UNIX operating system. Its features include control-flow primitives, parameter passing, variables and string substitution. Constructs such as while, if then else, case and for are available. Two-way communication is possible between the shell and commands. String valued parameters, typically file names or flags may be passed to a command. A return code is set by commands that may be used to determine control-flow and the standard output from a command may be used as shell input. The shell can modify the environment in which commands run. Input and output can be redirected to files and processes that communicate through pipes can be invoked. Commands are found by searching directories in the file system in a sequence that can be defined by the user. Commands can be read either from the terminal or from a file, which allows command created to be sorted for later use. 1.2.8 Shell Variables
Variables in shell scripts do not have associated data types. All variables in shell scripts are treated as character strings. Creating variables Variables can be created either in shell scripts or at the shell prompt. Any variable created within a shell script is lost when the script stops executing. A variable created at the prompt, however, will remain in existence until the shell is terminated. The format for creating a variable is: <variable name> =<value> Example Name=ram Page 7
This variable contains the system prompt, that is. the $ symbol. Changing the value of the ps1 variable can change the system prompt. Example $ps1=Hello <ret> Hello b. The PATH variable A list of filenames that are to be searched for Unix commands execution are contained in this variable. The echo command is used to display the content of the variable. c. The HOME variable
This variable contains the Home directory where the login shell is initially located after logging in. d. The LOGNAME variable This variable contains the users login name or user name. The contents of this variable cannot be changed by the user but can be displayed. e. The .Profile file
Some environmental variables like the HOME and the LOGNAME variable are set automatically each time the user logs in. The others, however, have to be set. The .profile file is used for this purpose. This file is a special shell script that is executed as soon as the user logs in. It is similar to the autoexec.bat batch file in DOS. Referencing Variables A variable is referenced as follows: Command ${variable name} The braces are optional, but the $ is essential. To assign value of one variable to another variable, the command would be: Variable1=$variable2
Page 8
The environment variable can be transferred to the child shell using the export command. The export command causes a copy of the variable name and values to be passed onto a child shell process. 1.2.9 Shell Meta characters
UNIX offers the facility to perform an operation on a set of files without having to list out the names of all the files on which the operation has to be performed. Page 9
Page 10
Page 11
This makefile is typically called makefile or Makefile by convention, although any file name will do. However, if the user uses a different name, the user has to supply the name as an argument whenever the make command is executed. Once this information has been described to make, make takes over and does the rest. Simply typing the command make causes the program to examine the makefile and regenerate the system according to the rules laid out in the file created by the user. The automatic method of program generation saves the user from the bother of having to keep track of the files the user has changed and also recompiling each one by the user itself. When one file is changed the associated file is also changed. By specifying this dependency in the makefile, make will take care of recompiling the necessary files whenever that particular file is changed. 1.2.12 Debugging Tools The most generally available debugger is dbx. Prerequisites for dbx The dbx debugger on one hand is a source level debugger. This means that even though it is running the object code, it is smart enough to direct to the statement in the source that has caused the problem in the object code. On the other hand it is a symbolic debugger that it is smart enough to tell the name and value of the variable on which the program is having its difficulties. In order to use the debuggers one must first compile the entire program with the g option. One should run the debugger on nonoptimized code only. Some of the subcommands given from within dbx include the following: Help Tell me what I may command. Run Execute the program. Print Display value of var. Where Print currently active procedures. Stop at line - suspended execution at line. Stop in proc - suspended execution in subprogram proc. Cont - Resume execution Edit - Invoke vi editor
Step Execute 1 line
Page 12
1.3
Revision Points
Operating System An operating system is a collection of system programs that together controls the operation of a computer system. The operating system along with hardware, application and other system softwares, and users constitute a computer system. It has two objectives. Firstly, an operating system controls computers hardware. The second objective is to provide an interactive interface to the user and interpret commands so that it can communicate with hardware. UNIX The UNIX operating system was developed at AT&T Bell Laboratories by Ken Thompson and Dennis Ritchie in 1969 and the early 1970s. UNIX is a multi-user system that supports networking and distributed file systems such as Sun Microsystems NFS (Network File System) or the Open Software Foundations implementation of the AFS (Andrew File System).UNIX highly portable and it now contains system components written in a common, well-known programming language that are easily recompiled to work on a variety of systems. UNIX file system The UNIX file system is a hierarchical, tree-structured namespace that is designed to help users organize and access files. The namespace consists of directories that hold files. The UNIX file system consists of the following: Disk based file systems Network file systems Pseudo file systems Page 13
1.5
Summary
An operating system (OS) is a collection of software programs that coordinates the operation of computer hardware and software. The Unix Operating System can be broken down into three basic components, namely the Scheduler, the File System and the Shell. The UNIX scheduler is a program that allows several users to access the system simultaneously. UNIX operating system structure consists of Kernel, Shell and tools and applications. UNIXs shell interacts with the user and the computer.
1.6
Terminal Exercises
1. The operating system that allows only one program to run at a time is __________. 2. Define Network file system. 3. List out the functions of kernel. 4. What are the features of shell programming? 5. Mention the use of wall command.
1.7
Supplementary Materials
1. Sumitabha Dass, Unix Concepts and Applications, Second Edition, TMH, 1998
Page 14
1.8
Assignments
1. Describe the directory structure of the UNIX file system. 2. Distinguish between absolute path names and relative path names. 3. Why UNIX systems become the favored operating systems for implementing the open systems philosophy?
1.9
1.11 Keywords
Operating System Shell Network File System (NFS) UNIX systems Kernel Andrew File System (AFS)
Page 15