operating system laboratory for cse engineering playlist
• Operating System
Exp# 2h write system call
Date:
Aim
To append content to an existing file.
write()
Writes no. of bytes onto the file.
After a successful write, file's offset is incremented by the no. of bytes written.
If any error due to insufficient storage space, write fails.
close()
Closes a opened file.
When process terminates, files associated with the process are automatically closed.
Algorithm
1. Declare a character buffer buf to store 100 bytes.
2. Get exisiting filename as command line argument.
3. Create a file with the given name using open system call with O_APPEND option.
4. Check the file descriptor.
a) If value is negative, then stop.
5. Get input from the console until user types Ctrl+D
a) Read 100 bytes (max.) from console and store onto buf using read system call
b) Write length of buf onto file using write system call.
6. Close the file using close system call.
7. Stop