Professional Documents
Culture Documents
System Calls
System Calls
System Calls
System Calls
• System calls provide an interface to the services
made available by an operating system.
• 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 need to be written using
assembly language instructions.
• A system call is an explicit request to the kernel
made via a software interrupt.
• Each operating system has its own name for each
system call.
System Calls
• A number is associated with each system call
and the system call interface maintains a table
indexed according to these numbers.
• The caller needs to know nothing about how
the system call is implemented or what it does
during execution.
How system calls are used
Example: Writing a simple program to read data
from one file and copy them to another file.
• Input file name and output file name is required. ( a sequence of system
calls are required for this)
• After obtaining both file names, input file must be opened and output file is
to be created.
• If input file does not exist then a message is to be printed and abnormally
termination takes place (another system call).
• If output file with same name already exists then delete(system call)
previous one and create a new one(system call).
• When both files are set up, a loop runs which reads(system call) from input
file and writes(system call) to output file.
• After the entire file is copied, the program may close both the files(system
call), write to console and finally terminate normally (final system call).
System call sequence to copy the contents of one file to another file
Handling of a user application invoking the open() system call
Standard C Library Example
C program invoking printf() library call, which calls write() system call
Types of system calls
There are major five categories:
• Process Control
• File manipulation
• Device manipulation
• Information maintenance
• Communication
Process Control
• A running program needs to be able to halt its
execution either normally (end) or abnormally
(abort).
• Under either normal or abnormal circumstances,
the operating system must transfer control to the
invoking command interpreter. The command
interpreter then reads the next command.
• A process or job executing one program may
want to load and execute another program.
• If we create a new job or process, we should be
able to control its execution.
Process Control
• End,abort
• Load,execute
• Create process,terminate process
• Get process attribute, set process attribute
• Wait for time
• Wait event, signal event
• Allocate and free memory
File manipulation
In shared memory model, processes use shared memory create and shared
memory attach system calls to create and gain access to regions of memory
owned by other processes. Here processes are responsible for ensuring that
they are not writing to the same location simultaneously.
Communication
• Message passing is useful for exchanging
smaller amounts of data.
• Shared memory allows maximum speed.
Examples of Windows and Unix system
calls