KEMBAR78
OS Chapter-2 Note | PDF | Process (Computing) | Computer File
0% found this document useful (0 votes)
28 views9 pages

OS Chapter-2 Note

Chapter Two discusses the basic concepts of operating systems, including the services they provide, such as user interfaces, program execution, I/O operations, and file system manipulation. It explains the process concept, process states, and the role of process control blocks, as well as the importance of threads and file management. Additionally, it covers system calls, their types, and the role of system programs and command interpreters in facilitating user interaction with the operating system.

Uploaded by

Robel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views9 pages

OS Chapter-2 Note

Chapter Two discusses the basic concepts of operating systems, including the services they provide, such as user interfaces, program execution, I/O operations, and file system manipulation. It explains the process concept, process states, and the role of process control blocks, as well as the importance of threads and file management. Additionally, it covers system calls, their types, and the role of system programs and command interpreters in facilitating user interaction with the operating system.

Uploaded by

Robel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Chapter Two

Basic Operating Systems Concepts

Overview

OS services- OS provides an environment for execution of programs. It provides certain services to programs
and to the users of those programs. OS services are provided for the convenience of the programmer, to make
the programming task easier. Services provide functions that are helpful to the user –

a. User interface: All OS have a user interface (UI) .Interfaces is of three types- Command Line Interface: uses
text commands and a method for entering them. Batch interface: commands and directives to control those
commands are entered into files and those files are executed. Graphical user interface: This is a window system
with a pointing device to direct I/O, choose from menus and make selections and a keyboard to enter text.

b. Program execution: System must be able to load a program into memory and run that program. The program
must be able to end its execution either normally or abnormally.

c. I/O operations: A running program may require I/O which may involve a file or an I/O device. For efficiency
and protection, users cannot control I/O devices directly.

d. File system manipulation: Programs need to read and write files and directories. They also need to create
and delete them by name, search for a given file, and list file information.

e.Communications: One process might need to exchange information with another process. Such
communication may occur between processes that are executing on the same computer or between processes
that are executing on different computer systems tied together by a computer network. Communications may be
implemented via shared memory or through message passing.

f. Error detection: OS needs to be constantly aware of possible errors. Errors may occur in the CPU and memory
hardware, in I/O devices and in the user program. For each type of error, OS takes appropriate action to ensure
correct and consistent computing.

Another set of OS functions exist for ensuring efficient operation of the system. They are-

a. Resource allocation: When there are multiple users or multiple jobs running at the same time, resources
must be allocated to each of them. Different types of resources such as CPU cycles, main memory and file storage
are managed by the operating system.

b. Accounting: Keeping track of which users use how much and what kinds of computer resources.

c. Protection and security: Controlling the use of information stored in a multiuser or networked computer
system. Protection involves ensuring that all access to system resources is controlled. Security starts with
requiring each user to authenticate himself or herself to the system by means of password and to gain access to
system resources.

Process Concept
A process is a program in execution. A process is more than a program code sometimes known as text section. It
also includes the current activity as represented by the value of the program counter and the contents of the
1 Principles of Operating System Chapter- 2: Basic OS Concepts Simon M.
processor’s registers. A process generally also includes the process stack which contains temporary data and a
data section which contains global variables. A process may also include a heap which is memory that is
dynamically allocated during process run time. Program itself is not a process, a program is a passive entity such
as a file containing a list of instructions stored on disk (called an executable file) whereas process is an active
entity with a program counter specifying the next instruction to execute and a set of associated resources. A
program becomes a process when an executable file is loaded into memory. Although two processes may be
associated with the same program, they are considered two separate execution sequences.

Process State

As a process executes, it changes state. The state of a process is defined in part by the current activity of that
process. Each process may be in one of the following states-

 New: The process is being created.


 Running: Instructions are being executed.
 Waiting: The process is waiting for some event to occur.
 Ready: The process is waiting to be assigned to the processor.
 Terminated: The process has finished execution.

Process Control Block

Each process is represented in the operating system by a process control block also called task control block. It
contains many pieces of information associated with a specific process including:

 Process State: The state may be new, ready, running, waiting, halted etc.
 Program Counter: The counter indicates the address of the next instruction to be executed for this process.
 CPU registers: The registers vary in number and type depending on the computer architecture.

