Professional Documents
Culture Documents
Lecture 1
Operating System
• The operating system is the most important program that runs
on a computer.
• Operating systems provide a software platform on top of which
other programs, called application programs, can run.
• The operating system (OS) is the first thing loaded onto the
computer -- without the operating system, a computer is useless.
• Operating systems can now be found on many of the devices
we use every day, from cell phones to wireless access points.
• We can call it as Resource Manager for Computer hardware.
• Allocation of resources to Users.
• Easy interaction with Computer Resources like Input output
device, File System etc.
Purpose of Operating System
• The purpose of an operating system is to organize and control
hardware and software so that the device it lives in behaves in a
flexible but predictable way.
• Three main purposes of an operating system are:
–To provide an environment for a computer user to execute programs on
computer hardware in a convenient and efficient manner.
– To allocate the separate resources of the computer as needed to solve
the problem given. The allocation process should be as fair and efficient
as possible.
– As a control program it serves two major functions: (1) supervision of
the execution of user programs to prevent errors and improper use of
the computer, and (2) management of the operation and control of I/O
devices.
Function of Operating Systems
• Operating System Services
– Controlling the execution of processes by allowing their
creation, termination or suspension.
– Scheduling processes fairly for execution on the CPU.
Processes share the CPU in a time-shared manner.
– Allocating main memory for an executing process.
– Allocating secondary memory for efficient storage and
retrieval of user data.
– Allowing processes controlled access to peripheral devices
as terminals, tape drives, disk drives, and network devices.
Definition
What is an Operating System?
• An operating system (OS) is a resource
manager. It takes the form of a set of software
routines that allow users and application
programs to access system resources (e.g. the
CPU, memory, disks, modems, printers
network cards etc.) in a safe, efficient and
abstract way.
Classification of Operating System
Operating systems can be classified as follows:
• Multi-User Operating System: Multi-User OS allows two or more users to
run programs at the same time.
• Multi-tasking Operating Systems: Multi-tasking OS allows more than one
program to run concurrently.
• Distributed Operating Systems: In a distributed system, software and data
may be distributed around the system, programs and files maybe stored
on different storage devices which are located in different geographical
locations and maybe accessed from different computer terminals.
• Real Time Operating System: A real-time operating system is a
multitasking operating system which executes only real-time applications.
The main objective of real-time OS is their quick to events.
• Embedded Operating System: Embedded operating systems are designed
to be used in embedded computer systems. They operate on small
machines like PDAs with less autonomy. They are able to operate with a
limited number of resources.
What is Unix?
• The UNIX operating system is a set of programs that
act as a link between the computer and the user.
• Unix is a powerful, multi-user environment that has
been implemented on a variety of platforms.
• The UNIX operating system comprises three parts:
The kernel, the standard utility programs, and the
system configuration files.
• The UNIX system is full duplex: the character you
type on the keyboard are sent to the system, which
sends them back to the terminal to be printed on
screen.
Unix System
• The computer programs that allocate the system resources
and coordinate all the details of the computer's internals is
called the operating system or kernel.
• Users communicate with the kernel through a program known
as the shell. The shell is a command line interpreter; it
translates commands entered by the user and converts them
into a language that is understood by the kernel.
• There are various Unix variants available in the market. Solaris
Unix, AIX, HP Unix and BSD are few examples. Linux is also a
flavor of Unix which is freely available.
• UNIX is a multiuser system and multitasking operating
system.
Unix History
• Unix was created in 1969 by Dennis Ritchie (also the
creator of C programming language) & Ken Thompson.
• Slowly, an open operating system standardization was
thought of that led to the birth of POSIX (Portable
Operating System Interface). The first POSIX standard
was published in 1988.
• In 1991,LinusTorvalds developed the 1st version of this
new OS ( LINUX ) that was powered by Intel's 80386
microprocessor (a 32 bit microprocessor launched in
1985)
Unix and Linux
• Linux is a “Unix-like" operating system. Unix (POSIX)
actually is a standard by which a Unix-like operating
system should conform to.
• Linux mostly conforms to the POSIX standard.
• Almost all companies run Linux, BSD, Solaris or some
other Unix-like variant.
• You can configure them using different mechanisms
but the basic commands like ls, cd, chmod, chown,
find, etc work pretty much the same on all Unix
flavour.
Linux Features
• Open Source Free Operating System
• Multiuser OS
• Multitasking
• Users and Groups of defined
• User and Group mapped to IDs
• Special User Root has unrestricted privileges
Pros And Cons of Linux
• Pros
– Linux is free license.
– Linux is portable to any hardware platform.
– Linux is secure and versatile.
– Linux OS and most Linux application have very short
debug times.
• Cons
– There are far too many different distributions.
– Linux is not very user friendly and confusing for beginners.
– Is an open source product trustworthy.
Unix Architecture
All Components of typical OS
• Kernels
– Core of OS. Manages and controls hardware and File Systems.
– First part of OS to load into memory during booting.
– It provides basic services for all other parts of the OS like Application
Programs, Utilities through system calls
– Programs such as the shell and editors (ed and vi) interact with kernel by
invoking a well defined set of system calls.
• Shells
– Outermost part of OS and which interacts with User Commands.
– A program that provides an interface to access the services that are provided
by the OS.
– Examples are:
• COMMAND.COM of MS-DOS.
• Bourne shell of UNIX
• Bash (Unix shell) and Z shell
• Application Programs
– Useful programs like editors, office, browser etc.
Block Diagram
Hardware
Kernel
Shell
Application
programs/Users
Shell Scripting
• The shell works as an interpreter. Shell scripting is the process
of writing a "script" file for the shell.
• A script file typically contains the code that shall be interpreted
by the shell. The code should be written in the language that the
shell can understand.
For example:
– Bash is a shell.
– Bash understands a scripting language that can be called "bash
scripting language"
– You can write a bash script, which is a file that contains code written in
that bash scripting language. This process is called "shell scripting".
– You can execute the bash script by running bash and telling it to
interpret the script.
System Bootup
• If you have a computer which has UNIX
operating system installed on it, then you
simply need to 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 into the system, which is an activity to log
into the system and use it for your day to day
activities.
Login Unix
• The login program is used to establish a new session with
the system.
• It is normally invoked automatically by responding to the
"login:" prompt on the user's terminal.
• 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.
• Type your password at the password prompt, then press
ENTER. Your password is also case-sensitive.
• If you provided correct userid and password then you
would be allowed to enter into the system.
Example
• Read the information and messages that come up on the
screen something as below.
login : amrood
amrood's password:
Last login: Sun Jun 14 09:32:32 2009 from 62.61.164.73
$
• You would be provided with a command prompt ( sometime
called $ prompt ) where you would type your all the
commands.
• With correct credentials you would be allowed to enter the
system
• Logout = Ctrl-d ( proper way). Or turn off the terminal
Change Password
• All Unix systems require passwords to help ensure
that your files and data remain your own and that the
system itself is secure from hackers and crackers.
• Here are the steps to change your password −
– To Change the password type “ passwd” at terminal
$ passwd press enter
Old password … “type your old password”. Press en
New password..” type your new password”. Press enter
Retype password..’ retype your new password” press enter
Password is not visible and case sensitive
Example
$ passwd
Changing password for amrood
(current) Unix password:******
New UNIX password:*******
Retype new UNIX password:*******
passwd: all authentication tokens updated successfully
$
• Note − I have put stars (*) just to show you the location
where you would need to enter the current and new
passwords otherwise at your system, it would not show
you any character when you would type.
Mistake in Typing
• If you make a typing mistake and seen before pressing
RETURN.
• There are 2 ways to recover:
– Erase characters one at a time (by default @sign)
– Or kill the whole line and re-type it. (The sharp character #)
• Example:
– $ ddate@
Date
Sun jul 28 12:23:39 EDT 1998
$
– $dd#atte##e
Sun jul 28 12:34:39 EDT 1998
Unix Files and Directories
• All data is organized into files
• Files are organized into directories
• These directories are organized into tree like
structure called the file system.
• You can use ls command to list out all the files
or directories available in a directory.
Example
• Following is the example of using ls command with -l option.
$ ls -l
total 7
drwxrwxr-x 2 amrood amrood 4096 Dec 25 09:59 uml
-rw-rw-r-- 1 amrood amrood 5341 Dec 25 08:38 uml.jpg
drwxr-xr-x 2 amrood amrood 4096 Feb 15 2006 univ
drwxr-xr-x 2 root root 4096 Dec 9 2007 urlspedia
-rw-r--r-- 1 root root 276480 Dec 9 2007 urlspedia.tar
drwxr-xr-x 8 root root 4096 Nov 25 2007 usr
-rw-rw-r-- 1 amrood amrood 20480 Nov 25 2007 webthumb.tar
• Note: We can use an absolute path from any location where as if you want to use
relative path we should be present in a directory where we are going to specify relative
to that present working directory.
Processing Environment
• On a Unix system everything is file, if something is not a file ,
it is a process.
• A program is an executable file, and a process is an instance
of a running program.
• Many processes can execute simultaneously on UNIX system
with no logical limit to their number, and many instances of a
program can exist simultaneously in the system.
• As soon as you typed command and press enter, the
program gets ready in the memory and executed by kernel.
• Some programs create single process, such as ‘ls command’
while some creates more than one, such as open office.
Process ID
• Every process executing in the UNIX system has an
execution environment that includes a current
directory.
• In Unix based operating system, every process has a
process ID called PID.
• At any one time, no two processes with the same PID
exist in the system because it is the PID that UNIX uses
to track each process.
• PID must be unique integer value , no negative
interger
Process
• When you start a process (run a command), there are two ways you can run it:
– Foreground Processes
– Background Processes
Foreground Processes
• By default, every process that you start runs in the foreground. It gets its input
from the keyboard and sends its output to the screen.
• For Example
– You can see this happen with the ls command. If I want to list all the files in my current
directory, I can use the following command:
$ls ch*.doc
– This would display all the files whose name start with ch and ends with .doc:
– The process runs in the foreground, the output is directed to my screen, and if the ls
command wants any input (which it does not), it waits for it from the keyboard.
• While a program is running in foreground and taking much time, we cannot run
any other commands (start any other processes) because prompt would not be
available until program finishes its processing and comes out.
Background Processes:
• A background process runs without being connected to
your keyboard. If the background process requires any
keyboard input, it waits.
• The advantage of running a process in the background is
that you can run other commands; you do not have to
wait until it completes to start another!
• The simplest way to start a background process is to add
an ampersand ( &) at the end of the command.
• For Example:
$ls ch*.doc &
– This would also display all the files whose name start with ch
and ends with .doc:
Ps Command
• The ps (process status) command produces a list of the currently running processes on your
computer.
$ ps
• ps
• The output will show rows of data containing the following information:
• PID, TTY, Time, Command
• The PID is the process ID which identifies the running process. The TTY is the terminal type.
TIME is the amount of CPU (central processing unit) time in minutes and seconds that the
process has been running. CMD is the name of the command that launched the process.
• One of the most commonly used flags for ps is the -f ( f for full) option.
$ ps -f
UID PID PPID C STIME TTY TIME CMD
amrood 6738 3662 0 10:23:03 pts/6 0:00 first_one
amrood 6739 3662 0 10:22:54 pts/6 0:00 second_one
amrood 3662 3657 0 08:10:53 pts/6 0:00 -ksh
• Here is the description of all the fileds displayed by ps -f command:
Column Description
UID User ID that this process belongs to (the person
running it).
PID Process ID.
PPID Parent process ID (the ID of the process that started
it).
C CPU utilization of process.
STIME Process start time.
TTY Terminal type associated with the process
TIME CPU time taken by the process.
CMD The command that started this process.
Stopping Processes
• Ending a process can be done in several different ways. Often,
from a console-based command, sending a CTRL + C keystroke
(the default interrupt character) will exit the command. This
works when process is running in foreground mode.
• If a process is running in background mode then first you would
need to get its Job ID using ps command and after that you can
use kill command to kill the process as follows:
$ps -f
UID PID PPID C STIME TTY TIME CMD
amrood 6738 3662 0 10:23:03 pts/6 0:00 first_one
amrood 6739 3662 0 10:22:54 pts/6 0:00 second_one
amrood 3662 3657 0 08:10:53 pts/6 0:00 –ksh
$ kill 6738
Here kill command would terminate first_one process