L-1.7: System Calls in Operating system and its types in Hindi

Gate Smashers
19 Dec 201810:07

Summary

TLDRThis video script explains the concept of system calls, which are essential for transitioning from user mode to kernel mode in operating systems. It covers the necessity of system calls for accessing hardware devices and files, and categorizes them into file-related, device-related, information-related, process control, and inter-process communication system calls. The script also touches on system calls for security and protection, emphasizing their importance in operating systems.

Takeaways

  • 🔒 **User Mode vs Kernel Mode**: Applications run in user mode, but to access OS functionalities, they must switch to kernel mode.
  • 📲 **Purpose of System Calls**: System calls are the programmatic method to transition from user mode to kernel mode.
  • 💻 **System Calls in Programming**: In languages like C, system calls (e.g., read, write, open) are used to interact with the kernel for tasks like file handling or device access.
  • 🌐 **Variety in System Calls**: Different operating systems have different sets of system calls; for instance, Windows has around 700 system calls.
  • 📁 **File-Related System Calls**: These are used for creating, opening, reading, and writing files, requiring kernel privileges.
  • 🖥️ **Device-Related System Calls**: Necessary for accessing hardware devices like hard disks, printers, or monitors.
  • 📊 **Information-Related System Calls**: Used to retrieve metadata about processes, devices, and system information like time and date.
  • 🔄 **Process Control System Calls**: Facilitate process loading, execution, and control, including the creation of child processes with fork.
  • 🔗 **Inter-Process Communication (IPC)**: System calls like Pipe() and Shmget() enable communication between processes.
  • 🛡️ **Security and Protection**: System calls such as chmod and umask are used to manage file and system security.

Q & A

  • What is the primary purpose of a system call?

    -The primary purpose of a system call is to allow a program running in user mode to request services from the operating system's kernel, thus transitioning from user mode to kernel mode.

  • Why can't user mode applications directly access hardware or system resources?

    -User mode applications cannot directly access hardware or system resources because they do not have the necessary privileges to do so. Direct access must be mediated by the operating system's kernel through system calls to ensure security and proper resource management.

  • What is the difference between user mode and kernel mode?

    -User mode is a restricted environment where applications run, while kernel mode is a privileged mode that gives the operating system direct access to hardware and system resources. System calls are used to transition from user mode to kernel mode to perform operations that require higher privileges.

  • Can you provide an example of a system call in a C program?

    -Yes, in a C program, system calls such as 'read', 'write', 'open', 'close', and 'fork' are used to perform operations like reading from or writing to a file, opening or closing a file descriptor, or creating a child process.

  • How does the concept of system calls vary across different operating systems?

    -The concept of system calls remains the same across different operating systems, but the specific system calls available and their implementation can vary. For example, Linux has a different set of system calls compared to Windows, which has around 700 system calls.

  • What is the role of APIs in the context of system calls?

    -APIs (Application Programming Interfaces) provide a higher-level abstraction for developers, allowing them to perform operations without directly using system calls. APIs often internally call system calls to execute the required tasks.

  • What are file-related system calls and why are they necessary?

    -File-related system calls are used to perform operations on files, such as creating, opening, reading, and writing files. They are necessary because they allow user mode applications to interact with files on the disk through the kernel, which manages file access and permissions.

  • How do device-related system calls enable access to hardware?

    -Device-related system calls enable access to hardware by allowing user mode applications to request the kernel to perform operations on devices like hard disks, printers, or monitors. This is done to ensure that hardware access is controlled and secure.

  • What is the significance of the 'fork' system call in creating a multiprocessing environment?

    -The 'fork' system call is significant because it allows a process to create a child process, effectively duplicating itself. This is the foundation for multiprocessing, where multiple processes can run concurrently and perform different tasks.

  • What are inter-process communication (IPC) system calls and why are they used?

    -Inter-process communication system calls are used to allow two or more processes to communicate with each other. They are used for data exchange and synchronization between processes, and can involve mechanisms like pipes, shared memory, or message queues.

  • Can you explain the role of 'getpid' and 'getppid' system calls?

    -Yes, 'getpid' is used to obtain the process ID of the current process, while 'getppid' retrieves the process ID of the parent process. These system calls provide information related to process identification, which can be useful for process management and tracking.

