UNIX PROGRAMMING 1 1 HISTORY OF UNIX In

  • Slides: 38
Download presentation
UNIX PROGRAMMING

UNIX PROGRAMMING

1. 1 HISTORY OF UNIX In 1965 MIT, GE, AT&T Bell Laboratories worked together

1. 1 HISTORY OF UNIX In 1965 MIT, GE, AT&T Bell Laboratories worked together in a project called MULTICS(Multiplexed Information & Computing System) to develop a multi user operating system. But, it is an failed attempt

PDP-7 UNICS OS On the basis of ideas acquired on MULTICS, Ken Thompson &

PDP-7 UNICS OS On the basis of ideas acquired on MULTICS, Ken Thompson & Dennis Ritchie developed an operating system called UNICS (Uniplexed Information and Computing System) on machine PDP-7, But, it is not portable

B C UNICS OS UNIX • To achieve portability, Thompson developed language , but

B C UNICS OS UNIX • To achieve portability, Thompson developed language , but did not yield expected results • At same time many researchers showed interested on UNIX Project(In 1970 UNICS became UNIX) • In 1973 Dennis Ritchie developed high level programming language called C

Assembly language 5% C 95% • Dennis Ritchie Completely rewrote the entire UNIX using

Assembly language 5% C 95% • Dennis Ritchie Completely rewrote the entire UNIX using C. • Around 95% of UNIX system was written in C and remaining was written in Assembly language • The details of UNIX implementation in C was made available through public paper. • Later on Ken Thompson & Dennis Ritchie was awarded with ACM Turing award

 • University of California at Berkeley(UCB) was interested in the UNIX operating system

• University of California at Berkeley(UCB) was interested in the UNIX operating system • The team at Berkeley was responsible for many important developments and utilities • Berkeley filled gaps that existed in AT&T’s UNIX and released their own version of UNIX called BSD-UNIX

Many variants to UNIX? • From Mid-1970’s there we have many variants of the

Many variants to UNIX? • From Mid-1970’s there we have many variants of the UNIX System • One of the reasons is AT& T & BSD giving their products for free of cost Any standards? • IEEE standards board has given set of rules called POSIX(Portable Operating System) • AT& T given standards called UNIX International(UI) • However, still there exist a large number of UNIX variants in the market

 • Earlier many variants to UNIX are commercial • Researcher Richard Stallman introduced

• Earlier many variants to UNIX are commercial • Researcher Richard Stallman introduced the society called Free software foundation to create GNU(Genuinely Not UNIX) • In 1991 LINUS Torvalds and his students used GNU to develop operating System MINIX later on its is called LINUX

 • LINUX operating system is available under GPL(General Public License) • Different flavors

• LINUX operating system is available under GPL(General Public License) • Different flavors of LINUX operating System

Registration to Certification CISCO Academy Linux Essentials https: //www. netdevgroup. com/online/courses/linux-essentials

Registration to Certification CISCO Academy Linux Essentials https: //www. netdevgroup. com/online/courses/linux-essentials

1. 2. WHAT IS UNIX? • UNIX is an multi user operating system •

1. 2. WHAT IS UNIX? • UNIX is an multi user operating system • Operating system is going to act as interface between software and hardware recourses • UNIX provides virtual computers to different users by creating simulated processors, multiple address space and so on

1. 2. 1 Salient Features of UNIX • UNIX is an multi user operating

1. 2. 1 Salient Features of UNIX • UNIX is an multi user operating system-ability to concurrent execution of two are more processes • UNIX is an multi user operating system-ability to support more than one user login in to system simultaneously • UNIX provides virtual computers to different users by creating simulated processors, multiple address spaces

 • UNIX is an multi tasking operating system-ability to run different tasks belong

• UNIX is an multi tasking operating system-ability to run different tasks belong to one user • UNIX operating system is highly portable • Users can directly connect to same machine or may be connected to different machine s that are internet connected. • UNIX offers solid security at various levels(at startup, user level, file level) • UNIX has good library of utilities and commands

 • One of the very important key feature is , UNIX treats every

• One of the very important key feature is , UNIX treats every thing, including memory and I/O devices as files

1. 3 UNIX Components UNIX has following major components • The Kernel • The

1. 3 UNIX Components UNIX has following major components • The Kernel • The Shell • The File System + Utility programs

