Unit2-Services and Components of OS
Unit2-Services and Components of OS
• 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.
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.
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.
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.
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.
Resource Management
Protection
3
❖ System call sequence to copy the contents of one file to another file
4
System call parameter passing:
5
Types of System Calls:
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
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.)
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.
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.
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.
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.
The following table lists out commands that are available on majority of UNIX
systems to create and manage accounts and groups −
9
3 userdel Deletes accounts 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 −
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.
$ 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 −
12
The following table lists out the parameters −
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 −
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.
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.
0 No permission ---
17
(write) = 6
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
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
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.
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:
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.
22
Checking the disk space
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
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.ipv6.route.mtu_expires = 600
sunrpc.udp_slot_table_entries = 16
vm.block_dump = 0
# vi /etc/sysctl.conf
# sysctl –p
# sysctl –w {variable-name=value}
24