SlideShare a Scribd company logo
© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
System Calls
2© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What to Expect?
W's of System Calls
System Call vs Library Function
System Call Tracing
Hands-On
3© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
W's of System Calls
User programs vs Kernel programs
Runs in different spaces
Runs with different privileges
User space not allowed access to Kernel space
But they need the Kernel services
OS provides service points
For User programs
To request services from the Kernel
In Linux, these are called System Calls
4© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
System Calls in Linux
About 300 in count
Listing: /usr/include/asm/unistd.h
Provide layer between
Kernel Space (typically hardware)
User Space (typically user process)
Serve three purposes
Provide an Abstracted h/w interface for user space
Ensures System security and stability
Makes Process Management easier
5© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Working of a Linux System Call
Implemented as an ordinary function in the Linux Kernel
Executes like others in the Kernel Space
However, the call to that function isn't ordinary
When a user program makes a system call
Arguments are packaged up and handed to the kernel
A special procedure is required to transfer control to the kernel
Kernel takes over execution of the program until the call completes
Kernel transfers control back to the program with return value
Special procedure is typically achieved using “trap”
6© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Linux System Call Wrappers
Every System Call has standard steps
GNU C library (glibc) abstracts them
By wrapping with functions of same name
For easy invocation
Examples
I/O functions: open, read, ...
We rarely invoke direct system calls
But rather these system call (wrapper) functions
Any Exception?
Custom defined system call – using syscall(sno, ...)
7© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Contrast with a Library Function
A library function is an ordinary function
It resides in a library external to the program
But in the User Space only
Moreover, the call to it is also ordinary
Arguments placed in processor registers or the stack
Execution transferred to the start of the function
Typically resides in a loaded shared library
In the User Space only
Examples
fopen, printf, getopt, mkstemp (all from glibc)
8© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Return Values
Library functions often return pointers
Example: FILE * fp = fopen("harry","r");
NULL indicates failure
System calls usually return an integer
Example: int res = open(“harry”, O_RDONLY);
Return value
>= 0 indicates success
< 0, typically -1 indicates failure, and error is set in errno
Note the counter intuitive return of System Calls
Opposite way round
Cannot use as Boolean
9© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
More Information
Manual Sections
2 System calls e.g. _exit, read, write
3 Library calls e.g. exit, printf
7 Miscellaneous e.g. ascii, fifo, pthreads
9 POSIX Programmer Manual
Info pages are also available
10© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Tracing System Calls
Command: strace <program> [args]
Traces the execution of <program>
And Lists
System Calls made by <program>
Signals received by <program>
Controlled by various options
An interesting one is “-e”
Example
strace cat /dev/null
11© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Pros & Cons
Pros
System calls provide direct & hence more control over the
kernel services
Library functions abstract the nitty-gritty of architecture or
OS specific details of the system calls
Library functions can provide wrappers over repeated set
of system calls
Cons
Library functions may have overheads
System calls at times may expose the underlying system
dependency
12© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Let's try some Examples
System Call Invocation
System calls vs Library functions
File Operations
Observe the various system calls invoked
Use strace
13© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What all have we learnt?
W's of System Calls
Working of a System Call & syscall()
System Call Wrapper Functions
System Call vs Library Function
Pros & Cons
System Call Tracing
Hands-On
14© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?

More Related Content

PPTX
Media Access Control
PPTX
Security & protection in operating system
PPTX
Program Threats
PPTX
The sunsparc architecture
PPT
Protection and Security in Operating Systems
PPTX
Heap Management
PPT
Introduction to System Calls
PPTX
Addressing sequencing
Media Access Control
Security & protection in operating system
Program Threats
The sunsparc architecture
Protection and Security in Operating Systems
Heap Management
Introduction to System Calls
Addressing sequencing

What's hot (20)

