0% found this document useful (0 votes)
300 views

Unit2-Services and Components of OS

The document summarizes the key services and components of an operating system. It describes common OS services like program execution, I/O operations, file manipulation, communication, error detection, resource allocation and protection. It also explains the major OS components that handle processes, main memory, files, I/O devices and secondary storage. System calls are described as the programming interface to OS services, with examples of parameter passing methods and categories of system calls.

Uploaded by

Rutuja Pote
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
300 views

Unit2-Services and Components of OS

The document summarizes the key services and components of an operating system. It describes common OS services like program execution, I/O operations, file manipulation, communication, error detection, resource allocation and protection. It also explains the major OS components that handle processes, main memory, files, I/O devices and secondary storage. System calls are described as the programming interface to OS services, with examples of parameter passing methods and categories of system calls.

Uploaded by

Rutuja Pote
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Chapter 2: Services and Components of OS

2.1 Following are few common services provided by operating systems.

• Program execution
• I/O operations
• File System manipulation
• Communication
• Error Detection
• Resource Allocation
• Protection

Program execution

Operating system handles many kinds of activities for user programs and system
programs called as a process.

Following are the major activities of an operating system with respect to program
management.

• Loads a program into memory.


• Executes the program.
• Handles program's execution.

1
• Provides a mechanism for process synchronization.Provides a mechanism
for process communication.
• Provides a mechanism for deadlock handling.

I/O Operation

Operating System manages the communication between user and device drivers.
OS provides following functions:

• I/O operation means read or write operation with any file or any specific I/O
device.
• Program may require any I/O device while running.
• Operating system provides the access to the required I/O device when
required.

File system manipulation

A file system is normally organized into directories for easy navigation and usage.
Following are the major activities of an operating system with respect to file
management.

• Program needs to read a file or write a file.


• The operating system gives the permission to the program for operation on
file.
• Operating System provides an interface to the user to create/delete files.
• Operating System provides an interface to the user to create/delete
directories.
• Operating System provides an interface to create the backup of file system.

Communication

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.

• Two processes often require data to be transferred between them.


• The both processes can be on the one computer or on different computer but
are connected through computer network.
• Communication may be implemented by two methods either by Shared
Memory or by Message Passing.

2
Error handling

Error can occur anytime and anywhere. 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.

• OS constantly remains aware of possible errors.


• OS takes the appropriate action to ensure correct and consistent computing.

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.

• OS manages all kind of resources using schedulers.


• CPU scheduling algorithms are used for better utilization of CPU.

Protection

Protection refers to mechanism or a way to control the access of programs,


processes, or users to the resources defined by computer systems. Following are
the major activities of an operating system with respect to protection.

• OS ensures that all access to system resources is controlled.


• OS ensures that external I/O devices are protected from invalid access
attempts.
• OS provides authentication feature for each user by means of a password.

2.2 System Calls

➢ Definition : Programming interface to the services provided by the OS


➢ Typically written in a high-level language (C or C++)
➢ Mostly accessed by programs using Application Program Interface (API)
rather than direct system call use.
➢ The example of the API : Win32 for Windows, Java API for JVM

3
❖ System call sequence to copy the contents of one file to another file

System Call Implementation

➢ A number is assigned to each system call.


➢ System call interface maintains a table indexed according to this number.
➢ System call i/f will invoke the system call in OS kernel and will return status
of system call and return values.
➢ User doesn’t have to know the details of implementation of system call. Just
needs to know API and what OS will do as result of call.
➢ Most of the details of the OS interface are hidden by the API from the
programmers.

4
System call parameter passing:

We have to provide certain information along with the system call.

There are two ways of passing the parameters to system call:

1) Simplest: Passing the parameters in the registers. If parameters are


more than the registers then the parameters will be stored in memory
and address of this block is passed as parameter.
2) Parameters are pushed to stack and OS will pop them.

5
Types of System Calls:

System calls can be roughly grouped into five major categories:

