Today we will learn basic open() command of the linux .Look at the following program
First explore basics of read() and open() through following link.
Create one hello.txt file using vi editor.
sudo vi /hello.txt
write “hello” inside the file .
I believe beginner didn’t get what file descriptor is (Did U !! You probably intelligent then 🙂 )
Those who don’t. File descriptor is non negative number.Every file whenever we open the file one entry will be created inside the kernel for that file. If the file Descriptor value is negative than OS will throw an error.Maximum value of file descriptor can be OPEN_MAX.
REMEMBER: whenever we open or create any file , the kernel returns a file descriptor to process.
REMEMBER: UNIX System shells associates the file descriptor 0 with Standard Input of a process, file descriptor 1 with Standard Output, and file descriptor 2 with Standard Error.
Compile and execute following open.c program.
#define BLOCK_SIZE 4096
I hope you understand the simple open.c program .Best exercise to do with this program is try to dynamically allocate memory to the buffer .If you have any doubt I am here just a comment far away from you