PDF
8086 memory segmentation
PPT
OS Process and Thread Concepts
PPTX
Process state in OS
PPTX
System calls
PPT
Query Decomposition and data localization
PPTX
Handheld operting system
PPT
Sorting network
PPT
Computer Organization and Assembly Language
PPTX
INSTRUCTION LEVEL PARALLALISM
PPTX
Software Evolution
PPT
Web and http computer network
PDF
Difference among 8085,8086,80186,80286,80386 Microprocessor.pdf
PPTX
Input Output Organization
PPTX
Memory organization in computer architecture
PDF
Process & Thread Management
PPT
Computer Organization and Architecture.
PPTX
Common Standards in Cloud Computing
PPTX
Io techniques & its types
8086 memory segmentation
OS Process and Thread Concepts
Process state in OS
System calls
Query Decomposition and data localization
Handheld operting system
Sorting network
Computer Organization and Assembly Language
INSTRUCTION LEVEL PARALLALISM
Software Evolution
Web and http computer network
Difference among 8085,8086,80186,80286,80386 Microprocessor.pdf
Input Output Organization
Memory organization in computer architecture
Process & Thread Management
Computer Organization and Architecture.
Common Standards in Cloud Computing
Io techniques & its types
Ad

Viewers also liked (20)

PDF
Embedded C
PDF
PDF
Synchronization
PDF
PDF
Linux Network Management
PDF
Network Drivers
PDF
Inter Process Communication
PDF
Kernel Debugging & Profiling
PDF
References
PDF
Character Drivers
PDF
Introduction to Linux Drivers
PDF
Interrupts
PDF
Shell Scripting
PDF
Linux User Space Debugging & Profiling
PDF
Bootloaders
PDF
Functional Programming with LISP
PDF
Board Bringup
PDF
Embedded Software Design
PDF
Mobile Hacking using Linux Drivers
Embedded C
Synchronization
Linux Network Management
Network Drivers
Inter Process Communication
Kernel Debugging & Profiling
References
Character Drivers
Introduction to Linux Drivers
Interrupts
Shell Scripting
Linux User Space Debugging & Profiling
Bootloaders
Functional Programming with LISP
Board Bringup
Embedded Software Design
Mobile Hacking using Linux Drivers
Ad

Similar to System Calls (20)

PDF
System Calls
PPTX
Services and system calls
PPTX
Systemcall1
PPT
System calls in Linux environment for beginners
PPTX
OS SERVICES.pptxJGHHHHHHHHHHHHHHHHGGGGGGGG
PDF
CNIT 127: Ch 3: Shellcode
PDF
Trap Handling in Linux
PDF
Part 04 Creating a System Call in Linux
PPTX
2_System Calls.pptx
PPTX
Comsats University Islamabad OS lab 03.pptx
PDF
CNIT 127 Ch 3: Shellcode
PDF
CNIT 127 Ch 3: Shellcode
PPTX
A brief history of system calls
PDF
L03SystemCalls.pdf all about system call in os
PPT
Advanced c programming in Linux
PDF
Lecture2 process structure and programming
PPTX
System calls in operating sytems incluses operating sytem process
PDF
CNIT 127: 3: Shellcode
PPT
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
PPTX
session 4(system calls).pptxsession 4(system calls).pptx
System Calls
Services and system calls
Systemcall1
System calls in Linux environment for beginners
OS SERVICES.pptxJGHHHHHHHHHHHHHHHHGGGGGGGG
CNIT 127: Ch 3: Shellcode
Trap Handling in Linux
Part 04 Creating a System Call in Linux
2_System Calls.pptx
Comsats University Islamabad OS lab 03.pptx
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
A brief history of system calls
L03SystemCalls.pdf all about system call in os
Advanced c programming in Linux
Lecture2 process structure and programming
System calls in operating sytems incluses operating sytem process
CNIT 127: 3: Shellcode
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
session 4(system calls).pptxsession 4(system calls).pptx

More from Anil Kumar Pugalia (16)