1. Process Control
o load
o execute
o end, abort
o create process (for example, fork on Unix-like systems)
o terminate process
o get/set process attributes
o wait for time, wait event, signal event
o allocate, free memory
2. File management
o create file, delete file
o open, close
o read, write, reposition
o get/set file attributes
3. Device Management
o request device, release device
o read, write, reposition
o get/set device attributes
o logically attach or detach devices
4. Information Maintenance
o get/set time or date
o get/set system data
o get/set process, file, or device attributes
5. Communication
o create, delete communication connection
o send, receive messages
o transfer status information
o attach or detach remote devices

2.3 Operating System Components:


1. Process management
2. Main memory management
3. File management
4. I/O system management
5. Secondary storage management

6
Process Management
The operating system manages many kinds of activities ranging from user
programs to system programs like printer spooler, name servers, file server etc.
Each of these activities is encapsulated in a process. A process includes the
complete execution context (code, data, PC, registers, OS resources in use etc.)

The five major activities of an operating system in regard to process management


are
➢ Creation and deletion of user and system processes.
➢ Suspension and resumption of processes.
➢ A mechanism for process synchronization.
➢ A mechanism for process communication.
➢ A mechanism for deadlock handling.

Main-Memory Management
Primary-Memory or Main-Memory is a large array of words or bytes. Each word
or byte has its own address. Main-memory provides storage that can be access
directly by the CPU. That is to say for a program to be executed, it must in the
main memory.

The major activities of an operating in regard to memory-management are:


➢ Keep track of which part of memory are currently being used and by whom.
➢ Decide which process are loaded into memory when memory space becomes
available
➢ Allocate and de-allocate memory space as needed.

File Management
A file is a collected of related information defined by its creator. Computer can
store files on the disk (secondary storage), which provide long term storage. Some
examples of storage media are magnetic tape, magnetic disk and optical disk. Each
of these media has its own properties like speed, capacity, data transfer rate and
access methods. A file system normally organized into directories to ease their use.
These directories may contain files and other directions.
The five main major activities of an operating system in regard to file management
are
➢ The creation and deletion of files.
➢ The creation and deletion of directories.
➢ The support of primitives for manipulating files and directions.

7
➢ The mapping of files onto secondary storage.
➢ The backup of files on stable storage media.

I/O System Management


I/O subsystem hides the peculiarities of specific hardware devices from the user.
Only the device driver knows the peculiarities of the specific device to which it is
assigned.

Following are the components of I/O subsystem


1. Buffering, Caching and Spooling which are memory management
components.
2. Device driver interface.
3. Drivers for specific devices.

Secondary-Storage Management
Systems have several levels of storage, including primary storage, secondary
storage and cache storage. Instructions and data must be placed in primary storage
or cache to be referenced by a running program. Because main memory is too
small to accommodate all data and programs, and its data are lost when power is
lost, the computer system must provide secondary storage to back up main
memory. Secondary storage consists of tapes, disks, and other media designed to
hold information that will eventually be accessed in primary storage (primary,
secondary, cache) is ordinarily divided into bytes or words consisting of a fixed
number of bytes. Each location in storage has an address; the set of all addresses
available to a program is called an address space.

The three major activities of an operating system in regard to secondary storage


Management is:
1. Managing the free space available on the secondary-storage device
2. Allocation of storage space when new files have to be written.
3. Scheduling the requests for memory access.

2.4 Use of operating system Tools


➢ User management :

There are three types of accounts on a UNIX system −

8
• Root account
This is also called superuser and would have complete and unfettered
control of the system. A superuser can run any commands without any
restriction. This user should be assumed as a system administrator.
• System accounts
System accounts are those needed for the operation of system-specific
components for example mail accounts and the sshdaccounts. These
accounts are usually needed for some specific function on your system, and
any modifications to them could adversely affect the system.
• User accounts
User accounts provide interactive access to the system for users and groups
of users. General users are typically assigned to these accounts and usually
have limited access to critical system files and directories.

There are four main user administration files −