The Kernel • • • Kernel is the heart of any UNIX operating system

The Kernel • • • Kernel is the heart of any UNIX operating system mostly written in C It is collection of programs that is embedded on the hardware It is loaded in to the memory as soon as system booted It is only component that can directly communicate with hardware It manages , all system resources • • • Memory I/O CPU allocation Process priorities IPC Many other such tasks • Earlier all programs are part of kernel and moved in to memory during boot, such kernel are called Monolithic kernel • However, these days only required module is moved in to kernel • Kernel with on small set of kernel programs is called a micro kernel • Other programs are moved in and out based on requirement

The File System • UNIX treats everything as a file including hardware devices •

The File System • UNIX treats everything as a file including hardware devices • All file and directories in UNIX system are organized in an inverted tree-like hierarchical structure • This structured arrangement of all the files and directories is known as file system • UNIX supports both local file system and distributed file system

The shell • A shell is program that sits on top of kernel and

The shell • A shell is program that sits on top of kernel and acts as an interface between the users and the kernel • Shell is command interpreter or processor • The shell presents a command line prompt usually with symbols $, #, % at which user can type the command • After accepting user commands, user command is passed and identifies the executable in PATH • Shell has programming capability on its own , we can write programs like shell programs • Shell programs are shell scripts Types of shells:

Bourne Shell(sh) • • Developed by Stephen Bourne at AT&T labs The most common

Bourne Shell(sh) • • Developed by Stephen Bourne at AT&T labs The most common shell available in on AT& T UNIX operating system It is first major shell developed & available in almost all UNIX system Two goals 1)Command line interpreter and 2)Scripting The C Shell(csh) • Developed by Bill joy at UCB as part of the BSD release • The objective of achieving a scripting language similar to C programming language. • It is called C shell because it syntax and usage is very similar to C programming language • It is not available in all machines • Programs written in C shell are not compatible with Bourne shell • One advantage over Bourne shell is, it executers process in background Korn Shell(ksh) • • • Developed by David Korn at AT& T labs It is built on the Bourne shell It also incorporated feature of C shell At present it is one of widely used shells It can run Bourne shell scripts with out any modifications

Bourne again Shell(sh) • It was written by Brian Fox for the GNU project

Bourne again Shell(sh) • It was written by Brian Fox for the GNU project as a pre-software replacement for the Bourne Shell. • Bash stands for Bourne Again Shell and it is the default shell on many Linux distributions • It is also a sh-compatible shell and offers practical improvements over sh • Command line editing • Job Control • Unlimited size command history • Shell Functions and Aliases • Unlimited size Indexed arrays • Integer arithmetic in any base from two to sixty-four

Shell as a command processor Shell act as 1. Command Processor 2. Small programming

Shell as a command processor Shell act as 1. Command Processor 2. Small programming language Shell as command processor, when interpreting a command at it command prompt, the shell follows one or more following steps 5)Display result in the prompt 1)Read the command 2)Interpret (or) parses the command 4)Execute the command 3)Find the PATH of the required command • Evaluate variable prefixed with $ symbol • Command with in back quotes are executed and their output is substituted • Check for I/O redirection • Check for wildcard characters like *, ? , []

1. 4 USING UNIX • To use UNIX, one has to get in to

1. 4 USING UNIX • To use UNIX, one has to get in to the UNIX environment • The process of getting into the UNIX operating system is known as logging in to the system • As soon as the system booted , a daemon process will get started e. g init • The daemon processes are background processes that started at boot time and continue to run up to system shut down

The sequence of events in a complete login process can be listed as follows

The sequence of events in a complete login process can be listed as follows 1. The users enter his login name at he getty’s login prompt 2. The getty executes the login program with the login name as the input argument 3. The login program requests for password and validates against /etc/passwd After successful login 1. The login program set up TERM environment variable and runs shell 2. The shell executes the appropriate startup files like. profile 3. The shell then prints a prompt, ususaly with different symbols an wait for further input • $(dollar) • % C (percent) • # (hash) Bourne shell and Koran shell, bash shell Any shell root 4. When the user completes the session , he will come out of the UNIX environment called logging out 5. As soon as user logs out, the control is returned to init daemon Note: The TERM environment variable tells programs what type of terminal you use. . profile is profile of UNIX user

1. 5 COMMANDS IN UNIX § UNIX has large number of commands § Some