2 Principles of Operating System Chapter- 2: Basic OS Concepts Simon M.


 CPU scheduling information: This information includes a process priority, pointers to scheduling queues,
and other scheduling parameters.
 Memory management information: This information may include such information as the value of base
and limit registers etc.
 Accounting information: This information includes the amount of CPU and real time used, time limits etc.
 I/O status information: This information includes the list of I/O devices allocated to the process, etc.

Threads

Process is a program that performs a single thread of execution. A single thread of control allows the process to
perform only one task at one time.

File Concept
Computers can store information on various storage media such as magnetic disks, magnetic tapes and optical
disks. OS provides a uniform logical view of information storage. OS abstracts from the physical properties of its
storage devices to define a logical storage unit called a file. Files are mapped by OS onto physical devices. These
storage devices are non-volatile so the contents are persistent through power failures and system reboots. A file is
a named collection of related information that is recorded on secondary storage. A file is the smallest allotment of
logical secondary storage; that is data cannot be written to secondary storage unless they are within a file. Files
represent programs and data. Data files may be numeric, alphabetic, alphanumeric or binary. Files may be free
form such as text files or may be formatted rigidly. A file is a sequence of bits, bytes, lines or records. Information
in a file is defined by its creator. Many different types of information may be stored in a file – source programs,
object programs, executable programs, numeric data, text etc. A file has a certain defined structure which depends
on its type.

Text file: sequence of characters organized into lines.


Source file: sequence of sub routines and functions each of which is further organized as declarations followed by
executable statements.
Object file: sequence of bytes organized into blocks understandable by the system’s linker.
Executable file: series of code sections that the loader can bring into memory and execute.

3 Principles of Operating System Chapter- 2: Basic OS Concepts Simon M.


File Attributes
A file is referred to by its name. A name is usually a string of characters. When a file is named, it becomes
independent of the process, the user and even the system that created it. A file’s attributes vary from one OS to
another but consist of these –

 Name: symbolic file name is the only information kept in human readable form.
 Identifier: number which identifies the file within the file system; it is the non human readable name for the
file.
 Type: information is needed for systems that support different types of files.
 Location: this information is a pointer to a device and to the location of the file on that device.
 Size: the current size of the file.
 Protection: Access control information determines who can do reading, writing, executing etc.
 Time, date and user identification: This information may be kept for creation, last modification and last use.
The information about all files is kept in the directory structure which resides on secondary storage. A directory
entry consists of the file’s name and its unique identifier. The identifier in turn locates the other file attributes.

File Operations
A file is an abstract data type. OS can provide system calls to create, write, read, reposition, delete and truncate
files.
 Creating a file – First space in the file system must be found for the file. Second, an entry for the new file
must be made in the directory.
 Writing a file – To write a file, specify both the name of the file and the information to be written to the
file. The system must keep a write pointer to the location in the file where the next write is to take place.
 Reading a file – To read from a file, directory is searched for the associated entry and the system needs to
keep a read pointer to the location in the file where the next read is to take place. Because a process is
either reading from or writing to a file, the current operation location can be kept as a per process current
file position pointer.
 Repositioning within a file – Directory is searched for the appropriate entry and the current file position
pointer is repositioned to a given value. This operation is also known as file seek.
 Deleting a file – To delete a file, search the directory for the named file. When found, release all files
space and erase the directory entry.
 Truncating a file – User may want to erase the contents of a file but keep its attributes. This function
allows all attributes to remain unchanged except for file length.

Other common operations include appending new information to the end of an existing file and renaming an
existing file. We may also need operations that allow the user to get and set the various attributes of a file.

4 Principles of Operating System Chapter- 2: Basic OS Concepts Simon M.


System Calls

System calls provide an interface to the services made available by an operating system.

An example to illustrate how system calls are used: Writing a simple program to read data from one file and copy
them to another file-

a) First input required is names of two files – input file and output file. Names can be specified in many ways-

One approach is for the program to ask the user for the names of two files. In an interactive system, this approach
will require a sequence of system calls, to write a prompting message on screen and then read from the keyboard
the characters that define the two files. On mouse based and icon based systems, a menu of file names is displayed
in a window where the user can use the mouse to select the source names and a window can be opened for the
destination name to be specified.

b) Once the two file names are obtained, program must open the input file and create the output file. Each of
these operations requires another system call.

Possible error conditions –