• /etc/passwd − Keeps the user account and password information. This file
holds the majority of information about accounts on the UNIX system.
• /etc/shadow − Holds the encrypted password of the corresponding account.
Not all the systems support this file.
• /etc/group − This file contains the group information for each account.
• /etc/gshadow − This file contains secure group account information.

The following table lists out commands that are available on majority of UNIX
systems to create and manage accounts and groups −

Sr.No. Command & Description

1 useradd Adds accounts to the system

2 usermod Modifies account attributes

9
3 userdel Deletes accounts from the system

4 groupadd Adds groups to the system

5 groupmod Modifies group attributes

6 groupdel Removes groups from the system

Create an Account
Let us see how to create a new account on your Unix system. Following is the
syntax to create a user's account −

useradd -d homedir -g groupname -m -s shell -u userid accountname


The following table lists out the parameters −

Sr.No. Option & Description

1 -d homedir
Specifies home directory for the account

2 -g groupname
Specifies a group account for this account

3 -m
Creates the home directory if it doesn't exist

4 -s shell
Specifies the default shell for this account

5 -u userid

10
You can specify a user id for this account

6 accountname
Actual account name to be created

If you do not specify any parameter, then the system makes use of the default
values. The useradd command modifies the /etc/passwd, /etc/shadow,
and /etc/group files and creates a home directory.
Following is the example that creates an account mcmohd, setting its home
directory to /home/mcmohd and the group as developers. This user would have
Korn Shell assigned to it.

$ useradd -d /home/mcmohd -g developers -s /bin/ksh mcmohd


Before issuing the above command, make sure you already have
the developers group created using the groupadd command.
Once an account is created you can set its password using the passwd command
as follows −

$ passwd mcmohd20
Changing password for user mcmohd20.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
When you type passwd accountname, it gives you an option to change the
password, provided you are a superuser. Otherwise, you can change just your
password using the same command but without specifying your account name.

Modify an Account
The usermod command enables you to make changes to an existing account from
the command line. It uses the same arguments as the useradd command, plus the
-l argument, which allows you to change the account name.

11
For example, to change the account name mcmohd to mcmohd20 and to change
home directory accordingly, you will need to issue the following command −
$ usermod -d /home/mcmohd20 -m -l mcmohd mcmohd20

Delete an Account
The userdel command can be used to delete an existing user. This is a very
dangerous command if not used with caution.
There is only one argument or option available for the command .r, for removing
the account's home directory and mail file.
For example, to remove account mcmohd20, issue the following command −
$ userdel -r mcmohd20
If you want to keep the home directory for backup purposes, omit the -r option.
You can remove the home directory as needed at a later time.
Create a Group
We will now understand how to create a group. For this, we need to create groups
before creating any account otherwise, we can make use of the existing groups in
our system. We have all the groups listed in /etc/groups file.
All the default groups are system account specific groups and it is not
recommended to use them for ordinary accounts. So, following is the syntax to
create a new group account −

groupadd [-g gid [-o]] [-r] [-f] groupname

12
The following table lists out the parameters −

Sr.No. Option & Description

1 -g GID
The numerical value of the group's ID

2 -o
This option permits to add group with non-unique GID

3 -r
This flag instructs groupadd to add a system account

4 -f
This option causes to just exit with success status, if
the specified group already exists. With -g, if the
specified GID already exists, other (unique) GID is
chosen

5 groupname
Actual group name to be created

If you do not specify any parameter, then the system makes use of the default
values.
Following example creates a developers group with default values, which is very
much acceptable for most of the administrators.
$ groupadd developers

13
Modify a Group
To modify a group, use the groupmod syntax −

$ groupmod -n new_modified_group_name old_group_name


To change the developers_2 group name to developer, type −
$ groupmod -n developer developer_2
Here is how you will change the financial GID to 545 −

$ groupmod -g 545 developer

Delete a Group
We will now understand how to delete a group. To delete an existing group, all
you need is the groupdel command and the group name. To delete the financial
group, the command is −
$ groupdel developer
This removes only the group, not the files associated with that group. The files are
still accessible by their owners.

