Osy Unit 2
Osy Unit 2
Once the two file names have been obtained, the program must open the input file and create the
output file. Each of these operations requires another system call. Possible error conditions for each operation
can require additional system calls. When the program tries to open the input file, for example, 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 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 thatthere is already an
output file with the same name. This situation may causethe program to abort (a system call), or we may delete
the existing file (anothersystem call) and create a new one (yet another system call). Another option,in an
interactive system, is to ask the user (via a sequence of system calls tooutput the prompting message and to
read the response from the terminal)whether to replace the existing file or to abort the program.When 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 readand write must return status information regarding various possible errorconditions. On
input, the program may find that the end of the file has beenreached 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 outputdevice
(for example, no more disk space).
Finally, after the entire file is copied, the program may close both files(another system call), write a
message to the console or window (more systemcalls), and finally terminate normally (the final system call).
This system-call sequence is shown in Figure.As you can see, even simple programs may make heavy use of
Q1. State any four types of system call provided by an operating system.
Ans: System calls related to Process Control: End, Abort Load, Execute, Create process,
Terminate process, Ready process, Dispatch process, Suspend, Resume, Get Process attribute,
set attribute, Wait for time, Wait event, signal event.
System calls Related to File Management: Create file, delete file Open file , Close file Create
directory Read, Write, Reposition Get file attribute , set file attribute, Create a link, Change the
working directory.
System calls Related to Device Management: Request a device, Release a device Read, Write,
Reposition, Get device attribute, Set device attribute
System calls Related to 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.
System calls Related to Communication: create,delete communication connection send,
receive messages, transfer status information, attach or detach remote devices
Q3. What is system call? With the help of diagram explain open ( ) system call.
Ans: System Calls: System calls are programming interface to the services provided by the
operating system
1. Each system call associated with a particular number.
2. System call interface maintains a table indexed according to these numbers.
3. The system call interface invokes intended system call in operating system kernel and returns
status of the system call and any return values.
4. The caller needs to know nothing about how the system call is implemented. Just needs to
obey API and understand what OS will do as a result call.
5. Most details of operating system interface hidden from programmers by API. It is managed by
run-time support library.
Q4. List types of system call and explain the system call – “Information Maintenance”.
Ans: Types of System calls are as follows:
1. Process or Job control
2. File Management
3. Device Management
4. Information Maintenance
5. Communications
Information Maintenance:
The operating system keeps information about all its processes and provides system calls to
access this information. Some system calls exist purely for transferring information between the
user program and the operating system. Transferring information between the user program and
the operating system requires system call. System information includes displaying current date
and time, the number of current user, the version number of the operating system, the amount of
free memory or disk space and so on.
System calls Related to 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.
3. The system call interface invokes intended system call in operatingsystem kernel and returns
status of the system call and any returnvalues.
4. The caller needs to know nothing about how the system call isimplemented. Just needs to obey
API and understand what OS will doas a result call.
5. Most details of operating system interface hidden from programmersby API. It is managed by
run-time support library.
Open ( ) system call for most file systems, a program initializes access to a filein a file system
using the open system call. This allocates resources associatedto the file (the file descriptor), and
returns a handle that the process will use torefer to that file.
Q6. What is system call? Enlist any four system calls related with process management.
Ans: System call is an interface between a running program and operating system. It allows
userto access services provided by operating system. This system calls are procedures
writtenusing C, C++ and assembly language instructions. Each operating system has its own
namefor each system call. Each system call is associated with a number that identifies itself.
System calls related with process management:
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.
Q9. List any four services provided by OS and explain any two of them. OR
Explain any six services of Operating System. Draw diagram of services of OS
Ans.
1. User interface
2. Program execution
3. I/O operations
4. File-system manipulation
5. Communications
6. Error detection
7. Resource allocation
8. Accounting
9. Protection and security
2. Program execution: - The operating system provides an environment where the usercan
conveniently run programs. To run a program, the program is loaded into the mainmemory and
then CPU is assigned to that process for its execution. Operating systemperforms this function
for the convenience of the user. It also performs other importanttasks like allocation and de-
allocation of memory, CPU scheduling etc. It alsoprovides service to end process execution
either normally or abnormally by indicatingerror.
4. File system manipulation: - Programs may need to read and write data from and tothe files
and directories. Operating system manages the secondary storage. User givesa command for
reading or writing to a file. Operating system makes it easier for userprograms to accomplish
their task such as opening a file, saving a file and deleting afile from the storage disk. It also
provides services for file permission management toallow or deny access to files or directories
based on file ownership.
5. Communication: - In the system, one process may need to exchange information withanother
process. Such communication may occur between processes that are executingon different
computer systems tied together by a computer network. Communicationcan be implemented via
shared memory or through message passing, in which packetsof information are moved between
processes by the operating system.
7. Resource allocation: - When there are multiple users or multiple processes running at the
same time, resources must be allocated to each of them. Operating system manages resource
allocation to the processes. These resources are CPU, main memory, file storage and I/O devices.
For maximizing use of CPU, operating system does CPU scheduling. Operating system contains
routines to allocate printers, modems, USB storage drives and other peripheral devices.
8. Accounting: - Operating system keeps track of usages of various computer resourcesallocated
to users. This accounting is used for reconfiguration of system to improvecomputing services.
concurrently, one process should not interfere with the otherprocesses or operating system itself.
Protection provides controlled access tosystem resources. Security is provided by user
authentication such as password foraccessing information.
Diagram of services of OS
Secondary storage Management: The computer system provides secondary storage to back up
main memory. Secondary storage is required because main memory is too small to accommodate
all data and programs, and the data that it holds is lost when power is lost. Most modern
computer systems use disks as the principal on-line storage medium for programs and data. Most
of the programs including compilers, assemblers, word processors, editors, and formatters are
stored on a disk until loaded into memory. Secondary storage consists of tapes drives, disk
drives, and other media.
Activities:
Free space management
Storage allocation
Storage de-allocation
Disk scheduling.
To read a piece of data that is stored at the end of the file, one has to read all of the data that
comes before it-you cannot jump directly to the desired data. This is similar to the way cassette
tape players work. If one wants to listen to the last song on a cassette tape, he has to either fast-
forward over all of the songs that come before it or listen to them. There is no way to jump
directly to a specific song.
Ans:
File system manipulation: While working on the computer, generally a user performs various
types of operations on files like creating a file, opening a file, saving a file, deleting a file, search
for a file with file name from the storage disk, etc. Programs need to read a file or write a files
and directories. The operating system gives the permission to program for performing operations
on file. Maintain details of files or directories with their respective details. Some programs
include permissions management that allow or deny access to files or directories based on file
ownership.
Resource allocation: When multiple users or multiple jobs are running at the same time, it is the
responsibility of an operating system to allocate the required resources to each process.
Operating system manages many different types of resources such as CPU, main memory, tape
drive or secondary storage etc. For this purpose, various types of algorithms are implemented
such as process scheduling, CPU scheduling, disk scheduling etc. There are some routines that
allocate printers, modems, USB storage drives and other peripheral devices.
from main memory during the data fetch cycle. The main memory is generally the only large
storage device that the CPU is able to address and access directly.
For a program to be executed, it must be mapped to absolute addresses and loaded into memory.
As the program executes, it accesses program instructions and data from memory by generating
these absolute addresses.
To improve both the utilization of the CPU and the speed of the computer’s response to its users,
operating system keeps several programs in memory. To handle memory with multiple programs
memory management is necessary.
Activities of memory management.
1) Keeping track of which part of memory are currently being used and by whom.
2) Deciding which processes and data to move into and out of memory.
3) Allocating & Deallocating space as needed.
1. Process Management
The operating system manages many kinds of activities ranging from user programs tosystem
programs like printer spooler, name servers, file server etc. Each of these activitiesis
encapsulated in a process. A process includes the complete execution context (code,data, PC,
registers, OS resources in use etc.). The basic unit of software that the operatingsystem deals
with in scheduling the work done by the processor is either a process or athread, depending on
the operating system. It’s tempting to think of a process as anapplication, but that gives an
incomplete picture of how processes relate to the operating system and hardware. The
application you see (word processor or spreadsheet or game) is,indeed, a process, but that
application may cause several other processes to begin, for taskslike communications with other
devices or other computers. There are also numerousprocesses that run without giving you direct
evidence that they ever exist. A process, then,is software that performs some action and can be
controlled by a user, by other applicationsor by the operating system. It is processes, rather than
applications, that the operatingsystem controls and schedules for execution by the CPU. In a
single-tasking system, theschedule is straightforward. The operating system allows the
application to begin running,suspending the execution only long enough to deal with interrupts
and user input.
The five major activities of an operating system in regard to process management are
1. Creation and deletion of user and system processes.
2. Suspension and resumption of processes.
3. A mechanism for process synchronization.
4. A mechanism for process communication.
5. A mechanism for deadlock handling.
2. Main-Memory Management
Services provided under Memory Management are directed to keeping track of memoryand
allocating/de allocating it to various processes. The OS keeps a list of free memorylocations.
Before a program is loaded in the memory from the disk, this MM consults thefree list, allocates
the memory to the process, depending upon the program size andupdates the list of free memory.
Primary-Memory or Main-Memory is a large array ofwords or bytes. Each word or byte has its
own address. Main-memory provides storagethat can be access directly by the CPU. That is to
say for a program to be executed, it mustin the main memory.
The major activities of an operating in regard to memory-management are:
1. Keeping track of which parts of memory are currently being used and by whom.
2. Deciding which processes (or parts thereof) and data to move into and out of memory.
3. Allocating and deallocating memory space as needed.
3. File Management
A file is a collected of related information defined by its creator. Computer can store fileson the
disk (secondary storage), which provide long term storage. Some examples ofstorage media are
magnetic tape, magnetic disk and optical disk. Each of these media hasits own properties like
speed, capacity, and data transfer rate and access methods. A filesystem normally organized into
directories to ease their use. These directories may containfiles and other directions.
The five main major activities of an operating system in regard to file managementare:
1. The creation and deletion of files.
2. The creation and deletion of directions.
3. The support of primitives for manipulating files and directions.
4. The mapping of files onto secondary storage.
5. The backup of files on stable storage media.
5. Secondary-Storage Management
Systems have several levels of storage, including primary storage, secondary storage andcache
storage. Instructions and data must be placed in primary storage or cache to bereferenced by a
running program. Because main memory is too small to accommodate alldata and programs, and
its data are lost when power is lost, the computer system mustprovide 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 inprimary storage (primary, secondary, cache) is
ordinarily divided into bytes or wordsconsisting of a fixed number of bytes. Each location in
storage has an address; the set of alladdresses available to a program is called an address space.
The three major activities of an operating system in regard to secondary storage
management are:
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.
Q17. Explain how parameter passing is done while implementing system calls.
Ans:Three general methods are used to pass parameters to the operating system.
The simplest approach is to pass the parameters in registers. In some cases, however, there may be more
parameters than registers. In these cases, the parameters are generally stored in a block, or table, in memory,
and the address of the block is passed as a parameter in a register (as shown in the Figure). This is the approach
taken by Linux and Solaris. Parameters also can be placed, or pushed, onto the stack by the program and
popped off the stack by the operating system. Some operating systems prefer the block or stack method
because those approaches do not limit the number or length of parameters being passed.
Q18. Describe Operating System tools. OR What are the system tools used in Linux?
Explain. OR Write a note on use of operating system tools.
Ans: Operating system tools are special system programs that are used to manage the overall
functions of an operating system.
These tools are used for following purposes:
Memory management, processor management, device management, file management, security,
control over system performance, job accounting, error detecting aids, coordination between
users & other software.
Some of the tools are discussed below:
1. User Management:
As the administrator, it is your job to create and manage the accounts for all required users. To
facilitate this, Linux comes with several tools for user management. User management includes
everything from creating a user to deleting a user from system.
There are 3 types of accounts present in Unix operating system.
1. Root: This account belongs to system administrator. This is also called as superuser.
Superuser has permission to run any command.
2. System Accounts: This account is required for system related components. For example,
email&sshd accounts.
3. User Accounts: These accounts belong to users & group of users. General users have
these accounts & these users have limited access to the system files & directories.
Following are four user administration files:
/etc/passwd : This file holds information about user account & password.
/etc/shadow: This file keeps encrypted password of corresponding account.
/etc/group: his file holds group information for each user account.
/etc/gshadow: It contains secure group account information.
Following commands are used to create & manage user, group accout:
Useradd: To add user account to the system.
Usermod: To modify accounts attributes.
Userdel: To delete user account from the system.
groupadd: To add groups to the system.
groupmod: To modify group attributes.
groupdel:To remove groups from the system.
2. Security Policy:
OS security policy helps in protecting systems from various threats to the systems like malware,
spyware, ransom ware, viruses, worms, backdoor intrusions, & many more. Security policies
provide all possible preventatives measures & techniques to keep operating system safe. It also
protects OS from activities like data theft, unwanted modifications to data, deletion of data etc.
There are wide operations performed by OS security policies. Some of the major areas are listed
below:
System updating or patching system regularly.
Software installation or updation of various antiviruses.
Firewall installation & management of upcoming & outgoing traffic on networks.
Provide security to user account.
Deciding what kind of data, users & hardware is vital in the system.
Although there are already a lot of good security features built into Linux-based system, one very
important potential weakness can exist when local access granted i.e. file permission based
issues resulting from a user not assigning the correct permissions to files & directories. So based
upon the need for proper permissions, it is categorized as below:
1. Permission Groups:
Each file & directory has three user based permission groups:
i) owner ⁄user: The owner ⁄user permissions apply only to the file or directory, they will
not impact the actions of the other users.
ii) group: The group permissions are apply on the group that has been assigned to the
file or directory, they will not affect the actions of other users.
iii) all users: The all users permissions apply to all other users on the system, this is the
permission group that you need to watch the most.
2. Permission Types:
Each file or directory has three basic permission types:
i) read: The read permission refers to a user’s capability to read the contents of the file.
ii) write: The write permission refers to a user’s capability to write or modify the file or
directory.
iii) execute: The execute permission affects to a user’s capability to execute a file or
view the contents of a directory.
3. Viewing the permissions:
You can view the permissions in your favorite GUI File Manager or by reviewing the
output of the “ls –l” command while in the terminal & while working in the directory
which contains the file or folder.
The permission in the command line is displayed as _rwxrwxrwx 1 owner:group
Numerical Permissions
# Permissions Binary rwx Octal rwx
7 Read, write & execute 111 7
6 Read & write 110 6
5 Read & execute 101 5
4 Read only 100 4
3 Write & execute 011 3
2 Write only 010 2
1 Execute only 001 1
0 None 000 0
3. Device Management:
Device management is the process of managing the implementation, operation & maintenance of
a physical and/or virtual device. All Linux device files are located in the /dev directory, which is
an integral part of the root (/) file system because these device files must be available to the
operating system during the boot process. The device nodes in the /dev directory provide access
to the corresponding kernel devices. With udev, the /dev directory reflects the current state of the
kernel. Every kernel device has one corresponding device file. If a device is disconnected from
the system, the device node is removed.
4. Performance Monitor:
It is really very tough job for every system or network administrator to monitor & debug Linux
system performance problems every day. There are some command line monitoring tools that
might be useful for every Linux system administrator. These commands are available under all
flavors of Linux & can be useful to monitor & find the actual causes of performance problem.
top command:
Linux top command is a performance monitoring program which is used frequently by
many system administrators to monitor Linux performance & it is available under many
Linux like operating systems.
The top command used to display all the running & active real time processes in ordered
list & updates it regularly. It display CPU usage, memory usage, swap memory, cache
size, buffer size, process PID, user commands & many more. It also shows high memory
& CPU utilization of running processes.
The top command is much useful for system administrator to monitor & take correct
action when required.
Syntax of top command
$root: - top
vmstat command:
Linux vmstat command used to display statistics of virtual memory, kernel threads, disks,
system processes, I⁄ O blocks, interrupts, CPU activity & much more. By default vmstat
command is not available under Linux system; you need to install a package called
sysstat that includes vmstat program.
Syntax of vmstat command
$root: - vmstat [options] [delay [count]]
5. Task Scheduler:
Task scheduler can be called CPU scheduler. Throughout the lifetime process it migrates
or travels to the various scheduling queues. An OS should select processes for scheduling
purposes from these queues in some manner or style. The selection procedure is done by
schedulers.
In batch system there can be many processes which can be executed immediately. In
batch systems if processes are more than they are spooled to the mass storage devices like
disks in which they are kept for the later execution.
The scheduler which picks up jobs from this spool & loads into main memory for
execution is called as long term scheduler or job scheduler.
There is another scheduler which selects the jobs or processes which are ready to execute
from this spool & allocates the CPU to one of them is called short term scheduler or CPU
scheduler.