Files
In Linux everything is a file. But, what is a file?
A file anything a process can read or write.
In C, files is are represent by either:
- a file descriptor (type
int) - a stream (type
FILE *)
Operations like read`` and write` are called IO operations (IO for input/output).
To perform IO operations, a process has to first obtain a file descriptor pointing to the file.
Open files are exposed to a process as file descriptors. These are numerical
identifiers (of type int).
Read and write operations are perfomed with rispect to the file position.
The file position can be modified via calls to lseek. If a file was opened twice,
the two file positions are independent and lseek will only modify the target file.
More generic IO operations are done via calls to ioctl.
Once the process has finished with the file, it should close the file.