➢ Security Policy
File ownership is an important component of UNIX that provides a secure method
for storing files. Every file in UNIX has the following attributes –
Permission Groups:
• Owner permissions − The owner's permissions determine what actions the
owner of the file can perform on the file.
• Group permissions − The group's permissions determine what actions a
user, who is a member of the group that a file belongs to, can perform on
the file.
• Other (world) permissions − The permissions for others indicate what
action all other users can perform on the file.

14
The Permission Indicators
While using ls -l command, it displays various information related to file
permission as follows −
$ls -l /home/amrood
-rwxr-xr-- 1 amrood users 1024 Nov 2 00:10 myfile
drwxr-xr--- 1 amrood users 1024 Nov 2 00:10 mydir
Here, the first column represents different access modes, i.e., the permission
associated with a file or a directory.
The permissions are broken into groups of threes, and each position in the group
denotes a specific permission, in this order: read (r), write (w), execute (x) −
• The first three characters (2-4) represent the permissions for the file's owner.
For example, -rwxr-xr-- represents that the owner has read (r), write (w)
and execute (x) permission.
• The second group of three characters (5-7) consists of the permissions for
the group to which the file belongs. For example, -rwxr-xr-- represents that
the group has read (r) and execute (x) permission, but no write permission.
• The last group of three characters (8-10) represents the permissions for
everyone else. For example, -rwxr-xr--represents that there is read (r) only
permission.
File Access Modes
The permissions of a file are the first line of defense in the security of a Unix
system. The basic building blocks of Unix permissions are the read, write,
and execute permissions, which have been described below −
Read
Grants the capability to read, i.e., view the contents of the file.
Write
Grants the capability to modify, or remove the content of the file.
Execute
User with execute permissions can run a file as a program.

15
Changing Permissions
To change the file or the directory permissions, you use the chmod (change
mode) command. There are two ways to use chmod — the symbolic mode and the
absolute mode.
Using chmod in Symbolic Mode
The easiest way for a beginner to modify file or directory permissions is to use the
symbolic mode. With symbolic permissions you can add, delete, or specify the
permission set you want by using the operators in the following table.

Sr.No. Chmod operator & Description

1 +
Adds the designated permission(s) to a file or
directory.

2 -
Removes the designated permission(s) from a file or
directory.

3 =
Sets the designated permission(s).

Here's an example using testfile. Running ls -1 on the testfile shows that the file's
permissions are as follows −
$ls -l testfile
-rwxrwxr-- 1 amrood users 1024 Nov 2 00:10 testfile
Then each example chmod command from the preceding table is run on the
testfile, followed by ls –l, so you can see the permission changes −
$chmod o+wx testfile
$ls -l testfile
-rwxrwxrwx 1 amrood users 1024 Nov 2 00:10 testfile
$chmod u-x testfile
$ls -l testfile
-rw-rwxrwx 1 amrood users 1024 Nov 2 00:10 testfile
16
$chmod g = rx testfile
$ls -l testfile
-rw-r-xrwx 1 amrood users 1024 Nov 2 00:10 testfile
Here's how you can combine these commands on a single line −
$chmod o+wx,u-x,g = rx testfile
$ls -l testfile
-rw-r-xrwx 1 amrood users 1024 Nov 2 00:10 testfile
Using chmod with Absolute Permissions
The second way to modify permissions with the chmod command is to use a
number to specify each set of permissions for the file.
Each permission is assigned a value, as the following table shows, and the total of
each set of permissions provides a number for that set.

Number Octal Permission Representation Ref

0 No permission ---

1 Execute permission --x

2 Write permission -w-

3 Execute and write permission: 1 (execute) -wx


+ 2 (write) = 3

4 Read permission r--

5 Read and execute permission: 4 (read) + 1 r-x


(execute) = 5

6 Read and write permission: 4 (read) + 2 rw-

17
(write) = 6

7 All permissions: 4 (read) + 2 (write) + 1 rwx


(execute) = 7

Here's an example using the testfile. Running ls -1 on the testfile shows that the
file's permissions are as follows −