Outlines

00:00

💻 Understanding System Calls

The paragraph introduces the concept of system calls, explaining the necessity of transitioning from user mode to kernel mode to access operating system functionalities. It uses the example of a C program to illustrate how arithmetic operations are performed in user mode, but displaying the result on a monitor or accessing hardware requires kernel mode. The paragraph further explains that system calls are the programmatic way to make this transition and access kernel functionalities. It mentions direct use of system calls in Linux for operations like read, write, close, open, and fork, contrasting it with the use of APIs or library functions like printf in other systems, which indirectly invoke system calls. The paragraph also categorizes system calls into file-related, device-related, and information-related, providing examples of each.

05:07

📂 System Call Categories and Their Uses

This paragraph delves deeper into the different types of system calls and their specific uses. It discusses file-related system calls, which are essential for creating, opening, reading, and writing files, emphasizing that these operations require kernel privileges granted through system calls. The paragraph then moves on to device-related system calls, explaining that accessing hardware like hard disks, printers, or monitors necessitates system calls to obtain operating system privileges. It introduces the concept of metadata and information-related system calls, which are used to retrieve details about processes and system attributes. The discussion continues with process control system calls, which are crucial for loading and executing programs, creating child processes with fork, and managing process synchronization with wait and signal system calls. The paragraph concludes with communication system calls, focusing on inter-process communication mechanisms like Pipes and shared memory, and system calls related to security and protection, such as chmod and umask.

Mindmap

Keywords

💡System Call

A system call is a programmatic method by which a user-space application makes a request to the kernel. It is a fundamental concept in operating systems, allowing applications to request services from the kernel. In the video, the presenter explains that to access hardware or system resources, one must use system calls to transition from user mode to kernel mode. For example, when a C program needs to print something on the monitor, it uses system calls like 'write' to communicate with the kernel.

💡User Mode

User mode is a level of privilege in an operating system where applications run and the CPU operates with limited access to system resources and hardware. The video script mentions that most of the work, like writing a program or using an API, is done in user mode. It contrasts with kernel mode, where more sensitive operations are performed.

💡Kernel Mode

Kernel mode is a privileged mode of operation in an operating system where the CPU can perform all instructions and access all memory. The script explains that to access the functionalities of the operating system, one must switch to kernel mode from user mode, typically through a system call.

💡API

An API (Application Programming Interface) is a set of routines, protocols, and tools for building software applications. The presenter uses the term 'API' to describe how developers often write code using higher-level functions like 'printf' instead of direct system calls. These APIs abstract the complexity of system calls and provide a more user-friendly interface for developers.

💡File System Calls

File system calls are a type of system call that deal with file operations such as creating, opening, reading, and writing files. The video script gives an example of how these system calls are used when a program needs to access a file on the hard disk, which is managed by the operating system's kernel.

💡Device System Calls

Device system calls are used to access or interact with hardware devices such as printers or monitors. The script explains that users cannot directly access devices; they must request access through system calls, which are granted privileges by the operating system to perform operations like reading from or writing to a device.

💡Information Related System Calls

These system calls are used to retrieve metadata about processes or devices. The video provides 'getpid' as an example, which is used to obtain the process ID, illustrating how these system calls help in managing and identifying processes within the operating system.

💡Process Control System Calls

Process control system calls are used to manage processes, such as loading, creating, or aborting them. The script mentions 'fork' as a key system call in this category, which allows a process to create a child process, enabling multitasking and parallel processing within the operating system.

💡Inter-Process Communication (IPC)

IPC system calls facilitate communication between different processes. The video discusses methods like Pipes and shared memory, which are implemented through system calls such as 'pipe()' and 'shmget()', allowing processes to exchange data or signals.

💡Protection and Security System Calls

These system calls are related to setting permissions and access controls on files and resources. The script mentions 'chmod' and 'umask' as examples, which are used to change file permissions, demonstrating how system calls play a role in maintaining the security and integrity of the operating system.

💡System Calls Categorization

The video script categorizes system calls into different types based on their functionality, such as file-related, device-related, information-related, process control, communication, and protection/security. This categorization helps in understanding the broad range of tasks that system calls can perform within an operating system.

