0% found this document useful (0 votes)
15 views5 pages

Experiment 5 (OSII)

The document outlines an experiment focused on file management using low-level file access system calls, detailing the definitions and syntax of key system calls such as Open, Read, Write, and Close. It includes example C programs demonstrating each system call's functionality. The aim is to enhance understanding of file management through practical implementation.

Uploaded by

devab52664
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

Experiment 5 (OSII)

The document outlines an experiment focused on file management using low-level file access system calls, detailing the definitions and syntax of key system calls such as Open, Read, Write, and Close. It includes example C programs demonstrating each system call's functionality. The aim is to enhance understanding of file management through practical implementation.

Uploaded by

devab52664
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment 5

Title : Study & Implement File Management using Low Level file Access System calls.
Aim: To Learn about File Management using low level file access system calls.

Theory: write theory about low level file access system calls.

 Def of System Call


 System Calls are divided in 5 categories:
1. Process control
2. File management
3. Device management
4. Information maintenance
5. Communication
 File management system calls:
1. Open():
Def
Syntax
Explain syntax in brief.

2. Read():
Def
Syntax
Explain syntax in brief.
3. Write():
Def
Syntax
Explain syntax in brief.
4. Close():
Def
Syntax
Explain syntax in brief.

Conclusion

1) Open():
// C program to illustrate

// open system call

#include <errno.h>

#include <fcntl.h>

#include <stdio.h>

#include <unistd.h>

extern int errno;

int main()

// if file does not have in directory

// then file foo.txt is created.

int fd = open("foo.txt", O_RDONLY | O_CREAT);

printf("fd = %d\n", fd);

if (fd == -1) {

// print which type of error have in a code

printf("Error Number % d\n", errno);

// print program detail "Success or failure"

perror("Program");

return 0;
}

2) Close():

// C program to illustrate close system Call

#include <fcntl.h>

#include <stdio.h>

#include <unistd.h>

int main()

int fd1 = open("foo.txt", O_RDONLY);

if (fd1 < 0) {

perror("c1");

exit(1);

printf("opened the fd = % d\n", fd1);

// Using close system Call

if (close(fd1) < 0) {

perror("c1");

exit(1);

printf("closed the fd.\n");

3) Read():
// C program to illustrate

// read system Call

#include <fcntl.h>

#include <stdio.h>

#include <unistd.h>

int main()

int fd, sz;

char* c = (char*)calloc(100, sizeof(char));

fd = open("foo.txt", O_RDONLY);

if (fd < 0) {

perror("r1");

exit(1);

sz = read(fd, c, 10);

printf("called read(% d, c, 10). returned that"

" %d bytes were read.\n",

fd, sz);

c[sz] = '\0';

printf("Those bytes are as follows: % s\n", c);

return 0;
}

4) Write():

// C program to illustrate

// write system Call

#include<stdio.h>

#include <fcntl.h>

main()

int sz;

int fd = open("foo.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);

if (fd < 0)

perror("r1");

exit(1);

sz = write(fd, "hello geeks\n", strlen("hello geeks\n"));

printf("called write(% d, \"hello geeks\\n\", %d)."

" It returned %d\n", fd, strlen("hello geeks\n"), sz);

close(fd);

You might also like