SlideShare a Scribd company logo
2
Most read
5
Most read
6
Most read
OPERATING SYSTEMS
System Calls
INTRODUCTION
Know it!
In computing, a system call is a programmatic way in
which a computer program requests a service from the
kernel of the operating system it is executed on.
A system call allows programs to interact with the
operating system.
A computer program makes a system call when it
makes a request to the operating system’s kernel.
All programs needing resources must use system calls.
Example
For example, if we need to write a program code to
read data from one file, copy that data into another file.
The first information that the program requires is the
name of the two files, the input and output files.
In an interactive system, this type of program
execution requires some system calls by OS.
First call is to write a prompting message on the
screen
Second, to read from the keyboard, the characters
which define the two files.
System Calls - Introduction
System Calls - Introduction
Kernel Mode Vs User Mode
Some system calls -
Some use cases
Reading and writing from files demand system calls.
If a file system wants to create or delete files, system
calls are required.
System calls are used for the creation and
management of new processes.
Network connections need system calls for sending
and receiving packets.
Access to hardware devices like scanner, and printer,
need a system call.
wait()
In some systems, a process needs to wait for another
process to complete its execution. This type of
situation occurs when a parent process creates a child
process, and the execution of the parent process
remains suspended until its child process executes.
The suspension of the parent process automatically
occurs with a wait() system call. When the child
process ends execution, the control moves back to the
parent process.
System Calls - Introduction
fork()
Processes use this system call to create processes
that are a copy of themselves.
With the help of this system Call parent process
creates a child process, and the execution of the parent
process will be suspended till the child process
executes.
Example
#include<stdio.h>
#include<unistd.h>
int main(){
printf("PID = %dn", getpid());
return 0;
}
getid()
Getpid() is the function used to get the process ID of
the process that calls that function. The PID for the
initial process is 1, and then each new process is
assigned a new Id. It is a simple approach to getting
the PID.
Example
#include<stdio.h>
#include<unistd.h>
int main(){
fork();
printf("PID = %dn", getpid());
return 0;
}
fork() system call is used to create a separate, duplicate process)
Example
#include<stdio.h>
#include<unistd.h>
int main(){
fork();
fork();
fork();
printf("PID = %dn", getpid());
return 0;
}
Prints 8 times!!
P1 P2 P6
P4
P3
P5
P8 P7
Example
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include <sys/wait.h>
int main(){
int fd[2],n;
char buffer[100];
pid_t p;
pipe(fd);
p = fork();
}
if(p>0){
close(fd[0]);
printf("Passing value to child!n");
write(fd[1],"Hello my child!!",15);
printf("n");
wait(NULL);
}
else{
close(fd[1]);
n = read(fd[0], buffer, 100);
write(1,buffer,n);
}
STEPS IN SYSTEM
CALLS
In steps 1-3, the calling program pushes the parameters onto the stack. The first and third
parameters are called by value, but the second one is called by its address as denoted by the
& symbol.
In step 4, the actual call to the library procedure is made. This instruction is the normal
procedure call instruction used to call all procedures.
In step 5, the library procedure places the system call number in a place where the operating
system expects it, such as a register.
In step 6, the library procedure executes a TRAP instruction to switch from user mode to
kernel mode and start execution at a fixed address within the kernel.
In step 7, the kernel examines the system call number and then dispatches it to the correct
system call handler. This correct number is given in the table of system call handlers by
pointers referenced at the system call number.
In step 8, the system call handler runs.
In step 9, the operation is completed, and the user is given back control once the TRAP
instruction is set.
In step 10, this procedure returns to the user program, like how all normal library procedures
do.
In step 11, the operating system has to clear the stack, so it increments it enough so that it is
empty.
Practice
#include<stdio.h>
#include<unistd.h>
int main(){
fork();
fork();
fork();
fork();
printf("PID = %dn", getpid());
return 0;
}
How many times would the printf statement be executed??
Practice
#include<stdio.h>
#include<unistd.h>
int main(){
fork();
fork();
fork();
fork();
printf("PID = %dn", getpid());
return 0;
}
16 process | 15 child process | 1 root process
Thank you!!

More Related Content

PPTX
Synopsys Fusion Compiler-Comprehensive RTL-to-GDSII Implementation System
PDF
Programed I/O Modul..
PPTX
Registers siso, sipo
PPTX
Unit vi (2)
PPTX
Trends in Embedded system Design
PDF
Embedded Operating System - Linux
PDF
Introduction to FPGA, VHDL
Synopsys Fusion Compiler-Comprehensive RTL-to-GDSII Implementation System
Programed I/O Modul..
Registers siso, sipo
Unit vi (2)
Trends in Embedded system Design
Embedded Operating System - Linux
Introduction to FPGA, VHDL

