OPERATING SYSTEM , Given by CHANDAN Kr GUPTA ,Teacher:IITT c.o.e.,Pojewal.{you all can edit this file,maximum size:30 pages




Operating Systems Lab
Operating System

In computing, an operating system (OS) is the system software responsible for the direct control and management of hardware and basic system operations, as well as running application software such as word processing programs and web browsers.

In general, the operating system is the first layer of software loaded into computer memory when it starts up. Since these basic common services are assumed to be provided by the OS, there is no need to re-implement those same functions over and over again in every other piece of software that you may use. The portion of code that performs these core services is called the "kernel" of the operating system.

LINUX:

Linux is a computer operating system and its kernel. It is among the most famous examples of free software and of open-source development.

The term Linux refers to the Linux kernel, but is commonly used to describe entire Unix-like operating systems (also known as GNU/Linux) that are based on the Linux kernel, the libraries and the tools from the GNU project. Linux distributions often bundle large quantities of software with the core system known as "packages".

The kernel was originally developed for Intel 386 microprocessors but now supports a variety of computer architectures. It is deployed in applications ranging from personal computers to supercomputers and embedded systems such as mobile phones and personal video recorders.

Initially developed and largely used by individual enthusiasts, Linux has since gained the support of lT industry mammoths such as IBM and Hewlett ­Packard, and is overtaking many proprietary versions of Unix. Proponents and many analysts attribute this success to its vendor independence, low cost of implementation, tight security, and sturdy reliability.

MS-DOS:

Microsoft's disk operating system, MS-DOS, was Microsoft's implementation of DOS, which was the first popular operating system for the IBM PC, and until recently, was widely used on the PC compatible platform. It was originally released with the PC in 1981 and had seven major versions before Microsoft stopped development in 1995. It was the key product in Microsoft's growth from a programming languages company to a diverse software development firm, providing the company with essential revenue and marketing resources.

Mac OS:

Mac OS, which stands for Macintosh Operating System, is Apple Computer's name for the operating systems for Macintosh computers. The original Mac OS was the first commercially successful operating system, which used a graphical user interface. The Macintosh team included Bill Atkinson, Jef Raskin and Andy Hertzfeld.



Various Commands used at the Command Prompt:

Contents

cat -- for creating and displaying short files chmod - change permissions

cd - change directory cp _.- for copying files date - display date echo ­

echo argument ftp - connect to a remote machine to download or upload files

grep - search file

head - display first part of file

ls - see what files you have

lpr - standard print command (see also print)

more - use to read files

mkdir - create directory

mv.- for moving and renaming files

ncftp - especially good for downloading files via anonymous ftp.

print - custom print command (see also Ipn)

pwd - find out what directory you are in

rm - remove a file

rmdir - remove directory

rsh - remote shell

setenv - set an environment variable

sort - sort file

tail - display last part of file

tar - create an archive, add or extract files

telnet - log in to another machine

cat - This is one of the most flexible Unix commands. We can use to create, view and concatenate files. For our first example we create a three-item English Spanish dictionary

1\ 0 filft nailed "diet"

in a file called "diet.


% cat >dict red rojo green verde blue.azul <control-D>


wc - count characters, words, lines


different way:


Now suppose that, we have another file « thatiooks like this:


Home directory


Computers store information in things called/^*. A file is like a sheet of paper (maybe a very long one) with something written on it. Files are stored in things called directories.

We are now going to learn how make, use, and manage files and directories. We will begin by figuring out what our home directory is:

%cd %pwd

/ulc/jeremy % echo $HOME

/u/c/jeremy

The cd command ( change directory) used with no arguments takes us from wherever we might be to our home directory. The pwd (print working directory) tells in which directory we find ourselves for the moment. In the case at hand it is /u/c/jeremy. Don't be concerned for the moment about the /ulc/ part. It is a path, but that is irrelevant for now. Note that echo SHOME has exactly the same effect as pwd.

Creating short files


To create a short file. For this we use the cat command. Follow the example below carefully:

% cat >dict

red: rojo yellow: amarillo black: negro white: blanco blue: azul green: verde <control-d>%


By <control-d> we mean: hold the control key down; while it is down press "d". We have just used cat to create a short English-Spanish dictionary. This dictionary resides in the file diet. We told cat to put what we typed in diet using the "into" symbol, namely> . To tell cat that we were done typing we typed control-d (ffdff for "done"). To check that the dictionary is really there and that it was correctly entered we do this;


%ls

diet

% cat diet


red: rojo yellow: amarillo black: negro white: blanco blue: azul green: verde






What is a concurrent system?



Briefly, it is a system in which more than one thing can happen at the same time
 

A, B, and Care:


â threads in the same process


â processes on the same uniprocessor


ã processes on the same multiprocessor


âprocesses on networked machines


â transactions on the same database


We will call A, B, and C processes. Concurrent processes typically share information in one of two ways: by sharing memory or by passing messages. Shared memory is used by threads, processes on the same machine, and transactions on the same database. Message passing is used by processes on the same machine (via IPC: Inter-Process Communication) and by processes on networked machines.
 

Interference


Processes that share memory can interfere with one another. For example,consider the following code:

int count = 0; int add _ one()

count = count -f 1;

Suppose two threads execute this code at the same time. The function body really consists of three steps:

1. Read count into a register

2. Increment the register by one

3. Store the register into count

Depending on how these 3 steps interleave in the 2 executions, the result can he that count holds either the value 1 or the value 2.


Mutual Exclusion



One solution to the interference problem is to make sure that only one process has access to the shared information at any given time. This is called mutual exclusion.

Disabling interrupts


One way to achieve mutual exclusion is to simply turn off all interrupts. For example, the Linux kernel has code like this in its x86 version, where the cli instruction turns off interrupts (Clear the Interrupt flag), and the sti
instruction turns on interrupts (Set the Interrupt flag):

cli make sure we really have interrupts disabled

-*. • Operate on the shared data here. This is called a critical section.

sti ! enable interrupts

Advantages:

No interrupts, so no interference

Disadvantages:

Only works for a uniprocessor

Important I/O interrupts may be missed

Test-and-set


Some processors have an instruction that can read, modify, and write a memory location in one atomic (uninterruptible) step. The test-and-set instruction is a common one (see the btr and tsbb instructions on the Intel x86 architecture). It sets a memory location to -1 if it originally contained the number 0, and does nothing otherwise. It also sets a processor flag to indicate whether its test for zero was successful or not.

Advantages:

Fast CPU instruction

Works on multiprocessors

 Disadvantages:

Only works on a single machine

Other instructions that provide similar capabilities "fetch-and-increment" and swap.

Semaphores

Semaphores are high-level constructs that allow us to avoid the interference problem. Think of them as signal flags that concurrent entities wave at each other to coordinate entry into their critical sections. A semaphore can be thought of as an integer, on which two operations can be performed:

else block on the semaphore queue


if the queue is not empty then unblock something on the queue







































UNIX is a registered trademark of AT&T Bell Laboratories in the USA and other countries.


1.0 Introduction


The shell is both a command language and a programming language that provides an interface to the UNIX operating system.


1.1 Simple commands.

Simple commands consist of one or more words separated by blanks. The first word is the name of the command to be executed; any remaining words are passed as arguments to the command. For example, who is a command that prints the names of users logged in. The command

ls -l

prints a list of files in the current directory. The argument -/ tells ls to print status information" size and the creation date for each file.


1.2 Background commands

To execute a command the shell normally creates a new process and waits for it to finish. A command may be run without waiting for it to finish. For example


cc pgnuc &


calls the C compiler to compile the filspgrnx. The trailing & is an operator that instructs the shell not to wait for the command to finish. To help keep track of such a process the shell reports its process number following its creation. A list of currently active processes may be obtained using the ps command.


Prompting


When the shell is used from a terminal it will issue a prompt before reading a command. By default this prompt is *$ \ It may be changed by saying, for example,

PSI=yesdear
 

that sets the prompt to be the string yesdear. If a newline is typed and further input is needed then the shell will issue the prompt "> f. Sometimes this can be caused by mistyping a quote mark. If it is unexpected then an interrupt (DEL) will return the shell to read another command. This prompt may be changed by saying, for example,


PS2=inore
 

The shell and login


Following login (1) the shell is called to read and execute commands typed at the terminal. If the user's login directory contains the file.profile then it is assumed to contain commands and is read by title shell before reading any commands from theterminal.

Summary


ls Print the names of files in the current directory.

ls >file

Put the output from Is into file. ls | we -1

Print the number of files in the current directory. ls I grep old

Print those file names containing the string old ls | grep old I we -1

Print the number of files whose name contains the string old cc pgffiuc &

Run cc in the background.

Shell procedures

The shell may be used to read and execute commands contained in a file. For example,

sh fi!e [ args ... ]

sh wg fred

is equivalent to

who I grep fred

UNIX files have three independent attributes, read, write and execute. The UNIX command chmod (1) may be used to make a file executable. For example,

chmod +x wg



$MAIL

When used interactively the shell looks at the file specified by this variable before it issues a prompt. If the specified file has been modified since it was last looked at the shell prints the message you have mail before prompting for the next command. This variable is typically set in the file "profile, in the user's login directory. For example, MAIL-/usr/mail/fred


SHOME


The default argument for the cd command. The current directory is used to resolve file name references that do not begin with a /, and is changed using the cd command. For example,

cd /usr/fred/bin makes the current directory /usr/fred/bin.


cat wn

will print on the terminal the file wn in this directory. The command cd with no argument is equivalent to



Preprocessor

C Preprocessor accepts source code as input and is responsible for :

removing comments

interpreting spec

interareting special preprocessor directives denoted by i.


for example,

# include - includes contents of a named file. Files usually called header files. e.g



 Compiler



o define MM ARRAY SIZE 100

The C compiler translates source to assembly code. The source code is received from the
preprocessor.


Assembler



The assembler creates object code. On a UNIX system you may see lies with a. 0 suffix (. OBJ on MSDOS) to indicate object code files.


Link Editor



If a source file references library functions or ftmctioiis in other source files the link combines these functions (with main 0) to create an executable file. External Variable references resolved here also.

Compiler Options


Now that we have a basic understanding of the compilation model we can now introduce some useful and sometimes essential common compiler options. Again see the online man pages and Appendix J for .and

-c

Suppress the linking process and produce a . 0 file for each source file listed. Several can be subsequently linked by the cc command, for example:

cc filel.o file2,0 ... *.. -0 executable

-llibrary

Link with object libraries. TMs option must follow the source file arguments. The object libraries are archived and can be standard, third party or user created libraries (We discuss this topic briefly below. Probably the most commonly used library is the math library ( math. h). You must link in tins library explicitly if you wish to use the maths functions (note do note forget to #include <math. h> header file), for example:

cc calcic -0 calc -1 m

Many other libraries are linked in this fashion (see below)

. -"'directory

Add directory to the list of directories containing objwt-library routines. The linker always looks for standard and other system libraries in /lib and /usr/iib. If you want to link in libraries that you have created or installed yourself (unless you have certain privileges and get the libraries installed in /usr/iib) you will have to specify where you files are stored.




Microsoft Windows NT

NT is a commercial OS, first released for public use in July 1993. Windows NT uses a computational model based on processes and threads (rather than just processes). It also has a pervasive underlying object model. The product goals for Windows NT were that it should be an extensible, portable, reliable and secure OS for contemporary computers.

Extensibility I

There are at least two dimensions to the extensibility aspect. The first relates to OS configurations. A Windows NT machine can be configured for a workstation or a server. In either configuration, the OS uses the same source code, but different components are incorporated into each at compile time.
This allows Windows NT to be optimized to perform best according to the way the machine will be used - as a workstation or as a server - without building two different operating systems.

The next layer of abstraction is the subsystem layer. Subsystems emulate different operating systems and the protection subsystems provide security features. Therefore they provide application portability for Windows NT software. For example, version 4.0 has POSIX subsystem that executes on top of the Kernel and Executive and makes Windows NT look like POSIX (the POSIX standards are a set of specifications of different aspects of operating system behavior - it is based on a UNIX model and it came as a consequence of many different UNIX implementations).


Portability

It is possible to port Windows NT across different hardware platforms. Microsoft's goal was to be able to reuse the NT Kernel, NT executive and Subsystems on new microprocessors as they became available without having to rewrite the Kernel. Therefore, the Hardware Abstraction Layer (HAL) was designed as the software module

The HAL, NT Kernel and NT Executive are supervisor- mode software that collectively exports an API that is used by the subsystem designers (but not by application programmers). Subsystem designers choose a target API (like POSEX or Win32) and then build a subsystem to implement the target API using the supervisor portion of Windows NT. Microsoft's preferred API is Win32.


The NT Kernel


The Kernel is object oriented. It provides objects and threads on top of HAL. To implement objects and threads the Kernel must manage the hardware and software interrupts (exceptions, traps), perform processor scheduling and handle multiprocessor synchronization.

Some kernel object types are instantiated by the Kernel itself to store and manipulate the Kernel's state. Other objects are instantiated and used by the Executive, subsystems and application code. That is, Windows NT and all of its applications are managed at the Kernel level as objects.

Kernel objects are intended to be fast. They run in supervisor mode in trusted context so there is no security and only limited error checking for Kernel objects, in contrast to normal objects which incorporate these features. However, Kernel objects cannot be manipulated directly by user mode programs, only through function.