System Calls: Types and Structure

System Calls

1. Memory Management

All data must be in memory before and after processing. All instructions must be in memory in order to execute.

Activities:

  • Optimizing CPU and computer response to users.
  • Keeping track of which parts of memory are currently being used and by whom.
  • Deciding which processes (or parts thereof) and data to move into and out of memory.
  • Allocating and deallocating memory space as needed.

2. Storage Management

  • Files are usually organized into directories.
  • Access control on most systems determines who can access what.
  • Creating and deleting files and directories.
  • Primitives to manipulate files and directories.
  • Mapping files onto secondary storage.
  • Backup files onto stable (nonvolatile) storage media.

3. I/O Subsystem

Hides peculiarities of hardware devices from the user.

  • Memory management of I/O includes:
    • Buffering: Storing data temporarily while it is being transferred.
    • Caching: Storing parts of data in faster storage for performance.
    • Spooling: Overlapping of output of one job with input of other jobs.

4. User OS Interface

  • CLI (Command Line Interface): Allows direct command entry (usually in the kernel).
  • GUI (Graphical User Interface): A user-friendly desktop metaphor interface.
  • Many systems include both CLI and GUI interfaces.

The KERNEL (supervisor mode) interacts with the user (protected mode) via system calls, which use interrupts.

5. System Calls

  • Each system call uses the same interrupt number (0x80).
  • Their associated number distinguishes system calls.
  • Arguments are passed to the kernel via registers.
  • The result values of a system call must be stored in user space (prepared by the user program).
  • The result is returned in a register.
  • The user cannot execute their own program in the kernel.

6. System API Standards

Three most used APIs:

  1. POSIX (Portable Operating System Interface for Unix): For LINUX, MAC
  2. WIN-32
  3. JAVA API

A) POSIX:

  • Defines system calls and programs.
  • Standard defines:
    • Name
    • Synopsis – int sum(int a, int b);
    • Description
    • Return value
    • Errors
    • Examples
    • See also – list of system calls related to it.

B) Win-32:

  • Not fully described.
  • Versions for 16, 32, and 64 bits.

7. Types of POSIX Calls

  • A) Process Control:
    • fork (create a new process)
    • exit (terminates it)
    • wait, waitpid (waits for a process to terminate)
    • execl (executes a program)
  • B) Memory Management (obsolete):
    • malloc (memory allocator)
    • free
  • C) File Access:
    • File – An object that can be written to, read from, or both. It has certain attributes, including access permissions and type. To access any file, it must first be opened using an open() call that returns a file descriptor (fd). (0-Stdin, 1-Stdout, 2-Stderr).
    • open, close, write, read, lseek (move the read/write file offset), stat, dup (duplicates an open fd), chmod (change mode of a file), pipe (creates an inter-process communication channel)
  • D) File & Directory Management:
    • mkdir (create a directory relative to a directory fd)
    • rmdir, chdir, link (link one file to another file), unlink (delete a system file)
  • E) Device Management:
    • ioctl (control a device)
  • F) Other:
    • kill, signal

8. Microkernel System Structure

  • Moves as much from the kernel into user space as possible.
  • Communication takes place between user modules using message passing.
  • Pros: Easier to extend and port to new architectures. More reliable and secure.
  • Cons: Performance overhead of user space to kernel space communication.

Questions and Answers

  • RR scheduling gives a small amount of CPU time: B) for each ready process
  • A preemptive scheduler can temporarily interrupt a process: B) at any time
  • If it’s not preemptive: A) only if the process allows this action.
  • An OS with kernel thread support: A) has a scheduler that plans with threads
  • Semaphores solve: B) Problem of critical section
  • A critical section is: C) part of code that uses a shared resource
  • Scheduling can prevent deadlock: A) If there is information about all processes’ demands
  • Event Segmentation fault becomes: B) If the offset is bigger than segment size
  • Event page fault becomes: A) If the memory cell is not in physical memory
  • Segments: A) Have arbitrary size
  • Segmentation compared to paging has: A) smaller internal fragmentation
  • Demand paging: A) loads into memory only used page
  • Working set represents pages: A) That one process used as last N instructions