SlideShare ist ein Scribd-Unternehmen logo
1 von 14
© 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?

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Demand paging
Demand pagingDemand paging
Demand paging
 
Fuse- Filesystem in User space
Fuse- Filesystem in User space Fuse- Filesystem in User space
Fuse- Filesystem in User space
 
Unix ppt
Unix pptUnix ppt
Unix ppt
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Bsd ppt
Bsd pptBsd ppt
Bsd ppt
 
Case study windows
Case study windowsCase study windows
Case study windows
 
Disk management
Disk managementDisk management
Disk management
 
Unix case-study
Unix case-studyUnix case-study
Unix case-study
 
Storage Management in Linux OS.ppt
Storage Management in Linux OS.pptStorage Management in Linux OS.ppt
Storage Management in Linux OS.ppt
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
 
Windows V/S Linux OS - Comparison
Windows V/S Linux OS - ComparisonWindows V/S Linux OS - Comparison
Windows V/S Linux OS - Comparison
 
Linux Kernel Overview
Linux Kernel OverviewLinux Kernel Overview
Linux Kernel Overview
 
System call
System callSystem call
System call
 
6.Distributed Operating Systems
6.Distributed Operating Systems6.Distributed Operating Systems
6.Distributed Operating Systems
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Samba server
Samba serverSamba server
Samba server
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
Operating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsOperating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - Threads
 
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
 

Andere mochten auch (20)

Embedded C
Embedded CEmbedded C
Embedded C
 
Timers
TimersTimers
Timers
 
Signals
SignalsSignals
Signals
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Threads
ThreadsThreads
Threads
 
Linux Network Management
Linux Network ManagementLinux Network Management
Linux Network Management
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
References
ReferencesReferences
References
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
Introduction to Linux Drivers
Introduction to Linux DriversIntroduction to Linux Drivers
Introduction to Linux Drivers
 
Interrupts
InterruptsInterrupts
Interrupts
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & Profiling
 
Bootloaders
BootloadersBootloaders
Bootloaders
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISP
 
Board Bringup
Board BringupBoard Bringup
Board Bringup
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 

Ähnlich wie System Calls

Operation system structure
Operation system structureOperation system structure
Operation system structure
brysan30
 
Chapter 2 Operating System Structures.ppt
Chapter 2 Operating System Structures.pptChapter 2 Operating System Structures.ppt
Chapter 2 Operating System Structures.ppt
ErenJeager20
 
Chapter 2 Operating System Structures.ppt
Chapter 2 Operating System Structures.pptChapter 2 Operating System Structures.ppt
Chapter 2 Operating System Structures.ppt
alo154283
 

Ähnlich wie System Calls (20)

System Calls
System CallsSystem Calls
System Calls
 
W5 system call, DD, OS structure.ppt
W5 system call, DD, OS structure.pptW5 system call, DD, OS structure.ppt
W5 system call, DD, OS structure.ppt
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Operating System- Structures of Operating System
Operating System- Structures of Operating SystemOperating System- Structures of Operating System
Operating System- Structures of Operating System
 
Operating system structures
Operating system structuresOperating system structures
Operating system structures
 
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURESOPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
 
Operation system structure
Operation system structureOperation system structure
Operation system structure
 
Ch2
Ch2Ch2
Ch2
 
CH02.pdf
CH02.pdfCH02.pdf
CH02.pdf
 
MODULE 2.ppt
MODULE 2.pptMODULE 2.ppt
MODULE 2.ppt
 
Ch2
Ch2Ch2
Ch2
 
OS-ch02-part-1-2024.ppt
OS-ch02-part-1-2024.pptOS-ch02-part-1-2024.ppt
OS-ch02-part-1-2024.ppt
 
ch2.ppt
ch2.pptch2.ppt
ch2.ppt
 
Chapter 2 Operating System Structures.ppt
Chapter 2 Operating System Structures.pptChapter 2 Operating System Structures.ppt
Chapter 2 Operating System Structures.ppt
 
Chapter 2 Operating System Structures.ppt
Chapter 2 Operating System Structures.pptChapter 2 Operating System Structures.ppt
Chapter 2 Operating System Structures.ppt
 
ch2.ppt
ch2.pptch2.ppt
ch2.ppt
 
ch2.ppt
ch2.pptch2.ppt
ch2.ppt
 
ch2.ppt
ch2.pptch2.ppt
ch2.ppt
 
Operating-System Structures
Operating-System StructuresOperating-System Structures
Operating-System Structures
 

Mehr von Anil Kumar Pugalia (14)

File System Modules
File System ModulesFile System Modules
File System Modules
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
Processes
ProcessesProcesses
Processes
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
Video Drivers
Video DriversVideo Drivers
Video Drivers
 
Power of vi
Power of viPower of vi
Power of vi
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
 
"make" system
"make" system"make" system
"make" system
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
 
RPM Building
RPM BuildingRPM Building
RPM Building
 
Processes
ProcessesProcesses
Processes
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Linux File System
Linux File SystemLinux File System
Linux File System
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

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?