1. 5 COMMANDS IN UNIX § UNIX has large number of commands § Some general features of a UNIX command • UNIX command is program written to perform certain specific action • All UNIX commands are written in lower case letters e. g. cat, ls, who, mkdir • UNIX commands are cryptic e. g. cat stands for concatenation • UNIX commands can have zero or more arguments e. g. ls-l • UNIX commands can also have 1. Format specifiers indicated by “+” e. g. $ date+%m 08 2 Options indicated by “-” e. g. $ ls –l -rw-------. 1 root 1547 Sep 8 2014 anaconda-ks. cfg -rwxr-xr-x. 1 root 8960 Aug 15 07: 30 a. out • Sometimes UNIX commands with its arguments may not fit in a single line(80 characters). In such case shell prompt may overflow, indicated by special symbol “>” • UNIX command can be killed by using ctrl+c • UNIX commands can be executed in the backgroung e. g: ls&

1. 5. 1 Types of UNIX Commands There are two types of UNIX commands

1. 5. 1 Types of UNIX Commands There are two types of UNIX commands 1) External Commands 2) Internal Commands External Commands Ø A command with an independent existence I the form a separate file is external command Ø For such commands, shell searches the command programs in system variable PATH Example: cat, ls, who Internal Commands Ø Internal commands do not have independent existence Ø These commands are part of another program Example: echo [root@host-2 -105 ~]# type echo is a shell builtin [root@host-2 -105 ~]# type cat is /usr/bin/cat

1. 6 Some Basic Commands 1)man command • man command provides complete details of

1. 6 Some Basic Commands 1)man command • man command provides complete details of UNIX command or utility • It is an interface to the on-line reference manuals Examples: $man pwd Usage: $ man command

 The details of man command can be identified by using $man e Forward

The details of man command can be identified by using $man e Forward one line (or N lines). y Backward one line (or N lines). f Forward one window b Backward one window Type h for help Type q to quit man page For Certain commands the output is very large and it scrolls of fast & user will be able to see only last screen. In all such cases the output can be piped to more command $ man who | more The output of man who will be redirected to the more command using pipe character(|)

2)The who command provides a list of all the current users in the three

2)The who command provides a list of all the current users in the three column format 1 st Column: Name of the user 2 nd Column: Device name E, g. • The pts/0 is telling you which "pseudo terminal" the user is logged in on. • : 0 and is referred to as the actual "console“ Option –H provides header

 Option –u provides idle time Command who am I (or) who –m can

Option –u provides idle time Command who am I (or) who –m can be used to know self login details 3)The cat command Used to create small UNIX files by writing in the command line Input operation is terminated by using <ctrl-d>

 Use cat>> filename to append content to file Use cat < or cat

Use cat>> filename to append content to file Use cat < or cat command to display file content

4)The date command User can display the current date along with the time nearest

4)The date command User can display the current date along with the time nearest to the seconds The date can be used along with format specifiers to print date in specific manner. Each format specifier is preceded with symbol “+” %m –month %h –month in word %y-last two digits of year %Y- four digits of year %d-day in dd format %D- day in mm/dd/yy format %H-HOURS %M-MINUTES %S-Seconds

The banner command sudo apt-get install sysvbanner

The banner command sudo apt-get install sysvbanner

The calendar command -A num Print lines from today and next num days (forward,

The calendar command -A num Print lines from today and next num days (forward, future). -B num Print lines from today and previous num days (backward, past).

The spell and ispell command Spell check based on American Usage sudo apt-get install

The spell and ispell command Spell check based on American Usage sudo apt-get install spell Spell check based on British Usage, is by -b

The lock command • • Used to lock the terminal session by given time

The lock command • • Used to lock the terminal session by given time By default, the user can lock it for 30 minutes The locking period can be changed by assigning a different value to DEFLOGOUT When the lock command is given the terminal ask for pass word twice • A numeric option of range can provided for lock time • The locked terminal can be unlocked by re-entering the password with terminal that was locked earlier

bold=$(tput bold) echo "this is ${bold}bold” u=$(tput smul) echo "this is ${u}Underline" u=$(tput blink)

bold=$(tput bold) echo "this is ${bold}bold” u=$(tput smul) echo "this is ${u}Underline" u=$(tput blink) u=$(tput rev) Start reverse video http: //linuxcommand. org/lc 3_adv_tput. php