+ All Categories
Home > Documents > 1_ systemcalls

1_ systemcalls

Date post: 06-Apr-2018
Category:
Upload: mahsa-ranjbar
View: 227 times
Download: 0 times
Share this document with a friend

of 20

Transcript
  • 8/3/2019 1_ systemcalls

    1/20

    Operating System

    A collection of system programs which allow theuser to run application software.

    manages processes and resources.

    abstracts the real hardware of the system andpresents the users and applications with a virtual

    machine.

    has utilities for system administration tasks.

  • 8/3/2019 1_ systemcalls

    2/20

    OS Mechanisms

    Two mechanisms for controlling accessto system resources are

    different modes of execution

    system calls

  • 8/3/2019 1_ systemcalls

    3/20

    Processor Modes

    Modern processors typically can operate in 2 modes:"user mode" and "kernel mode " .

    User mode

    processor executes normal instructions in the user's program.

    Kernel mode

    processor executes both normal and privileged instructions

    Processor can access additional registers and memory address

    space that are accessible only in kernel mode

  • 8/3/2019 1_ systemcalls

    4/20

    Kernel

    The kernel is the core of the operatingsystem.

    It consists of code and data structures that

    are protected and can be accessed only in the

    kernel mode.

  • 8/3/2019 1_ systemcalls

    5/20

  • 8/3/2019 1_ systemcalls

    6/20

    System Calls

    User programs are not allowed to accesssystem resources directly. They must ask theOS to do that for them.

    OS provides a set of functions that can be

    called by user programs to request for OS

    services. These functions are called system

    calls

  • 8/3/2019 1_ systemcalls

    7/20

    System Calls

    System calls run in kernel mode.

    They can be called by executing a special

    instruction (trap or software interrupt) which

    causes processor to switch to the kernel mode andjump to a previously defined location in the

    kernel.

    When the system call finishes, processor returnsto the user program and runs in user mode.

  • 8/3/2019 1_ systemcalls

    8/20

  • 8/3/2019 1_ systemcalls

    9/20

    Differences between library functions andsystem calls

    System calls run in kernel-mode but libraryfunctions run in user-mode and may callsystem calls.

    System calls are not linked to user

    programs.

    There are only a small number of system

    calls. (about 250 in Linux, see /usr/include/asm/unistd.h )

  • 8/3/2019 1_ systemcalls

    10/20

    Solaris System Calls

    Solaris has about 200 system calls.

    Files and I/O

    Process management

    Interprocess communication

    Others

  • 8/3/2019 1_ systemcalls

    11/20

    System Calls: Files & I/O

    open, close open and close a file

    create, unlink create and remove a file

    read, write read and write a file

    lseek move to a specified byte in a file

    chmod change access permission mode

    mkdir, rmdir make and remove a directory

    stat get file status

    ioctl control device

  • 8/3/2019 1_ systemcalls

    12/20

    System Calls: Process Management

    fork create a new process exec execute a file

    exit terminate proces

    wait wait for a child process to terminate

    sbrk change the size of the space allocated in theheap data segment of the process (used by memory

    allocation functions, e.g. malloc)

  • 8/3/2019 1_ systemcalls

    13/20

    System Calls: Interprocess Communication

    kill, sigsend send a signal to a process pause suspend process until signal

    sigaction set signal handler

  • 8/3/2019 1_ systemcalls

    14/20

    Programming in UNIX

    Programming in a UNIX system (and modernoperating systems) often relies on two concepts:

    controlled access to system services

    realized by having system calls running in privileged

    mode

    common interface, various implementations

    realized by API

  • 8/3/2019 1_ systemcalls

    15/20

    Programming with System Calls

    High level languages, including C, providefunctions for programmers to use systemcalls just like normal function.

    /usr/include/unistd.h

    man -s 2 intro (Solaris) or man 2 intro

    (Linux)

  • 8/3/2019 1_ systemcalls

    16/20

    errno and perror

    When a system call fails, it usually returns -1 and

    sets the global variable errno to a value describingwhat went wrong.

    The function perror() translates this error code

    into human-readable form and prints a system error

    message.

    void perror(const char *s);

    The argument string s is printed first, then the

    system error message. Usually s is a user message

    indicating where the error occurs.

  • 8/3/2019 1_ systemcalls

    17/20

    API (Application Programming Interface)

    An API is a set of functions provided by an operatingsystem or other system software.

    An application program calls the functions to request the

    services.

    An API clearly defines how to call functions and what

    the results are. (API is specification, not implementation)

    Examples: APIs for file system, graphics user interface,networking, etc.

  • 8/3/2019 1_ systemcalls

    18/20

    Advantages of Using API

    Portability User programs that follow the APIs definition are portable.

    An API can provide a common interface for different

    implementations of a service.

    For example, the UNIX file system API is the same for all

    kinds of devices.

    X windows API has many implementations on different

    machine architectures

    Using an API allows upgrading system software without

    changing user programs

  • 8/3/2019 1_ systemcalls

    19/20

    Privileged Instructions

    Two modes of execution --> two kinds ofinstructions :

    normal instructions, e.g., add, sub, etc.

    privileged instructions, e.g.,

    read/write reserved registers

    read/write protected memory

  • 8/3/2019 1_ systemcalls

    20/20

    Exception Mechanism

    Switching from user mode to kernel mode to perform systemoperations and return to user mode

    Exception is caused by hardware interupt (I/O) and software

    interrupt

    Software interrupt or trap Some special instructions cause processor to switch between

    user and kernel modes: trap , return_from_trap

    Exception Handler

    When an exception occurs, an exception handler is called.

    Exception handler code is in kernel's protected memory Exception hander code for software traps are system calls


Recommended