Unix operating system


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Unix operating system

  1. 1. UNIX OPERATING SYSTEM Unix operating systems are widely used in servers, workstations, and mobile devices. TheUnix environment and the client–server program model were essential elements in thedevelopment of the Internet and the reshaping of computing as centered in networks rather thanin individual computers. Unix systems are characterized by various concepts: the use of plain text for storing data;a hierarchical file system; treating devices and certain types of inter-processcommunication (IPC) as files; and the use of a large number of software tools, small programsthat can be strung together through a command line interpreter using pipes, as opposed to using asingle monolithic program that includes all of the same functionality. These concepts arecollectively known as the Unix philosophy. The microkernel concept was introduced in an effort to reverse the trend towards largerkernels and return to a system in which most tasks were completed by smaller utilities. In an erawhen a "normal" computer consisted of a hard disk for storage and a data terminal for input andoutput (I/O), the Unix file model worked quite well as most I/O was "linear". However, modernsystems include networking and other new devices. As graphical user interfaces developed, thefile model proved inadequate to the task of handling asynchronous events such as thosegenerated by a mouse, and in the 1980s non-blocking I/O and the set of inter-processcommunication mechanisms was augmented (sockets, shared memory, queues, semaphores), andfunctionalities such as network protocols were moved out of the kernel. A Unix kernel — the core or key components of the operating system — consists ofmany kernel subsystems like process management, memory management, file management,device management and network management.Each of the subsystems has some features: Concurrency: As Unix is a multiprocessing OS, many processes run concurrently to improve the performance of the system. Virtual memory (VM): Memory management subsystem implements the virtual memory concept and a user need not worry about the executable program size and the RAM size. Paging: It is a technique to minimize the internal as well as the external fragmentation in the physical memory. Virtual file system (VFS): A VFS is a file system used to help the user to hide the different file systems complexities. A user can use the same standard file system related calls to access different file systems.The kernel provides these and other basic services: interrupt and trap handling, separationbetween user and system space, system calls, scheduling, timer and clock handling, filedescriptor management.
  2. 2. Unix Architecture:Here is a basic block diagram of a UNIX system:The main concept that unites all versions of UNIX is the following four basics: Kernel: The kernel is the heart of the operating system. It interacts with hardware and most of the tasks like memory management, tash scheduling and file management. Shell: The shell is the utility that processes your requests. When you type in a command at your terminal, the shell interprets the command and calls the program that you want. The shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are most famous shells which are available with most of the Unix variants. Commands and Utilities: There are various command and utilities which you would use in your day to day activities. cp, mv, cat and grep etc. are few examples of commands and utilities. There are over 250 standard commands plus numerous others provided through 3rd party software. All the commands come along with various optional options. Files and Directories: All data in UNIX is organized into files. All files are organized into directories. These directories are organized into a tree-like structure called the filesystem.
  3. 3. System Bootup:If you have a computer which has UNIX operating system installed on it, then you simply needto turn on its power to make it live.As soon as you turn on the power, system starts booting up and finally it prompts you to log intothe system, which is an activity to log into the system and use it for your day to day activities.Login Unix:When you first connect to a UNIX system, you usually see a prompt such as the following:To log in: 1. Have your userid (user identification) and password ready. Contact your system administrator if you dont have these yet. 2. Type your userid at the login prompt, then press ENTER. Your userid is case-sensitive, so be sure you type it exactly as your system administrator instructed. 3. Type your password at the password prompt, then press ENTER. Your password is also case-sensitive. 4. If you provided correct userid and password then you would be allowed to enter into the system. Read the information and messages that come up on the screen something as below.SHELL SCRIPT A shell script is a script written for the shell, or command line interpreter, of an operatingsystem. It is often considered a simple domain-specific programming language. Typicaloperations performed by shell scripts include file manipulation, program execution, and printingtextProgrammingMany modern shells also supply various features usually found only in more sophisticatedgeneral-purpose programming languages, such as control-flow constructs, variables, comments,arrays, subroutines, and so on. With these sorts of features available, it is possible to writereasonably sophisticated applications as shell scripts. However, they are still limited by the factthat most shell languages have little or no support for data typing systems, classes, threading,complex math, and other common full language features, and are also generally much slowerthan compiled code or interpreted languages written with speed as a performance goal.
  4. 4. Advantages and disadvantagesOften, writing a shell script is much quicker than writing the equivalent code in otherprogramming languages. The many advantages include easy program or file selection, quickstart, and interactive debugging. A shell script can be used to provide a sequencing and decision-making linkage around existing programs, and for moderately-sized scripts the absence of acompilation step is an advantage. Interpretive running makes it easy to write debugging code intoa script and re-run it to detect and fix bugs. Non-expert users can use scripting to tailor thebehavior of programs, and shell scripting provides some limited scope for multiprocessing.Command line arguments to scriptsWhen you start a script from your interactive login shell, you can provide arguments to thatscript on the command line. These are automatically turned into variables that can be used insidethe script.If the command line contains filename wildcard characters, variable substitution references, orcommand substitution references, those are expanded or substituted first. Then the command linestring is broken into separate arguments at blanks, except that a quoted string can containembedded blanks.You refer to these arguments as separate variables within the script itself by using the dollar sign(variable substitution operator) followed by an integer number, for example, cp $1 $2This statement inside a shell script would run the cp program with the first "argument" to theshell script (first word on the command line that started the shell script) passed as the name ofthe file to copy via $1, and the second argument to the shell script passed as the name of the newcopy via $2.The entire list of command line arguments can be referenced as one string with the syntax $*Making and setting your own variables in a scriptIn addition to the command line arguments, the shell maintains a table of other user-created orspecial purpose variables in memory. Each variable has a name and a value. Names - up to 20 letters or digits (start with letter) - case matters! Values are strings of characters or digits of arbitrary length without any intrinsic "type". They are treated as character strings or numeric values, depending upon how they are used.It is also possible to treat any variable as an array of words and access each word separately (seedetailed documentation on the C-shell).
  5. 5. Certain variable names are reserved by the shell for special uses, such as path or term.You can create any number of variables.Using variables in the script"Variable substitution" is the process of replacing a reference to the name of a variable with itsactual value. This is how we use variables.The dollar sign ($) is the basic substitution operator when it is used as the prefix for a variablename. Anytime you use the dollar sign as the first letter of a word in a shell command, it willexpect the word to be the name of a variable. If you want the dollar sign to be interpreted as justa simple dollar sign, precede it wth the backslash () "escape" character. Here are the basicformats for variable substitution: $?nameThis tests whether the name variable exists. If the variable does exist, the shell substitutes thevalue 1 (one, true); if not, the value 0 (zero, false). Use this form if you are just using the variableas a flag. The result can be used in an if statement to conditionally execute some commands. $nameThis form causes the entire word list value of name to be substituted for the reference. If name isnot defined (was never set), you get an error. $#nameThis substitutes the number of words contained within the name variable. If the variable has anull value (that is, simply set as a "flag" variable), it substitutes zero. If the variable has neverbeen set, you get an error. $name[n]This substitutes the "nth" word (blank separated value) from the name variable. The squarebrackets are required to enclose the value n that specifies which word is wanted, and must followthe variable name with no intervening spaces. This is a way to treat a variable containing a multi-word value as an array of separate words. If you specify a word index value n that is greater thanthe actual number of words in the variable, you get an error.Examples: set a = ($b)Sets new variable a equal to the word list in existing variable b. echo $bEchoes (prints) the value of existing variable b to the standard output (terminal).Flow-of-control statments
  6. 6. if and foreach are the basic flow-of-control statements. There are more advanced ones namedswitch and while which are similar to the statements of the same name in the C language.ifThe if command allows you to conditionally execute a command or set of commands dependingupon whether some expression is true. There are two forms. if ( logical_expression ) command ... This form will execute command (which can have a long list of arguments) if the logical__expression is true. This expression can be one of the logical or file testing expressions described above. For example, you can test if a file whose name is stored in the shells built-in variable $1 (first argument to the shell script) exists as a plain file, and if so, make a backup copy of it with: if ( -f $1 ) cp $1 $1.bak This simple cp command will not work if given a directory to copy, which is why there is the test for a "plain" file. if ( logical_expression ) then block of commands - any number of lines to be executed if logical_expression is "true" (or has non-zero value). else another block of commands - any number of lines to be executed if logical_expression is "false" (or has value 0). endif This form allows you to execute more than one command if the expression is true. The then keyword must follow the logical_expression test on the same line, and the endif keyword must be on a line by itself to end the entire if command. The else statement is optional. If you use this, the else keyword must be on a line by itself. The following lines up to the endif are executed if the expression was false. The "blocks of commands" may in turn contain additional nested if commands. Just be sure that each if has a matching endif statement enclosed in the same block.Relational operators
  7. 7. -eq: equal to-ne: not equal to-ge: greater than or equal to-le: less than or equal to-gt: greater than-lt: less thanLogical operators!: not-a: and-o: or