What's hot (20)

PPTX
Spi in arm7(lpc2148)
PPTX
Unit vi (1)
PPTX
Introduction Linux Device Drivers
PPTX
Arduino course
PPTX
FULL CUSTOM, STANDARD CELLS - VLSI Design Styles.pptx
PPTX
Math coprocessor 8087
PPTX
Unit2 Software engineering UPTU
PPTX
Latches and flip flops
PPTX
UNIT 3 Peripheral Interfacing.pptx
DOCX
Instruction set of 8086
PDF
ModelSim 기초 매뉴얼
PPT
Minterm and maxterm
PPTX
Synthesis
PPTX
Introduction to arm processor
PPT
Introduction to Interrupts of 8085 microprocessor
PDF
Interrupt handling
PPTX
Powerplanning
PDF
Linux kernel modules
PPTX
System Engineering Unit 5
PPTX
SPI introduction(Serial Peripheral Interface)
Spi in arm7(lpc2148)
Unit vi (1)
Introduction Linux Device Drivers
Arduino course
FULL CUSTOM, STANDARD CELLS - VLSI Design Styles.pptx
Math coprocessor 8087
Unit2 Software engineering UPTU
Latches and flip flops
UNIT 3 Peripheral Interfacing.pptx
Instruction set of 8086
ModelSim 기초 매뉴얼
Minterm and maxterm
Synthesis
Introduction to arm processor
Introduction to Interrupts of 8085 microprocessor
Interrupt handling
Powerplanning
Linux kernel modules
System Engineering Unit 5
SPI introduction(Serial Peripheral Interface)
Ad

Similar to System Calls - Introduction (20)

PDF
Os lab final
PPTX
Operating systems Lab program: to develop C program to implement process mana...
PPT
process creation OS
PDF
OS Lab 05.pdfdxsffffffffffxxxxgsssssfdgg
PDF
Operating System Lecture 4 on Different Topics
PPTX
OS presentation (1).pptx
PPT
1. Von Neumann + Booting Sequence + System Calls.ppt
PPTX
Systemcall1
PPTX
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
DOCX
Program Assignment Process ManagementObjective This program a.docx
PDF
Lecture2 process structure and programming
PPTX
Process management
PPT
What is-a-computer-process-os
PPT
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
PPT
DOCX
httplinux.die.netman3execfork() creates a new process by.docx
PDF
System calls
DOC
computer notes - Inter process communication
Os lab final
Operating systems Lab program: to develop C program to implement process mana...
process creation OS
OS Lab 05.pdfdxsffffffffffxxxxgsssssfdgg
Operating System Lecture 4 on Different Topics
OS presentation (1).pptx
1. Von Neumann + Booting Sequence + System Calls.ppt
Systemcall1
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
Program Assignment Process ManagementObjective This program a.docx
Lecture2 process structure and programming
Process management
What is-a-computer-process-os
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
httplinux.die.netman3execfork() creates a new process by.docx
System calls
computer notes - Inter process communication
Ad

More from To Sum It Up (20)

PPTX
Django Framework Interview Guide - Part 1
PPTX
Artificial intelligence ( AI ) | Guide
PPTX
On Page SEO (Search Engine Optimization)
PDF
Prompt Engineering | Beginner's Guide - For You
PPTX
Natural Language Processing (NLP) | Basics
PPTX
It's Machine Learning Basics -- For You!
PPTX
Polymorphism in Python
PDF
DSA Question Bank
PDF
Web API - Overview
PDF
CSS Overview
PDF
HTML Overview
PDF
EM Algorithm
PDF
User story mapping
PDF
User stories
PDF
Problem solving using computers - Unit 1 - Study material
PDF
Problem solving using computers - Chapter 1
PDF
Quality Circle | Case Study on Self Esteem | Team Opus Geeks.pdf
PPTX
Multimedia Content and Content Acquisition
PPTX
PHP Arrays_Introduction
PDF
Leadership
Django Framework Interview Guide - Part 1
Artificial intelligence ( AI ) | Guide
On Page SEO (Search Engine Optimization)
Prompt Engineering | Beginner's Guide - For You
Natural Language Processing (NLP) | Basics
It's Machine Learning Basics -- For You!
Polymorphism in Python
DSA Question Bank
Web API - Overview
CSS Overview
HTML Overview
EM Algorithm
User story mapping
User stories
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Chapter 1
Quality Circle | Case Study on Self Esteem | Team Opus Geeks.pdf
Multimedia Content and Content Acquisition
PHP Arrays_Introduction
Leadership

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Big Data Technologies - Introduction.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
KodekX | Application Modernization Development
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Electronic commerce courselecture one. Pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Big Data Technologies - Introduction.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Unlocking AI with Model Context Protocol (MCP)
KodekX | Application Modernization Development
Understanding_Digital_Forensics_Presentation.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Network Security Unit 5.pdf for BCA BBA.
NewMind AI Weekly Chronicles - August'25 Week I
Per capita expenditure prediction using model stacking based on satellite ima...
Digital-Transformation-Roadmap-for-Companies.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Machine learning based COVID-19 study performance prediction
Advanced methodologies resolving dimensionality complications for autism neur...
Programs and apps: productivity, graphics, security and other tools
Electronic commerce courselecture one. Pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
Building Integrated photovoltaic BIPV_UPV.pdf

