OS Structure_System Calls
OS Structure_System Calls
o To describe the services an operating system provides to users, processes, and other
systems
o To explain how operating systems are installed and customized and how they boot
machine’s hardware?
o It manages system resources, including the CPU, memory, and I/O devices, and ensures that multiple
applications can run simultaneously without interfering with each other.
o Thus, kernel is responsible for essential tasks like process management, memory management, file
systems, and device control.
Resource Management:
• CPU Scheduling: The kernel decides which process or thread gets to use the CPU and for how long, ensuring
efficient execution and multitasking.
• Memory Management: It manages the allocation and deallocation of memory space to various programs. This
includes handling virtual memory, paging, and swapping.
• Device Management: The kernel controls and coordinates the use of hardware devices, such as disks, printers,
and network interfaces, through device drivers.
• File System Management: It manages file operations, including reading, writing, creating, and deleting files, as
well as ensuring data security and integrity.
Process Management:
• The kernel handles the creation, scheduling, and termination of processes. It manages process states, inter-
process communication (IPC), and synchronization between processes.
• The kernel enforces security policies, ensuring that applications cannot access unauthorized
memory areas or perform unauthorized operations. It also handles user permissions and protects
system integrity.
• The kernel provides the system calls interface, which allows user programs to request services from
the operating system, such as file handling, process control, and device management.
• Access Level: Programs running in user mode cannot directly access hardware or system resources like
memory, I/O devices, or the CPU. They must use system calls to request services from the kernel, which
operates in kernel mode.
• Safety: Because user mode has restricted access, any crashes or bugs in user-mode programs are less
likely to affect the entire system. The operating system can isolate and handle such errors without
compromising overall stability.
• Access Level: In kernel mode, the kernel can execute any CPU instruction and access any memory
address or hardware device. This unrestricted access allows the kernel to manage system resources
effectively and perform critical operations like process scheduling, memory management, and device
control.
• Risk: Since kernel mode has full system access, errors or bugs in the kernel can cause the entire system
to crash or become unstable. Therefore, only trusted, low-level code, such as the OS kernel and device
drivers, runs in this mode.
o One set of operating-system services provides functions that are helpful to the user:
• User interface - Almost all operating systems have a user interface (UI).
• Program execution - The system must be able to load a program into memory and to run that
program, end execution, either normally or abnormally (indicating error)
• I/O operations - A running program may require I/O, which may involve a file or an I/O device
• File-system manipulation - Programs need to read and write files and directories, create and delete them, search
them, list file Information, permission management.
• Communications – Processes may exchange information, on the same computer or between computers over a
network
▪ Communications may be via shared memory or through message passing (packets moved by the OS)
▪ May occur in the CPU and memory hardware, in I/O devices, in user program
▪ For each type of error, OS should take the appropriate action to ensure correct and consistent computing
▪ Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system
o Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing
• Resource allocation - When multiple users or multiple jobs running concurrently, resources must be allocated to
each of them
▪ Many types of resources - CPU cycles, main memory, file storage, I/O devices.
• Accounting - To keep track of which users use how much and what kinds of computer resources
• Protection and security - The owners of information stored in a multiuser or networked computer system may want
to control use of that information, concurrent processes should not interfere with each other
▪ Security of the system from outsiders requires user authentication, extends to defending external I/O devices
from invalid access attempts
l Voice commands.
o They allow user-level processes to request services from the kernel of the operating
system.
• System calls act as a gateway for user programs to interact with the underlying
hardware and system resources.
• Since user programs typically do not have direct access to the hardware or
critical resources, they must go through system calls to request such access.
Note that the system-call names used throughout this text are generic
Operating System Concepts
Types of System Calls
• Process Control: Includes system calls for process creation, termination, and management (e.g., fork(),
exec(), exit(), wait()).
• File Management: Deals with file operations like creation, deletion, reading, writing, and setting
attributes (e.g., open(), read(), write(), close()).
• Device Management: Used to request device operations or manage device inputs and outputs (e.g.,
ioctl(), read(), write()).
• Information Maintenance: Includes system calls for getting or setting the system data (e.g., getpid() to
get process ID, alarm() to set timers).
• Communication: Used for inter-process communication, including sending and receiving messages,
establishing and managing connections (e.g., pipe(), shmget() for shared memory, send(), recv() for
network communication).
• They maintain abstraction between applications and hardware, enabling developers to write programs without
concern for hardware specifics.
o System call sequence to copy the contents of one file to another file
o The system call interface invokes the intended system call in OS kernel and returns status of
o 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
▪ Managed by run-time support library (set of functions built into libraries included with compiler)
o Often, more information is required than simply identity of desired system call
• Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a
register
• 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
o File management
• create file, delete file
• open, close file
• read, write, reposition
• get and set file attributes
o Device management
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices
o Information maintenance
• get time or date, set time or date
• get system data, set system data
• get and set process, file, or device attributes
o Communications
• create, delete communication connection
• send, receive messages if message passing model to
host name or process name
▪ From client to server
• Shared-memory model create and gain access to
memory regions
• transfer status information
• attach and detach remote devices
o Protection
• Control access to resources
• Get and set permissions
• Allow and deny user access
o C program invoking printf() library call, which calls write() system call
o Single-tasking
o Shell invoked when
system booted
o Simple method to run
program
• No process created
o Single memory space
o Loads program into
memory, overwriting all
but the kernel
o Program exit -> shell
reloaded At system startup running a program
o System programs provide a convenient environment for program development and execution.
They can be divided into:
• File manipulation
• Status information sometimes stored in a File modification
• Programming language support
• Program loading and execution
• Communications
• Background services
• Application programs
o Most users’ view of the operation system is defined by system programs, not the actual system
calls
o File management - Create, delete, copy, rename, print, dump, list, and
generally manipulate files and directories
o Status information
• Some ask the system for info - date, time, amount of available memory,
disk space, number of users
• Others provide detailed performance, logging, and debugging information
• Typically, these programs format and print the output to the terminal or
other output devices
• Some systems implement a registry - used to store and retrieve
configuration information
o File modification
o Program loading and execution- Absolute loaders, relocatable loaders, linkage editors, and overlay-
loaders, debugging systems for higher-level and machine language
o Communications - Provide the mechanism for creating virtual connections among processes, users, and
computer systems
• Allow users to send messages to one another’s screens, browse web pages, send electronic-mail
messages, log in remotely, transfer files from one machine to another
o Application programs
• Don’t pertain to system
• Run by users
• Not typically considered part of OS
• Launched by command line, mouse click, finger poke
o Much variation
• Early OSes in assembly language
• Then system programming languages like Algol, PL/1
• Now C, C++
o Actually usually a mix of languages
• Lowest levels in assembly
• Main body in C
• Systems programs in C, C++, scripting languages like
PERL, Python, shell scripts
o More high-level language easier to port to other hardware
• But slower
o Emulation can allow an OS to run on non-native hardware
messages messages
microkernel
hardware
kernel environment
BSD
Mach
Application Framework
surface media
Dalvik
manager framework
virtual machine
webkit libc
Linux kernel