When the program tries to open input file, no file of that name may exist or file is protected against access.
Program prints a message on console and terminates abnormally. If input file exists, we must create a new output
file. If the output file with the same name exists, the situation caused the program to abort or delete the existing
file and create a new one. Another option is to ask the user (via a sequence of system calls) whether to replace
the existing file or to abort the program. When both files are set up, a loop reads from the input file and writes to
the output file (system calls respectively). Each read and write must return status information regarding various
possible error conditions. After entire file is copied, program closes both files, write a message to the console or
window and finally terminate normally. Application developers design programs according to application
programming interface (API). API specifies set of functions that are available to an application programmer.
Three of the most common API’s available to application programmers are the Win32 API for Windows Systems;
POSIX API for POSIX based systems (which include all versions of UNIX, Linux and Mac OS X) and Java API for
designing programs that run on Java virtual machine.

5 Principles of Operating System Chapter- 2: Basic OS Concepts Simon M.


Pictorial representation of system calls-

The functions that make up the API typically invoke the actual system calls on behalf of the application
programmer.

Benefits of programming rather than invoking actual system calls:

Program portability – An application programmer designing a program using an API can expect program to
compile and run on any system that supports the same API.

Actual system calls can be more detailed and difficult to work with than the API available to an application
programmer.

The run time support system ( a set of functions built into libraries included with a compiler) for most
programming languages provides a system call interface that serves as a link to system calls made available by
OS. The system call interface intercepts function calls in the API and invokes the necessary system call within the
operating system. A number is associated with each system call and the system call interface maintains a table
indexed according to these numbers. System call interface then invokes the intended system call in the OS kernel
and returns the status of the system call and return any values. System calls occur in different ways, depending
on the computer in use – more information is required than simply the identity of the desired system call. The
exact type and amount of information vary according to the particular OS and call.

6 Principles of Operating System Chapter- 2: Basic OS Concepts Simon M.


Three general methods are used to pass parameters to OS-

I. Pass the parameters in registers

II. Storing parameters in blocks or tables in memory and the address of the block id passed as a parameter in a
register

III. Placing or pushing parameters onto the stack by the program and popping off the stack by the OS.

Types of system calls: Five major categories

1) Process control

 end, abort
 load, execute
 create process, terminate process
 get process attributes, set process attributes
 wait for time
 wait event, signal event
 allocate and free memory

2) File Management

 create file, delete file


 open, close
 read, write, reposition
 get file attributes, set file attributes

3) Device management

 request device, release device


 read, write, reposition
 get device attributes, set device attributes
 logically attach or detach devices

7 Principles of Operating System Chapter- 2: Basic OS Concepts Simon M.


4) Information maintenance

 get time or date, set time or date


 get system data, set system data
 get process, file or device attributes
 set process, file or device attributes

5) Communications

 create, delete communication connection


 send, receive messages
 transfer status information
 attach or detach remote devices

System Programs

System programs provide a convenient environment for program development and execution. They can be
divided into these categories-

File management: These programs create, delete, copy, rename, print, dump, list and manipulate files and
directories.

Status information: Some programs ask the system for the date, time, and amount of available memory or disk
space, number of users.

File modification: Text editors may be available to create and modify the content of files stored on disk or other
storage devices.

8 Principles of Operating System Chapter- 2: Basic OS Concepts Simon M.


Programming language support: Compilers, assemblers, debuggers and interpreters for common
programming languages are often provided to the user with the OS.

Program loading and execution: Once a program is assembled or compiled, it must be loaded into memory to
be executed. System provides absolute loaders, relocatable loaders, linkage editors and overlay loaders.

Communications: These programs provide the mechanism for creating virtual connections among processes,
users and computer systems.

In addition to systems programs, OS are supplied with programs that are useful in solving common problems or
performing operations. Such programs include web browsers, word processors and text formatters, spread
sheets, database systems etc. These programs are known as system utilities or application programs.

Command Interpreter System

A command interpreter is an interface of the operating system with the user. The user gives commands which
are executed by operating system (usually by turning them into system calls).

• Command-Interpreter:

– The program that reads and executes commands given to the operating system.

– Examples of command-line interpreters are command.com (DOS), shell (UNIX).

– In windows systems the interface is mouse and menu based – WIMP (Windows, Icons, Menu, and
Pointing device).

9 Principles of Operating System Chapter- 2: Basic OS Concepts Simon M.

You might also like