System Calls - Introduction

  • 2. Know it! In computing, a system call is a programmatic way in which a computer program requests a service from the kernel of the operating system it is executed on. A system call allows programs to interact with the operating system. A computer program makes a system call when it makes a request to the operating system’s kernel. All programs needing resources must use system calls.
  • 3. Example For example, if we need to write a program code to read data from one file, copy that data into another file. The first information that the program requires is the name of the two files, the input and output files. In an interactive system, this type of program execution requires some system calls by OS. First call is to write a prompting message on the screen Second, to read from the keyboard, the characters which define the two files.
  • 6. Kernel Mode Vs User Mode
  • 8. Some use cases Reading and writing from files demand system calls. If a file system wants to create or delete files, system calls are required. System calls are used for the creation and management of new processes. Network connections need system calls for sending and receiving packets. Access to hardware devices like scanner, and printer, need a system call.
  • 9. wait() In some systems, a process needs to wait for another process to complete its execution. This type of situation occurs when a parent process creates a child process, and the execution of the parent process remains suspended until its child process executes. The suspension of the parent process automatically occurs with a wait() system call. When the child process ends execution, the control moves back to the parent process.
  • 11. fork() Processes use this system call to create processes that are a copy of themselves. With the help of this system Call parent process creates a child process, and the execution of the parent process will be suspended till the child process executes.
  • 13. getid() Getpid() is the function used to get the process ID of the process that calls that function. The PID for the initial process is 1, and then each new process is assigned a new Id. It is a simple approach to getting the PID.
  • 14. Example #include<stdio.h> #include<unistd.h> int main(){ fork(); printf("PID = %dn", getpid()); return 0; } fork() system call is used to create a separate, duplicate process)
  • 17. Example #include<stdio.h> #include<stdlib.h> #include<unistd.h> #include <sys/wait.h> int main(){ int fd[2],n; char buffer[100]; pid_t p; pipe(fd); p = fork(); } if(p>0){ close(fd[0]); printf("Passing value to child!n"); write(fd[1],"Hello my child!!",15); printf("n"); wait(NULL); } else{ close(fd[1]); n = read(fd[0], buffer, 100); write(1,buffer,n); }
  • 19. In steps 1-3, the calling program pushes the parameters onto the stack. The first and third parameters are called by value, but the second one is called by its address as denoted by the & symbol. In step 4, the actual call to the library procedure is made. This instruction is the normal procedure call instruction used to call all procedures. In step 5, the library procedure places the system call number in a place where the operating system expects it, such as a register. In step 6, the library procedure executes a TRAP instruction to switch from user mode to kernel mode and start execution at a fixed address within the kernel. In step 7, the kernel examines the system call number and then dispatches it to the correct system call handler. This correct number is given in the table of system call handlers by pointers referenced at the system call number. In step 8, the system call handler runs. In step 9, the operation is completed, and the user is given back control once the TRAP instruction is set. In step 10, this procedure returns to the user program, like how all normal library procedures do. In step 11, the operating system has to clear the stack, so it increments it enough so that it is empty.
  • 20. Practice #include<stdio.h> #include<unistd.h> int main(){ fork(); fork(); fork(); fork(); printf("PID = %dn", getpid()); return 0; } How many times would the printf statement be executed??
  • 21. Practice #include<stdio.h> #include<unistd.h> int main(){ fork(); fork(); fork(); fork(); printf("PID = %dn", getpid()); return 0; } 16 process | 15 child process | 1 root process