This document discusses an operating systems lecture for a computer science course. It covers topics like system components, operating system services, system calls, how system calls work, different types of system calls like process control and file management, examples of system calls in Windows and Unix, and system programs. It provides examples of how a C program can make system calls and definitions of key concepts like what a system call is and how it allows programs to interface with the operating system kernel.
1 of 28
More Related Content
CS403: Operating System : Lec 5 System calls.pptx
1. OPERATING SYSTEM
(R18 II(II Sem))
Department of computer science and engineering (AI & ML)
LEC 5
by
Asst.Prof.M.Gokilavani
VITS
6/11/2023 Department of CSE (AI/ML) 1
4. TEXTBOOK:
• Operating System Principles- Abraham Silberchatz, Peter B. Galvin, Greg
Gagne 7th Edition, John Wiley.
• Advanced programming in the UNIX environment, W.R. Stevens, Pearson
education.
REFERENCES:
• Operating Systems – Internals and Design Principles Stallings, Fifth Edition–
2005, Pearson Education/PHI.
• Operating System A Design Approach- Crowley, TMH.
• Modern Operating Systems, Andrew S. Tanenbaum 2nd edition, Pearson/PHI.
• UNIX programming environment, Kernighan and Pike, PHI/ Pearson Education.
• UNIX Internals -The New Frontiers, U. Vahalia, Pearson Education
6/11/2023 Department of CSE (AI/ML) 4
5. Topics covered in Lec 5
6/11/2023 Department of CSE (AI/ML) 5
UNIT – I: Operating System - Introduction, Structures - Simple Batch,
Multiprogrammed, Time-shared, Personal Computer, Parallel, Distributed
Systems, Real-Time Systems, System components, Operating System
services, System Calls.
6. System calls in OS
• A system call is a way for a user program to interface with the
operating system.
• The program requests several services, and the OS responds by
invoking a series of system calls to satisfy the request.
• A system call can be written in assembly language or a high-level
language like C or Pascal.
• System calls are predefined functions that the operating system may
directly invoke if a high-level language is used.
6/11/2023 Department of CSE (AI/ML) 6
7. What is a System Call?
• A system call is a method for a computer program to request a service from
the kernel of the operating system on which it is running.
• A system call is a method of interacting with the operating system via
programs.
• A system call is a request from computer software to an operating system's
kernel.
• The Application Program Interface (API) connects the operating system's
functions to user programs.
• It acts as a link between the operating system and a process, allowing user-
level programs to request operating system services.
• The kernel system can only be accessed using system calls.
• System calls are required for any programs that use resources.
6/11/2023 Department of CSE (AI/ML) 7
8. How are system calls made?
• When a computer software needs to access the operating system's kernel, it makes a system call.
• The system call uses an API to expose the operating system's services to user programs.
• It is the only method to access the kernel system.
• All programs or processes that require resources for execution must use system calls, as they serve
as an interface between the operating system and user programs.
Below are some examples of how a system call varies from a user function.
• A system call function may create and use kernel processes to execute the asynchronous
processing.
• A system call has greater authority than a standard subroutine. A system call with kernel-mode
privilege executes in the kernel protection domain.
• System calls are not permitted to use shared libraries or any symbols that are not present in the
kernel protection domain.
• The code and data for system calls are stored in global kernel memory.
6/11/2023 Department of CSE (AI/ML) 8
9. Example of System Calls
• System call sequence to copy the contents of one file to another file.
6/11/2023 Department of CSE (AI/ML) 9
11. Why do you need system calls in Operating System?
There are various situations where you must require system calls in the
operating system. Following of the situations are as follows:
• It is must require when a file system wants to create or delete a file.
• Network connections require the system calls to sending and receiving
data packets.
• If you want to read or write a file, you need to system calls.
• If you want to access hardware devices, including a printer, scanner,
you need a system call.
• System calls are used to create and manage new processes.
6/11/2023 Department of CSE (AI/ML) 11
12. How System call works?
• 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)
6/11/2023 Department of CSE (AI/ML) 12
13. API – System Call – OS Relationship
6/11/2023 Department of CSE (AI/ML) 13
14. 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
6/11/2023 Department of CSE (AI/ML) 14
16. Types of System Calls
6/11/2023 Department of CSE (AI/ML) 16
17. Types of System Calls
• Process control
• create process, terminate process
• end, abort
• load, execute
• get process attributes, set process attributes
• wait for time
• wait event, signal event
• allocate and free memory
• Dump memory if error
• Debugger for determining bugs, single step execution
• Locks for managing access to shared data between processes
6/11/2023 Department of CSE (AI/ML) 17
18. Types of System Calls
• File management
• create file, delete file
• open, close file
• read, write, reposition
• get and set file attributes
• Device management
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices
• Protection
• Control access to resources
• Get and set permissions
• Allow and deny user access
6/11/2023 Department of CSE (AI/ML) 18
19. Types of System Calls (Cont.)
• Information maintenance
• get time or date, set time or date
• get system data, set system data
• get and set process, file, or device attributes
• 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
6/11/2023 Department of CSE (AI/ML) 19
20. Examples of Windows and Unix System Calls
6/11/2023 Department of CSE (AI/ML) 20
21. Standard C Library Example
• C program invoking printf() library call, which calls write() system
call.
6/11/2023 Department of CSE (AI/ML) 21
22. Example: MS-DOS
6/11/2023 Department of CSE (AI/ML) 22
• Single-tasking
• Shell invoked when system booted
• Simple method to run program
• No process created
• Single memory space
• Loads program into memory, overwriting all but the kernel
• Program exit -> shell reloaded
23. System Programs
• 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
• Most users’ view of the operation system is defined by system programs, not the
actual system calls
6/11/2023 Department of CSE (AI/ML) 23
25. System Programs
• Provide a convenient environment for program development and execution
• Some of them are simply user interfaces to system calls; others are
considerably more complex.
• File management - Create, delete, copy, rename, print, dump, list, and
generally manipulate files and directories.
• 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.
6/11/2023 Department of CSE (AI/ML) 25
26. System Programs
• File modification
• Text editors to create and modify files
• Special commands to search contents of files or perform transformations of the
text
• Programming-language support - Compilers, assemblers, debuggers and
interpreters sometimes provided
• Program loading and execution- Absolute loaders, relocatable loaders, linkage
editors, and overlay-loaders, debugging systems for higher-level and machine
language
• 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.
6/11/2023 Department of CSE (AI/ML) 26
27. System Programs
• Background Services
• Launch at boot time
• Some for system startup, then terminate
• Some from system boot to shutdown
• Provide facilities like disk checking, process scheduling, error logging,
printing
• Run in user context not kernel context
• Known as services, subsystems, daemons
• Application programs
• Don’t pertain to system
• Run by users
• Not typically considered part of OS
• Launched by command line, mouse click, finger poke
6/11/2023 Department of CSE (AI/ML) 27
28. Topics to be covered in next Lec 6
•Operating System Structure
6/11/2023 Department of CSE (AI/ML) 28
Thank you!!!