$ls -l testfile
-rwxrwxr-- 1 amrood users 1024 Nov 2 00:10 testfile
Then each example chmod command from the preceding table is run on the
testfile, followed by ls –l, so you can see the permission changes −
$ chmod 755 testfile
$ls -l testfile
-rwxr-xr-x 1 amrood users 1024 Nov 2 00:10 testfile
$chmod 743 testfile
$ls -l testfile
-rwxr---wx 1 amrood users 1024 Nov 2 00:10 testfile
$chmod 043 testfile
$ls -l testfile
----r---wx 1 amrood users 1024 Nov 2 00:10 testfile

Changing Owners and Groups


While creating an account on Unix, it assigns a owner ID and a group ID to each
user. All the permissions mentioned above are also assigned based on the Owner
and the Groups.
Two commands are available to change the owner and the group of files −
• chown − The chown command stands for "change owner" and is used to
change the owner of a file.
• chgrp − The chgrp command stands for "change group" and is used to
change the group of a file.
Changing Ownership
The chown command changes the ownership of a file. The basic syntax is as
follows −
18
$ chown user filelist
The value of the user can be either the name of a user on the system or the user
id (uid) of a user on the system.
The following example will help you understand the concept −
$ chown amrood testfile
$
Changes the owner of the given file to the user amrood.
NOTE − The super user, root, has the unrestricted capability to change the
ownership of any file but normal users can change the ownership of only those
files that they own.
Changing Group Ownership
The chgrp command changes the group ownership of a file. The basic syntax is as
follows −
$ chgrp group filelist
The value of group can be the name of a group on the system or the group ID
(GID) of a group on the system.
Following example helps you understand the concept −
$ chgrp special testfile
$
Changes the group of the given file to special group.

User Authentication:
Several protection methods are developed by keeping in mind that, the system
knows the recognition of each user. Several methods of user identification are
based on some user information.

• Password

• A password is a way of authentication. It can be used as a means to identify


a person. Since the password is the only way to identify a person, it has to be
kept secret. A password can be static. This means it will remain the same

19
unless the user changes it, or it rarely changes. Or a password can be
dynamic. A dynamic password changes regularly and does not remain the
same. One type of a dynamic password is a one-time pad that can only be
used once.
• Passwords were first used in the military. This was to be able to tell who was
a friend and who was an enemy when it was dark.
• Modern passwords are made of characters, letters and numbers. Sometimes a
password will require a minimum number of characters. Usually this is from
six to eight. Some websites allow only the use of letters and numbers, but no
other characters on the keyboard. Other websites advise using
a combination of letters and numbers to increase the "strength" of a
password. Websites also advise changing a password once a year or more
often to prevent hacking. A person may be able to guess a password if it is
too easy. While being typed, each letter of a password is shown as * or •.
• Other ways of verifying the identity of a person include using fingerprint
scanners and face detection.
• Encryption is the translation of data to achieve data security. To read an
encrypted string a secret key or password must be provided to decrypt it.
• In systems that use login based actions, the password can be converted to the
original string if the key is provided. Hashing is a one-way function and is
irreversible.

➢ Device management

Device drivers
The software that handles or manages a hardware controller is known as a device
driver. The Linux kernel device drivers are, essentially, a shared library of
privileged, memory resident, low level hardware handling routines. It is Linux's
device drivers that handle the peculiarities of the devices they are managing.

Device files

Under Linux and UNIX each and every hardware device treated as a file. A device
file allows to accesses hardware devices so that end users do not need to get
technical details about hardware.

20
In short, a device file (also called as a special file) is an interface for a device
driver that appears in a file system as if it were an ordinary file. This allows
software to interact with the device driver using standard input/output system calls,
which simplifies many tasks.

Device file two types

There are two types of device files based upon how data written to them and read
from them is processed by the operating system and hardware:

• Character special files or Character devices


• Talks to devices in a character by character (1 byte at a time)
• Examples: Virtual terminals, terminals and serial modems etc
• Block special files or Block devices
• Talks to devices 1 block at a time ( 1 block = 512 bytes to 32KB)
• Examples: Hard disk, DVD/CD ROM, and memory regions etc

