What is System Call ?
The topic is system call... In the last video
we discussed how we work in user mode & kernel mode.
If the user is using any application
or API or writing any program then we generally writes it in user mode.
But if I wants to access any functionality of
operating system then I have to go in kernel mode
So because our access is on the user mode
because we are accessing the user so to go in kernel mode we use system call.
About System Call .
System call is a programmatic way through which we shifts from user mode to kernel mode or can access the functionalities
of kernel and operating system.
Like if I'd take a simple example
if we are writing a C program and I want to get any value printed on monitor let's say 2 + 2 = 4 then 2 + 2 is up to user mode,
processor will do 2 + 2 no problem.
But we have to get it printed on the monitor
or if I want to get something printed or I want to access printer, so wherever I have to
access devices, I've to take help and do it through kernel.
What is Kernel ?
Kernel means through operating system
`Same way if I want to access some file
Let's say I want to perform a transaction
want to change data in some file
File is in hard disk.. so again, to access any file
or hard disk, I've to go in kernal mode
Because these all devices and resources
are being governed by operating system so in operating system kernal is the main logical unit
So here I've to take help of system call
and system call is generally...
Many times many operating systems
are like if we talk about Linux, then when we write C program in the text editor
then we can use system call there directly Like we can use read, write, close, open, fork etc
and many other system calls directly
And generally in Linux operating system or
if we'll talk about any other system also There're hundreds of system call... same way if we'd talk about window's
then there're around 700 system calls
But there are many operating systems
where we don't write system calls directly We rather use APIs or
we uses the local libraries like printf or scanf...
Printf means that we want to get some value printed, then we're writing Printf. But that printf
or scanf is not system call
Printf is a function, but that
function is accessing the system call, so print means writing on the monitor so whether you use system call directly or you use some API or any function but at the end work will be done through system call because system call will invoke kernal to perform this work so as I said system call generally
varies according to operating system.
Many of them have around 300 system calls
Window 7 have around 700 system calls so we categories these system calls
First we have file related system call First we have file related system call means
where we want to access any file
Let me tell you with a simple example
What happens generally is...
when we write any C program then we are writing that program
using some API or application
But when we execute that program then we says in operating system
that the program has become process now means when it's in running mode
then it became process And running mode means
that process will in the RAM
Means that process has arrived in the RAM now
and our operating system also i.e. kernal is in RAM also I'm just taking a general architecture... many times just a part of code lies in the RAM rather than whole code or kernal so we are talking through a simple example where it says that our kernal is in main memory and process also
Now if we want to do any execution in the process Let's say I want to access some file,
then this process don't have privilege that privilege will be given by kernal
So process will invoke system call and will access that file
So all this work here has been done through system call
So if we'd talk about file, then what we do in file?
Let's say I've to create some file...
Create a file
let's say I want to open a file,
want to read a file or write some file so all the file related work that we are doing here we are doing all that through file related system calls
Next is device related system call,
so device related system call means
if I want to access any device or hardware
here we are calling device as hardware
If we want to access hardware whether
it is hard disk, printer or monitor...
so to access all these devices... User can never
do direct access, he has to take privilege
Privilege will be given by operating system
so here we'll again take privilege through system call
Whether we are reading any device or writing
on a device or repositioning value of that device or we are accessing its attributes
Same way we use IOctrl... we use this
to control input output devices or to control a file also... although, file control
is a header file but we generally use it here
Next we have...
Information related
Information means regarding processes or devices,
if I want to take information of any attribute there we use information related system call
like getpid is a simple example.
We use getpid if I want to know about some process's ID, getppid means if I want to know about parent ID .
Wherever we need any process related information
which we call metadata in general term Means metadata related to a data is... data is like there's a audio file...
and the content in audio file is its data
But data related to it.. like its size, file name,
file's permission, file's extension...
All this is called attribute.
So if I want to access a data like this
for this we use information related system call
Same way if I want access system's time,
system's date, system's data... then in that case we use information related
Then process control... this is also
a major system call that we use where if you are getting a process loaded.
As I just told you, generally the programs
that we write or save, we are doing that in secondary memory in hard disk because we want to save it permanently.
But when we have to load them
in main memory or want execute them for that we use process control system call if you want to abort a process...
What is Fork System Call ?
Fork system call... this is a very important system call fork system call means like we talk about
multi processing environment in operating system
Means we want to do multiple processes
and tasks at a time for that we use multi threading environment
means we run multiple threads related to the process or we can use fork system call... In fork system call, a process creates its own child process
And that child process is doing its work
parent process is also doing its work this way we can create
a multiprocessing environment here so we create fork system call also through
process control system call wait & signal... we use it
under process synchronization if you want some process to wait or
want to increase semaphore values,
or want to allocate memory, so we can
access all these things through this system call Then communication... In communication
we generally use inter process communication
Inter process communication means...
two processes are communicating with each other they can either use this Pipe() method or shared memory so here we have pipe(0 system call,
Shm get() that we use to get value of shared memory or if I want to create or terminate connections,
we have system calls related to it here.
So these are major categorizations of system call we have system calls other than these also Like system calls related to protection and security where we use chmod, privileges... if I want to change on any file then we can use ch mod, u mask and
many other privileges and system calls that we use so you con't have to directly
memorize these system calls but at least you should be clear with
their idea that why we use system call and what is there importance in operating system
So this is all about the system calls
Thank You!
0 Comments