Highlights

System calls are a programmatic way to transition from user mode to kernel mode.

User mode is used for general application and API usage, while kernel mode is for accessing operating system functionalities.

System calls enable access to kernel functionalities such as device access and file manipulation.

In a C program, arithmetic operations are performed in user mode, but outputting to a monitor requires a system call.

System calls are necessary for accessing hardware like printers and monitors through the operating system.

File operations such as creating, opening, reading, and writing files are done through file-related system calls.

Device-related system calls are used for accessing hardware devices which are governed by the operating system.

Information-related system calls provide metadata about processes, devices, and system attributes like size, name, and permissions.

Process control system calls are used for loading programs into main memory and executing them.

The fork system call is crucial for creating child processes in a multiprocessing environment.

Process synchronization can be achieved through system calls like wait and signal.

Inter-process communication involves system calls such as Pipe() and Shmget() for Pipes and shared memory.

System calls also include those related to protection and security, like chmod for changing file permissions.

Linux provides direct access to system calls such as read, write, close, open, and fork.

Windows has around 700 system calls, indicating a large number of functionalities accessible through system calls.

Many operating systems offer APIs or libraries that indirectly access system calls, such as printf for printing.

System calls are categorized into file-related, device-related, information-related, process control, communication, and security.

Understanding the concept and importance of system calls is crucial for operating system functionality.

Transcripts

play00:00

Hello friends, Welcome to Gate Smashers

play00:02

The topic is system call... In the last video we discussed how we work in user mode & kernel mode

play00:09

If the user is using any application or API or writing any program

play00:16

then we generally writes it in user mode

play00:19

But if I wants to access any functionality of operating system then I have to go in kernel mode

play00:27

So because our access is on the user mode because we are accessing the user

play00:32

so to go in kernel mode we use system call

play00:36

System call is a programmatic way through which we shifts from user mode to kernel mode

play00:45

or can access the functionalities of kernel and operating system

play00:51

Like if I'd take a simple example if we are writing a C program

play00:55

and I want to get any value printed on monitor let's say 2 + 2 = 4

play01:02

then 2 + 2 is up to user mode, processor will do 2 + 2 no problem

play01:06

But we have to get it printed on the monitor or if I want to get something printed

play01:12

or I want to access printer, so wherever I have to access devices, I've to take help and do it through kernel

play01:22

