Os Unit2
Os Unit2
Operating-System Structures
OVERVIEW
Operating-System Services
System Calls
OS DEBUGGING
Operating-System Services
An operating system provides an environment for the execution of programs. It provides certain
services to programs and to the users of those programs. The specific services provided, of
course, differ from one operating system to another, but we can identify common classes. These
operating-system services are provided for the convenience of the programmer, to make the
programming task easier.
Program execution
I/O operations
File System manipulation
Communication
Error Detection
Resource Allocation
Accounting
Protection
Program execution
Operating systems handle many kinds of activities from user programs to system
programs like printer spooler, name servers, file server, etc. Each of these activities is
encapsulated as a process.
A process includes the complete execution context (code to execute, data to
manipulate, registers, OS resources in use). Following are the major activities of an
operating system with respect to program management −
I/O Operation
An I/O subsystem comprises of I/O devices and their corresponding driver software.
Drivers hide the peculiarities of specific hardware devices from the users.
An Operating System manages the communication between user and device drivers.
I/O operation means read or write operation with any file or any specific I/O
device.
Operating system provides the access to the required I/O device when required.
Communication
In case of distributed systems which are a collection of processors that do not share
memory, peripheral devices, or a clock, the operating system manages
communications between all the processes. Multiple processes communicate with one
another through communication lines in the network.
The OS handles routing and connection strategies, and the problems of contention and
security. Following are the major activities of an operating system with respect to
communication −
Error handling
Errors can occur anytime and anywhere. An error may occur in CPU, in I/O devices or
in the memory hardware. Following are the major activities of an operating system with
respect to error handling −
Resource Management
In case of multi-user or multi-tasking environment, resources such as main memory,
CPU cycles and files storage are to be allocated to each user or job. Following are the
major activities of an operating system with respect to resource management −
Accounting.
We want to keep track of which users use how much and what kinds of computer resources. This record
keeping may be used for accounting (so that users can be billed) or simply for accumulating usage
statistics. Usage statistics may be a valuable tool for researchers who wish to reconfigiire the system to
improve computing services.
Protection
Considering a computer system having multiple users and concurrent execution of
multiple processes, the various processes must be protected from each other's
activities.
Protection refers to a mechanism or a way to control the access of programs,
processes, or users to the resources defined by a computer system. Following are the
major activities of an operating system with respect to protection −
Some operating systems include the command interpreter in the kernel. Others, such as Windows XP and
UNIX, treat the command interpreter as a special program that is running when a job is initiated or when
a user first logs on (on interactive systems). On systems with multiple command interpreters to choose
from, the interpreters are known as shells. For example, on UNIX and Linux systems, there are several
different shells a user may choose from including the Bourne shell, C shell, Bourne-Again shell, the Korn
shell, etc. Most shells provide similar functionality with only minor differences; most users choose a shell
based upon personal preference.
The main function of the command interpreter is to get and execute the next user-specified
command. Many of the commands given at this level manipulate files: create, delete, list, print,
copy, execute, and so on. The MS-DOS and UNIX shells operate in this way. There are two
general ways in which these commands can be implemented. In one approach, the command
interpreter itself contains the code to execute the command. For example, a command to delete a
file may cause the command interpreter to jump to a section of its code that sets up the
parameters and makes the appropriate system call.
Graphical user interfaces first appeared due in part to research taking place in the early 1970s at
Xerox PARC research facility. The first GUI appeared on the Xerox Alto computer in 1973.
However, graphical interfaces became more widespread with the advent of Apple Macintosh
computers in the 1980s Traditionally, UNIX systems have been dominated by command-line
interfaces, although there are various GUI interfaces available, including the Common Desktop
Environment (CDE) and X-Windows systems that are common on commercial versions of UNIX
such as Solaris and IBM's AIX system. However, there has been significant development in GUI designs
from various opensource projects such as K Desktop Environment (or KDE) and the GNOME desktop by
the GNU project. Both the KDE and GNOME desktops rim on Linux and various UNIX systems and are
available under open-source licenses, which means their source code is in the public domain.
System Calls
System calls provide an interface to the services made available by an operating system. These calls are
generally available as routines written in C and C++, although certain low-level tasks (for example, tasks
where hardware must be accessed directly), may need to be written using assembly-language instructions.
In computing, a system call is the programmatic way in which a computer program requests a
service from the kernel of the operating system it is executed on. A system call is a way for
programs to interact with the operating system. A computer program makes a system call
when it makes a request to the operating system’s kernel. System call provides the services of
the operating system to the user programs via Application Program Interface(API). It provides
an interface between a process and operating system to allow user-level processes to request
services of the operating system. System calls are the only entry points into the kernel system.
All programs needing resources must use system calls.
Once the two file names are obtained, the program must open the input file and create the output file.
Each of these operations requires another system call. There are also possible error conditions for each
operation. When the program tries to open the input file, it may find that there is no file of that name or
that the file is protected against access. In these cases, the program should 8 print a message on the console
(another sequence of system calls) and then terminate abnormally (another system call). If the input file
exists, then we must create a new output file. We may find that there is already an output file with the
same name. This situation may cause the program to abort (a system call), or we may delete the existing
file (another system call) and create a new one (another system call). Another option, in an interactive
system, is to ask the user (via a sequence of system calls to output the prompting message and to read the
response from the terminal) whether to replace the existing file or to abort the program.
Now that both files are set up, we enter a loop that reads from the input file (a system call) and writes to
the output file (another system call). Each read and write must return status information regarding various
possible error conditions. On input, the program may find that the end of the file has been reached or that
there was a hardware failure in the read (such as a parity error). The write operation may encounter
various errors, depending on the output Device
Most programmers never see this level of detail, however. Typically, application developers design
programs according to an application programming interface (API). The API specifies a set of
functions that are available to an application programmer, including the parameters that are passed to
each function and the return values the programmer can expect. Three of the most common APIs
available to application programmers are the Win32 API for Windows systems, the POSIX API for
POSIX-based systems (which includes virtually all versions of UNIX, Linux, and Mac OS X), and the
Java API for
designing programs that run on the Java virtual machine.
EXAMPLE OF STANDARD API
As an example of a standard API, consider the ReadFileQ function in the
Win32 API—a function for reading from a file. The API for this function
appears
Process control
o end, abort
o load, execute
o create process, terminate process
o get process attributes, set process attributes
o wait for time
o wait event, signal event
o allocate and free memory
• File management
° create file, delete file
o open, close
° read, write, reposition
o get file attributes, set file attributes
• Device management
o request device, release device
° read, write, reposition
o get device attributes, set device attributes
° logically attach or detach devices
• Information maintenance
• Communications
0 create, delete communication connection
° send, receive messages
o transfer status information
o attach or detach remote devices
Process Control
These system calls deal with processes such as process creation, process termination
etc.
File Management
These system calls are responsible for file manipulation such as creating a file, reading
a file, writing into a file etc.
Device Management
These system calls are responsible for device manipulation such as reading from device
buffers, writing into device buffers etc.
Information Maintenance
These system calls handle information and its transfer between the operating system
and the user program.
Communication
These system calls are useful for interprocess communication. They also deal with
creating and deleting a communication connection.