Operating System 11
System Calls
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
What is a System Call
• System call is the programmatic way in which a
computer program requests a service from the
kernel of the operating system it is executed on.
• This may include hardware-related services (for
example, accessing a hard disk drive), creation
and execution of new processes, and
communication with integral kernel services such
as process scheduling.
• System calls provide an essential interface
between a process and the operating system.
System Calls Originate from
User Processes
• In most systems, system calls are possible to
be made only from userspace processes.
• In some systems, OS/360 and successors for
example, privileged system code also issues
system calls.
System Calls ensure Safety and
Security
• The architecture of most modern processors, with the
exception of some embedded systems, involves a security
model.
• For example, the rings model or layered approach specifies
multiple privilege levels under which software may be
executed: a program is usually limited to its own address
space so that it cannot access or modify other running
programs or the operating system itself, and is usually
prevented from directly manipulating hardware devices
(e.g. the frame buffer or network devices).
• However, many normal applications obviously need access
to these components, so system calls are made available by
the operating system to provide well defined, safe
implementations for such operations.
Interrupts
• The operating system executes at the highest level of
privilege, and allows applications to request services
via system calls, which are often initiated via interrupts.
• An interrupt automatically puts the CPU into some
elevated privilege level, and then passes control to the
kernel, which determines whether the calling program
should be granted the requested service.
• If the service is granted, the kernel executes a specific
set of instructions over which the calling program has
no direct control, returns the privilege level to that of
the calling program, and then returns control to the
calling program.
System Calls
• Programming interface to the services provided by the
OS
• Typically written in a high-level language (C or C++)
• Mostly accessed by programs via a high-level Application
Programming Interface (API) rather than direct system
call use
• Three most common APIs are Win32 API for Windows,
POSIX API for POSIX-based systems (including virtually all
versions of UNIX, Linux, and Mac OS X), and Java API for
the Java virtual machine (JVM)
Note that the system-call names used throughout this
text are generic
Example of System Calls
• System call sequence to copy the contents of
one file to another file
System Call Implementation
• Typically, a number associated with each system call
– System-call interface maintains a table indexed
according to these numbers
• The system call interface invokes the intended
system call in OS kernel and returns status of the
system call and any return values
• The caller need know nothing about how the
system call is implemented
– Just needs to obey API and understand what OS will do
as a result call
– Most details of OS interface hidden from programmer
by API
• Managed by run-time support library (set of functions built
into libraries included with compiler)
API – System Call – OS Relationship
System Call Parameter Passing
• Often, more information is required than simply
identity of desired system call
– Exact type and amount of information vary according to
OS and call
• Three general methods used to pass parameters to
the OS
– Simplest: pass the parameters in registers
• In some cases, may be more parameters than registers
– Parameters stored in a block, or table, in memory, and
address of block passed as a parameter in a register
• This approach taken by Linux and Solaris
– Parameters placed, or pushed, onto the stack by the
program and popped off the stack by the operating
system
– Block and stack methods do not limit the number or
length of parameters being passed
Parameter Passing via Table
System Call Implementation
• In a multithreaded process system calls can be
made from multiple threads.
• The handling of such calls is entirely dependent
on the design of the specific operating system.
• The following slides shows typical models
followed by kernels
• Many-to-one model
• One-to-one model
• Hybrid model
Many-to-one model:
• All system calls from any user thread in a
process are handled by a single kernel-level
thread.
• This model has a serious drawback – any
blocking system call (like awaiting input from
user) can freeze all the other threads.
• Also, since only one thread can access the
kernel at a time, this model cannot utilize
multiple cores of processor.
One-to-one model
• Every user thread gets attached to a distinct
kernel-level thread during a system call.
• This model solves the above problem of
blocking system calls.
• It is found in all major distribution of Linux,
recent Windows and Solaris versions.
Many-to-many model
• In this model a pool of user threads is mapped
to a pool of kernel threads. All system calls
from a user thread pool are handled by the
threads in their corresponding kernel thread
pool
both many to many and one to one
model depending upon choice made by
the kernel. This is found in old
versions of IRIX, HP-UX and Solaris.
System Calls as interface
between Running Programming
and OS
• System calls provide the interface between a running
program and the operating system.
• Generally available as assembly-language instructions.
• Languages defined to replace assembly language for
systems programming allow system calls to be made
directly (e.g., C, C++)
• Three general methods are used to pass parameters between
a running program and the operating system.
• Pass parameters in registers.
• Store the parameters in a table in memory, and the table
address is passed as a parameter in a register.
• Push (store) the parameters onto the stack by the program,
and pop off the stack by operating system.
Types of System Calls
• Process control
• File management
• Device management
• Information maintenance
• Communications
Process control
• 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
File manipulation
• create file, delete file
• open, close
• read, write, reposition
• get file attributes, set file attributes
Device manipulation
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices
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
Communications
• create, delete communication connection
• send, receive messages
• transfer status information
• attach or detach remote devices
Assignment
• Explain the concept of System Call