Kernel means through operating system `Same way if I want to access some file

play01:27

Let's say I want o perform a transaction want to change data in some file

play01:31

File is in hard disk.. so again, to access any file or hard disk, I've to go in kernal mode

play01:38

Because these all devices and resources are being governed by operating system

play01:45

so in operating system kernal is the main logical unit

play01:53

So here I've to take help of system call and system call is generally...

play01:59

Many times many operating systems are like if we talk about Linux,

play02:03

then when we write C program in the text editor then we can use system call there directly

play02:11

Like we can use read, write, close, open, fork etc and many other system calls directly

play02:17

And generally in Linux operating system or if we'll talk about any other system also

play02:22

There're hundreds of system call...

play02:24

same way if we'd talk about window's then there're around 700 system calls

play02:28

But there are many operating systems where we don't write system calls directly

play02:33

We rather use APIs or we uses the local libraries like printf

play02:40

Or scanner... printf means that we want to get some value printed,

play02:44

then we're writing Printf. But that printf or scanner is not system call

play02:52

Printf is a function, but that function is accessing the system call,

play02:58

so print means writing on the monitor so whether you use system call directly

play03:06

or you use some API or any function but at the end work will be done through system call

play03:13

because system call will invoke kernal to perform this work

play03:19

so as I said system call generally varies according to operating system

play03:24

Many of them have around 300 system calls Window 7 have around 700 system calls

play03:29

so we categories these system calls First we have file related system call

play03:37

First we have file related system call means where we want to access any file

play03:42

Let me tell you with a simple example

play03:46

What happens generally is... when we write any C program

play03:50

then we are writing that program using some API or application

play03:57

But when we execute that program

play04:00

then we says in operating system that the program has become process now

play04:04

means when it's in running mode then it became process

play04:08

And running mode means that process will in the RAM

play04:13

Means that process has arrived in the RAM now and our operating system also i.e. kernal is in RAM also

play04:23

I'm just taking a general architecture...

play04:25

many times just a part of code lies in the RAM rather than whole code or kernal

play04:31

so we are talking through a simple example where it says that our kernal is in main memory and process also

play04:39

Now if we want to do any execution in the process

play04:42

Let's say I want to access some file, then this process don't have privilege

play04:48

that privilege will be given by kernal So process will invoke system call and will access that file

play04:59

So all this work here has been done through system call So if we'd talk about file, then what we do in file?

play05:07

Let's say I've to create some file... Create a file

play05:10

let's say I want to open a file, want to read a file or write some file

play05:15

so all the file related work that we are doing here

play05:21

we are doing all that through file related system calls

play05:26

Next is device related system call, so device related system call means

play05:31

if I want to access any device or hardware here we are calling device as hardware

play05:37

If we want to access hardware whether it is hard disk, printer or monitor...

play05:43

so to access all these devices... User can never do direct access, he has to take privilege

play05:51

Privilege will be given by operating system so here we'll again take privilege through system call

play05:56

Whether we are reading any device or writing on a device or repositioning value of that device

play06:03

or we are accessing its attributes

play06:05

Same way we use IOctrl... we use this to control input output devices

play06:13

or to control a file also... although, file control is a header file but we generally use it here

play06:21

Next we have... Information related

play06:24

Information means regarding processes or devices, if I want to take information of any attribute

play06:33

there we use information related system call like getpid is a simple example

play06:40

We use getpid if I want to know about some process's ID, getppid means if I want to know about parent ID

play06:48

Wherever we need any process related information which we call metadata in general term

play06:54

Means metadata related to a data is...

play06:57

data is like there's a audio file... and the content in audio file is its data

play07:06

But data related to it.. like its size, file name, file's permission, file's extension... All this is called attribute

play07:14

So if I want to access a data like this for this we use information related system call

play07:20

Same way if I want access system's time, system's date, system's data...

play07:28

then in that case we use information related

play07:31

Then process control... this is also a major system call that we use

play07:36

where if you are getting a process loaded

play07:41

As I just told you, generally the programs that we write or save,

play07:45

we are doing that in secondary memory in hard disk because we want to save it permanently

play07:50

But when we have to load them in main memory or want execute them

play07:56

for that we use process control system call

play08:00

if you want to abort a process...

play08:02

Fork system call... this is a very important system call

play08:06

fork system call means like we talk about multi processing environment in operating system

play08:13

Means we want to do multiple processes and tasks at a time

play08:19

for that we use multi threading environment means we run multiple threads related to the process

play08:25

or we can use fork system call... In fork system call, a process creates its own child process

play08:33

And that child process is doing its work parent process is also doing its work

play08:36

this way we can create a multiprocessing environment here

play08:40

so we create fork system call also through process control system call

play08:46

wait & signal... we use it under process synchronization

play08:50

if you want some process to wait or want to increase semaphore values,

play08:55

or want to allocate memory, so we can access all these things through this system call

play09:00

Then communication... In communication we generally use inter process communication

play09:06

Inter process communication means... two processes are communicating with each other

play09:11

they can either use this Pipe() method or shared memory

play09:16

so here we have pipe(0 system call, Shmget() that we use to get value of shared memory

play09:23

or if I want to create or terminate connections, we have system calls related to it here

play09:29

So these are major categorizations of system call we have system calls other than these also

play09:34

Like system calls related to protection and security where we use chmod, privileges...

play09:40

if I want to change on any file

play09:42

then we can use chmod, umask and many other privileges and system calls that we use

play09:49

so you con't have to directly memorize these system calls

play09:53

but at least you should be clear with their idea that why we use system call

play09:58

and what is there importance in operating system

play10:02

So this is all about the system calls

play10:05

Thank You!

Rate This

5.0 / 5 (0 votes)

関連タグ
System CallsKernel ModeUser ModeOperating SystemsLinuxWindowsC ProgrammingFile AccessDevice AccessProcess Control
英語で要約が必要ですか?