(Open in Desktop/Laptop/Big Screen for better result.)
Title: Write a program to demonstrate use of file management system calls.
Theory:
➤ List file management systemcalls for windows as well as unix operating system.
1. For Windows:
File management system calls for windows:
CreateProcess()
ReadFile()
WriteFile()
CloseHandle()
2. For Linux:
File management system calls for windows:
Open()
Read()
Write()
Close()
➤ Code / Program:
#include<sys/types.h>
#include<stdio.h>
int main()
{
int n,fd;
char buff[50]; //declaring buffer
//message printing on the display
printf("Enter text to write in the file:\n");
//read from keyboard, specifying 0 as fd for std input devices
//Here, n stores the number of characters
n = read(0, buff, 50);
//creating a new file using open.
fd = open("gpmfile", 0_CREAT | 0_RDWER
//writing input data to file (fd)
write(fd, buff, n);
write to display (1 is standard fd for output device)
write(1, buff, n);
//closing the file
int close(int fd);
return 0;
}
➤ Steps to execute above code:
(We assumed that you have save the file with .c extension and you know the path of this file)
Step 1: Open terminal, Use cd command to move to the directory in which your file is there.
Step 2: Type gcc file_management_program.c and press enter, then type ./a.out to get the output.
Observation / Output:
Conclusion:
➼ Types of system calls.
I) Process Control: These system calls deal with processes such as process creation, process termination etc.
I) Process Control: These system calls deal with processes such as process creation, process termination etc.
II) File Management: These system calls are responsible for file manipulation such as creating a file, reading a file, writing into a file etc.
III) Device Management: These system calls are responsible for device manipulation such as reading from device buffers, writing into device buffers etc.
IV) Information Maintenance: These system calls handle information and its transfer between the operating system and the user program.
V) Communication: These system calls are useful for interprocess communication. They also deal with creating and deleting a communication connection.