Partitions

fdisk stands (for “fixed disk or format disk“) is an most commonly used command-
line based disk manipulation utility for a Linux/Unixsystems. With the help of
fdisk command you can view, create, resize, delete, change, copy and move
partitions on a hard drive using its own user friendly text based menu driven
interface.

21
Mounting the File System
A file system must be mounted in order to be usable by the system. To see what is
currently mounted (available for use) on your system, use the following command

$ mount
/dev/vzfs on / type reiserfs (rw,usrquota,grpquota)
proc on /proc type proc (rw,nodiratime)
devpts on /dev/pts type devpts (rw)
$
The /mnt directory, by the Unix convention, is where temporary mounts (such as
CDROM drives, remote network drives, and floppy drives) are located. If you
need to mount a file system, you can use the mount command with the following
syntax −
mount -t file_system_type device_to_mount directory_to_mount_to
For example, if you want to mount a CD-ROM to the directory /mnt/cdrom, you
can type −
$ mount -t iso9660 /dev/cdrom /mnt/cdrom
This assumes that your CD-ROM device is called /dev/cdrom and that you want to
mount it to /mnt/cdrom. Refer to the mount man page for more specific
information or type mount -h at the command line for help information.
After mounting, you can use the cd command to navigate the newly available file
system through the mount point you just made.

Unmounting the File System


To unmount (remove) the file system from your system, use the umount command
by identifying the mount point or device.
For example, to unmount cdrom, use the following command −
$ umount /dev/cdrom
The mount command enables you to access your file systems, but on most modern
Unix systems, the automount function makes this process invisible to the user and
requires no intervention.

22
Checking the disk space

The space available in file system can be displayed by using df command


$df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/loop0 18761008 15246876 2554440 86% /
none 4 0 4 0% /sys/fs/cgroup
udev 493812 4 493808 1% /dev
tmpfs 100672 1364 99308 2% /run
none 5120 0 5120 0% /run/lock
none 503352 1764 501588 1% /run/shm
none 102400 20 102380 1% /run/user
/dev/the2 1957124 1512 1955612 1% /snap/core

Performance Monitor:
1) top Command
top command is used to show the Linux processes. It provides a dynamic real-
time view of the running system. Usually, this command shows the summary
information of the system and the list of processes or threads which are currently
managed by the Linux Kernel.

2) vmstat
vmstat command in Linux/Unix is a performance monitoring command of the system
as it gives the information about processes, memory, paging, block IO, disk and CPU
scheduling. All these functionalities makes the command vmstat also known as virtual
memory statistic reporter.

Task Scheduler

The Linux sysctl command configures kernel parameters at runtime. The


parameters available are those listed under /proc/sys/. Each time the system
boots, the init program runs the /etc/rc.d/rc.sysinit script. This script contains a
command to execute sysctl using /etc/sysctl.conf to determine the values passed
to the kernel. Any values added to /etc/sysctl.conf therefore take effect each time
the system boots.

23
# sysctl –a

dev.cdrom.autoclose = 1

fs.quota.writes = 0

kernel.ctrl-alt-del = 0

kernel.domainname = (none)

kernel.exec-shield = 1

net.core.somaxconn = 128

net.ipv4.tcp_window_scaling = 1

net.ipv4.tcp_wmem = 4096 16384 131072

net.ipv6.route.mtu_expires = 600

sunrpc.udp_slot_table_entries = 16

vm.block_dump = 0

Modify Kernel parameter in /etc/sysctl.conf for permanent change


After modifying the kernel parameter in the /etc/sysctl.conf, execute sysctl –p to
commit the changes. The changes will still be there after the reboot.

# vi /etc/sysctl.conf

# sysctl –p

Modify kernel parameter temporarily


To temporarily modify a kernel parameter, execute the following command. Please note
that after reboot these changes will be lost.

# sysctl –w {variable-name=value}

24

You might also like