0% found this document useful (0 votes)
19 views12 pages

System Calls

ratnam

Uploaded by

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

System Calls

ratnam

Uploaded by

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

System Calls

1) What the System calls provide? (interface to the services of OS)


Operating systems provide various services to the users and System
calls provide an interface to the services made available by an
operating system.
2) How the system calls are written? ( in C or C++ or assembly
language)
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 have to be written using assembly-
language instructions.
3) Example? (to read data from one file and copy them to another file)
This may include several steps as follows
1) Obtaining the names of the two files
2) Opening the input file and creating a new output file
3) Performing read and write operations
4) Closing both the files

1) Obtaining the names of the two files (


1.Interactive Approach
2. mouse-based and icon-based
systems)
Interactive approach ( a sequence of systems calls , writing,reading)

1
this approach will require a sequence of system calls, first to write a
prompting message on the screen and then to read from the keyboard
the characters that define the two files
2. mouse-based and icon-based systems
a menu of file names is usually displayed in a window. The user can
then use the mouse to select the source name, and a window can be
opened for the destination name to be specified. This sequence
requires many I/O system calls
Open the input file and create the output file(
may result in various system calls
1.no such file exists
2.protection against access
3.already an output file with the same
name exists
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 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 (yet another
system call).
Performing read and write operations ( 1.by entering into a loop
2.eof reached,hardware failure
3.no more disk space
2
We enter a loop that reads from the input file (a system call) and writes
to the output file (another system call).
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 (for example, no more disk space).
Closing both the files
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
system calls), and finally terminate normally (the final system call). This
system-call sequence is shown in Figure 2.5.

3
Passing parameters to the operating system (
1. in registers
2. if more parameters are there
then store them in a block or
table and pass the address of the
block as a parameter in a
register)
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

4
Types of System Calls ( C I D P F P)
System calls can be classified into various types as given below
1) Communication
2) Information maintenance
3) Device Manipulation system calls
4) Process Control system calls
5) File Manipulation system calls
6) Protection

5
6
7
Protection
1) Define protection? (a mechanism for controlling access to
resources)
Protection provides a mechanism for controlling access to the
resources provided by a computer system

2) Resources that needs protection (computers, servers, mobiles,


handheld devices etc.)
All computer systems, from servers to mobile handheld devices,
must be concerned with protection
3) Various system calls used? ( 1. Set_permission()
2. get_permission()
3. allow_user()
4. deny_user()
set permission() and get permission(), which manipulate the permission
settings of resources such as files and disks. The allow user() and deny
user() system calls specify whether particular users can—or cannot—be
allowed access to certain resources.
2. Communication
1) process communication? ( 1)message passing 2)shared memory )
There are two common models of interposes communication: the
message passing model and the shared-memory model
message-passing model
1) How the communication is done? (by using a mail box )

8
Messages can be exchanged between the processes either directly or
indirectly through a common mailbox
2) Prerequisites of communication? (
1. Connection should be opened
2. name of the other communicator
should be known
Before communication can take place, a connection must be opened.
The name of the other communicator must be known, be it another
process on the same system or a process on another computer
connected by a communications network
3) Various system calls used in message passing?
1. get_hostid()
2. get_ processid()
3. open _connection()
4. close_connection()
5. accept connection()
6. write_message()
7.read _message()
8. wait for connection()
shared-memory model
1) Normal operation of OS ( prevents one process from accessing
another’s processes memory)
Normally, the operating system tries to prevent one process from
accessing another process’s memory.

9
2) Prerequisite of shared memory? ( 1.remove the above restriction
2.they are not writing to the
same location
simultaneously
Shared memory requires that two or more processes agree to remove
this restriction.
They can then exchange information by reading and writing data in the
shared areas. The form of the data is determined by the processes and
is not under the operating system’s control. The processes are also
responsible for ensuring that they are not writing to the same location
simultaneously
3) System calls used ? (
Shared_memory_create() and shared_memory_ attach() system calls to
create and gain access to regions of memory owned by other processes
3. Information Maintenance
1) What an operating system keeps? (Information about all its
processes)
The operating system keeps information about all its processes, and
system calls are used to access this information
2) What many operating systems provide?(a time profile of a program)
Many operating systems provide a time profile of a program to indicate
the amount of time that the program executes at a particular location
or set of locations.
3) Example system calls ( 1.current_time () and date ()
2. number of users

10
3.version number of OS
4.amount of free memory
5.amount of free disk space)
For example, most systems have a system call to return the current
time() and date().Other system calls may return information about the
system, such as the number of current users, the version number of the
operating system, the amount of free memory or disk space, and so on
Device Management
1. What a process may need( several resources ,main memory,disk
drives,files etc)
A process may need several resources to execute—main memory, disk
drives, access to files, and so on.
If the resources are available, they can be granted, and control can be
returned to the user process. Otherwise, the process will have to wait
until sufficient resources are available
2. Various system calls used?

request(),release(),read(),write(),reposition()
File Management
1) Various system calls used on files
1. Create ()
2.Delete()
3.Open()
4.Close()
5.read()
11
6. write ()
7.reposition()
create() and delete() files. Either system call requires the name of the
file and perhaps some of the file’s attributes. Once the file is created,
we need to open() it and to use it. We may also read(), write(), or
reposition() (rewind or skip to the end of the file, for example). Finally,
we need to close() the file, indicating that we are no longer using it
Process Control
A running program needs to be able to halt its execution either
normally (end()) or abnormally (abort()).
A process or job executing one program may want to load() and
execute() another program
to determine and reset the attributes of a job or process, including the
job’s priority, its maximum allowable execution time, and so on (get
process attributes() and set process attributes()
Terminate a job or process that we created (terminate process())
to wait for a certain amount of time to pass (wait time()).
to wait for a specific event to occur (wait event())

12

You might also like