SlideShare une entreprise Scribd logo
1  sur  17
© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
System Calls
2© 2010-19 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-19 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-19 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-19 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-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
System Call Execution Flow
…
xyz()
...
xyz() {
…
SYSCALL
…
}
system_call:
…
sys_xyz()
SYSEXIT
sys_xyz() {
…
...
}
System Call
invocation in
application
program
Wrapper
routine in libc
standard
library
System Call
handler
System Call
service routine
User Mode Kernel Mode
7© 2010-19 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, ...)
8© 2010-19 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)
9© 2010-19 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
10© 2010-19 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
11© 2010-19 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
12© 2010-19 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
13© 2010-19 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
14© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
System Call: access
Helps to determine whether the calling process
has access permission for a particular file
int access(const char *pathname, int mode);
pathname – Path to the file
mode – Accessibility checks. F_OK or a mask
consisting of bitwise or of R_OK, W_OK and X_OK
15© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
System Call: fcntl
Is used for performing the various advanced
operations on an open file descriptor
It allows to place a read or write lock on the file
More than one process can hold the read lock,
while only one process can hold the write lock
int fcntl(int fd, int cmd, ... /* arg */ )
fd – File descriptor
cmd – Operation to perform
… – Arguments
16© 2010-19 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
17© 2010-19 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?

Contenu connexe

Tendances (20)

Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
Processes
ProcessesProcesses
Processes
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
File System Modules
File System ModulesFile System Modules
File System Modules
 
System calls
System callsSystem calls
System calls
 
Part 04 Creating a System Call in Linux
Part 04 Creating a System Call in LinuxPart 04 Creating a System Call in Linux
Part 04 Creating a System Call in Linux
 
Block Drivers
Block DriversBlock Drivers
Block Drivers
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & Profiling
 
Linux Network Management
Linux Network ManagementLinux Network Management
Linux Network Management
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
System call
System callSystem call
System call
 
Introduction to System Calls
Introduction to System CallsIntroduction to System Calls
Introduction to System Calls
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
Introduction to Linux Drivers
Introduction to Linux DriversIntroduction to Linux Drivers
Introduction to Linux Drivers
 
Embedded Storage Management
Embedded Storage ManagementEmbedded Storage Management
Embedded Storage Management
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 
Studying a decade of Linux system calls
Studying a decade of Linux system callsStudying a decade of Linux system calls
Studying a decade of Linux system calls
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded Systems
 

Similaire à System Calls

Similaire à System Calls (20)

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
 
Operating system structures
Operating system structuresOperating system structures
Operating system structures
 
Operating System- Structures of Operating System
Operating System- Structures of Operating SystemOperating System- Structures of Operating System
Operating System- Structures of Operating System
 
Operation system structure
Operation system structureOperation system structure
Operation system structure
 
Ch2
Ch2Ch2
Ch2
 
Ch2
Ch2Ch2
Ch2
 
CH02.pdf
CH02.pdfCH02.pdf
CH02.pdf
 
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURESOPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
 
MODULE 2.ppt
MODULE 2.pptMODULE 2.ppt
MODULE 2.ppt
 
OS-ch02-part-1-2024.ppt
OS-ch02-part-1-2024.pptOS-ch02-part-1-2024.ppt
OS-ch02-part-1-2024.ppt
 
OS - Ch2
OS - Ch2OS - Ch2
OS - Ch2
 
Chapter 2 - Operating System Structures
Chapter 2 - Operating System StructuresChapter 2 - Operating System Structures
Chapter 2 - Operating System Structures
 
Ch2
Ch2Ch2
Ch2
 
Structure of operating system
Structure of operating systemStructure of operating system
Structure of operating system
 
os
osos
os
 
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
 

Plus de Anil Kumar Pugalia (19)

File System Modules
File System ModulesFile System Modules
File System Modules
 
Embedded C
Embedded CEmbedded C
Embedded C
 
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
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
References
ReferencesReferences
References
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISP
 
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
 
Timers
TimersTimers
Timers
 
Threads
ThreadsThreads
Threads
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Processes
ProcessesProcesses
Processes
 
Signals
SignalsSignals
Signals
 
Linux File System
Linux File SystemLinux File System
Linux File System
 

Dernier

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Dernier (20)

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

System Calls

  • 1. © 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. System Calls
  • 2. 2© 2010-19 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-19 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-19 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-19 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-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. System Call Execution Flow … xyz() ... xyz() { … SYSCALL … } system_call: … sys_xyz() SYSEXIT sys_xyz() { … ... } System Call invocation in application program Wrapper routine in libc standard library System Call handler System Call service routine User Mode Kernel Mode
  • 7. 7© 2010-19 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, ...)
  • 8. 8© 2010-19 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)
  • 9. 9© 2010-19 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
  • 10. 10© 2010-19 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
  • 11. 11© 2010-19 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
  • 12. 12© 2010-19 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
  • 13. 13© 2010-19 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
  • 14. 14© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. System Call: access Helps to determine whether the calling process has access permission for a particular file int access(const char *pathname, int mode); pathname – Path to the file mode – Accessibility checks. F_OK or a mask consisting of bitwise or of R_OK, W_OK and X_OK
  • 15. 15© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. System Call: fcntl Is used for performing the various advanced operations on an open file descriptor It allows to place a read or write lock on the file More than one process can hold the read lock, while only one process can hold the write lock int fcntl(int fd, int cmd, ... /* arg */ ) fd – File descriptor cmd – Operation to perform … – Arguments
  • 16. 16© 2010-19 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
  • 17. 17© 2010-19 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?