read system call using c program | os cs8461 | 4th sem of cse | operating system lab | QT

Опубликовано: 02 Ноябрь 2024
на канале: Quick Through
155
3

operating system laboratory for cse engineering playlist
   • Operating System  

Exp# 2g read system call
Date:
Aim

To read the given file and to display file contents.
read()
Reads no. of bytes from the file or from the terminal.
If read is successful, it returns no. of bytes read.
The file offset is incremented by no. of bytes read.
If end-of-file is encountered, it returns 0.
Algorithm
1. Declare a character buffer buf to store 100 bytes.
2. Get existing filename as command line argument.
3. Open the file for reading using open system call with O_RDONLY option.
4. Check the file descriptor.
a) If file does not exist, then stop.
5. Read until end-of-file using read system call.
a) Read 100 bytes (max.) from file and print it
6. Close the file using close system call.
7. Stop
Program