Operating system 11 system calls

  • 1.
    Operating System 11 SystemCalls Prof Neeraj Bhargava Vaibhav Khanna Department of Computer Science School of Engineering and Systems Sciences Maharshi Dayanand Saraswati University Ajmer
  • 2.
    What is aSystem Call • System call is the programmatic way in which a computer program requests a service from the kernel of the operating system it is executed on. • This may include hardware-related services (for example, accessing a hard disk drive), creation and execution of new processes, and communication with integral kernel services such as process scheduling. • System calls provide an essential interface between a process and the operating system.
  • 3.
    System Calls Originatefrom User Processes • In most systems, system calls are possible to be made only from userspace processes. • In some systems, OS/360 and successors for example, privileged system code also issues system calls.
  • 4.
    System Calls ensureSafety and Security • The architecture of most modern processors, with the exception of some embedded systems, involves a security model. • For example, the rings model or layered approach specifies multiple privilege levels under which software may be executed: a program is usually limited to its own address space so that it cannot access or modify other running programs or the operating system itself, and is usually prevented from directly manipulating hardware devices (e.g. the frame buffer or network devices). • However, many normal applications obviously need access to these components, so system calls are made available by the operating system to provide well defined, safe implementations for such operations.
  • 5.
    Interrupts • The operatingsystem executes at the highest level of privilege, and allows applications to request services via system calls, which are often initiated via interrupts. • An interrupt automatically puts the CPU into some elevated privilege level, and then passes control to the kernel, which determines whether the calling program should be granted the requested service. • If the service is granted, the kernel executes a specific set of instructions over which the calling program has no direct control, returns the privilege level to that of the calling program, and then returns control to the calling program.
  • 6.
    System Calls • Programminginterface to the services provided by the OS • Typically written in a high-level language (C or C++) • Mostly accessed by programs via a high-level Application Programming Interface (API) rather than direct system call use • Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM) Note that the system-call names used throughout this text are generic
  • 7.
    Example of SystemCalls • System call sequence to copy the contents of one file to another file
  • 8.
    System Call Implementation •Typically, a number associated with each system call – System-call interface maintains a table indexed according to these numbers • The system call interface invokes the intended system call in OS kernel and returns status of the system call and any return values • The caller need know nothing about how the system call is implemented – Just needs to obey API and understand what OS will do as a result call – Most details of OS interface hidden from programmer by API • Managed by run-time support library (set of functions built into libraries included with compiler)
  • 9.
    API – SystemCall – OS Relationship
  • 10.
    System Call ParameterPassing • Often, more information is required than simply identity of desired system call – Exact type and amount of information vary according to OS and call • Three general methods used to pass parameters to the OS – Simplest: pass the parameters in registers • In some cases, may be more parameters than registers – Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register • This approach taken by Linux and Solaris – Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system – Block and stack methods do not limit the number or length of parameters being passed
  • 11.
  • 12.
    System Call Implementation •In a multithreaded process system calls can be made from multiple threads. • The handling of such calls is entirely dependent on the design of the specific operating system. • The following slides shows typical models followed by kernels • Many-to-one model • One-to-one model • Hybrid model
  • 13.
    Many-to-one model: • Allsystem calls from any user thread in a process are handled by a single kernel-level thread. • This model has a serious drawback – any blocking system call (like awaiting input from user) can freeze all the other threads. • Also, since only one thread can access the kernel at a time, this model cannot utilize multiple cores of processor.
  • 14.
    One-to-one model • Everyuser thread gets attached to a distinct kernel-level thread during a system call. • This model solves the above problem of blocking system calls. • It is found in all major distribution of Linux, recent Windows and Solaris versions.
  • 15.
    Many-to-many model • Inthis model a pool of user threads is mapped to a pool of kernel threads. All system calls from a user thread pool are handled by the threads in their corresponding kernel thread pool
  • 16.
    both many tomany and one to one model depending upon choice made by the kernel. This is found in old versions of IRIX, HP-UX and Solaris.
  • 17.
    System Calls asinterface between Running Programming and OS • System calls provide the interface between a running program and the operating system. • Generally available as assembly-language instructions. • Languages defined to replace assembly language for systems programming allow system calls to be made directly (e.g., C, C++) • Three general methods are used to pass parameters between a running program and the operating system. • Pass parameters in registers. • Store the parameters in a table in memory, and the table address is passed as a parameter in a register. • Push (store) the parameters onto the stack by the program, and pop off the stack by operating system.
  • 18.
    Types of SystemCalls • Process control • File management • Device management • Information maintenance • Communications
  • 19.
    Process control • 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
  • 20.
    File manipulation • createfile, delete file • open, close • read, write, reposition • get file attributes, set file attributes
  • 21.
    Device manipulation • requestdevice, release device • read, write, reposition • get device attributes, set device attributes • logically attach or detach devices
  • 22.
    Information maintenance • gettime or date, set time or date • get system data, set system data • get process, file, or device attributes • set process, file, or device attributes
  • 23.
    Communications • create, deletecommunication connection • send, receive messages • transfer status information • attach or detach remote devices
  • 24.
    Assignment • Explain theconcept of System Call