PDF
File System Modules
PDF
Kernel Debugging & Profiling
PDF
PDF
Introduction to Linux
PDF
Playing with R L C Circuits
PDF
Audio Drivers
PDF
Video Drivers
PDF
Power of vi
PDF
gcc and friends
PDF
"make" system
PDF
Hardware Design for Software Hackers
PDF
RPM Building
PDF
PDF
Linux Memory Management
PDF
Linux File System
PDF
Introduction to Linux
File System Modules
Kernel Debugging & Profiling
Introduction to Linux
Playing with R L C Circuits
Audio Drivers
Video Drivers
Power of vi
gcc and friends
"make" system
Hardware Design for Software Hackers
RPM Building
Linux Memory Management
Linux File System
Introduction to Linux

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Encapsulation theory and applications.pdf
PPT
Teaching material agriculture food technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation_ Review paper, used for researhc scholars
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
Mobile App Security Testing_ A Comprehensive Guide.pdf
Review of recent advances in non-invasive hemoglobin estimation
Reach Out and Touch Someone: Haptics and Empathic Computing
Dropbox Q2 2025 Financial Results & Investor Presentation
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Encapsulation theory and applications.pdf
Teaching material agriculture food technology
Unlocking AI with Model Context Protocol (MCP)
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation_ Review paper, used for researhc scholars

System Calls

  • 1. © 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. System Calls
  • 2. 2© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? W's of System Calls System Call vs Library Function System Call Tracing Hands-On
  • 3. 3© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. W's of System Calls User programs vs Kernel programs Runs in different spaces Runs with different privileges User space not allowed access to Kernel space But they need the Kernel services OS provides service points For User programs To request services from the Kernel In Linux, these are called System Calls
  • 4. 4© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. System Calls in Linux About 300 in count Listing: /usr/include/asm/unistd.h Provide layer between Kernel Space (typically hardware) User Space (typically user process) Serve three purposes Provide an Abstracted h/w interface for user space Ensures System security and stability Makes Process Management easier
  • 5. 5© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Working of a Linux System Call Implemented as an ordinary function in the Linux Kernel Executes like others in the Kernel Space However, the call to that function isn't ordinary When a user program makes a system call Arguments are packaged up and handed to the kernel A special procedure is required to transfer control to the kernel Kernel takes over execution of the program until the call completes Kernel transfers control back to the program with return value Special procedure is typically achieved using “trap”
  • 6. 6© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Linux System Call Wrappers Every System Call has standard steps GNU C library (glibc) abstracts them By wrapping with functions of same name For easy invocation Examples I/O functions: open, read, ... We rarely invoke direct system calls But rather these system call (wrapper) functions Any Exception? Custom defined system call – using syscall(sno, ...)
  • 7. 7© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Contrast with a Library Function A library function is an ordinary function It resides in a library external to the program But in the User Space only Moreover, the call to it is also ordinary Arguments placed in processor registers or the stack Execution transferred to the start of the function Typically resides in a loaded shared library In the User Space only Examples fopen, printf, getopt, mkstemp (all from glibc)
  • 8. 8© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Return Values Library functions often return pointers Example: FILE * fp = fopen("harry","r"); NULL indicates failure System calls usually return an integer Example: int res = open(“harry”, O_RDONLY); Return value >= 0 indicates success < 0, typically -1 indicates failure, and error is set in errno Note the counter intuitive return of System Calls Opposite way round Cannot use as Boolean
  • 9. 9© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. More Information Manual Sections 2 System calls e.g. _exit, read, write 3 Library calls e.g. exit, printf 7 Miscellaneous e.g. ascii, fifo, pthreads 9 POSIX Programmer Manual Info pages are also available
  • 10. 10© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Tracing System Calls Command: strace <program> [args] Traces the execution of <program> And Lists System Calls made by <program> Signals received by <program> Controlled by various options An interesting one is “-e” Example strace cat /dev/null
  • 11. 11© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Pros & Cons Pros System calls provide direct & hence more control over the kernel services Library functions abstract the nitty-gritty of architecture or OS specific details of the system calls Library functions can provide wrappers over repeated set of system calls Cons Library functions may have overheads System calls at times may expose the underlying system dependency
  • 12. 12© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Let's try some Examples System Call Invocation System calls vs Library functions File Operations Observe the various system calls invoked Use strace
  • 13. 13© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What all have we learnt? W's of System Calls Working of a System Call & syscall() System Call Wrapper Functions System Call vs Library Function Pros & Cons System Call Tracing Hands-On
  • 14. 14© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?