Calling the read function reads data from the open file.
#include <unistd.h>intvoid *buf, size_t nbytes);
Reading data from Filedes to BUF, Nbytes is the number of bytes required to read.
Return value: Returns the number of bytes actually read if successful, returns 0 if the end of the file, or 1 if an error occurs.
When reading from an end device, it is usually read one line at a time.
The ssize_t provides a signed return value, size_t without symbols.
Call the Write function to write data to the open file.
#include <unistd.h>ssize_t write (intconstvoid *buf, size_t nbytes);
When writing data from buf to Filedes, Nbytes is the number of bytes written in the phase.
Return value: The return value is usually the same as the parameter nbytes, otherwise an error is expressed.
The file descriptor filedes is an int, usually associated with the standard input of the process with the file descriptor 0, and the file descriptor 1 associated with the standard output of the process, and the file descriptor 2 is associated with the standard error output of the process. In a POSIX-compliant application, the magic number 0,1,2 should be replaced with symbolic constants Stdin_fileno,stdout_fileno and Stderr_fileno. These constants are defined in the header file <unistd.h>.
Standard input/Output constants stdin and stdout are defined in header file <stdio.h>, respectively, representing standard input and standard output files. is a pointer type , struct _io_file *
When the process terminates, the system closes all open file descriptors for the process, so the program does not have to close the input and output files.
When you measure the execution time of a process, the UNIX system uses three process time values:
- Clock time
- User CPU Time
- System CPU Time
The clock time is the total amount of time the process is running.
User CPU time is the time that is spent executing user instructions.
System CPU time is the time it takes for the process to execute the kernel program. The sum of user CPU time and system CPU time is often referred to as CPU time.
Most file systems use some kind of pre-read (read ahead) technology to improve their performance. When sequential reads are detected, the system attempts to read more data than is required by the application and assumes that the application will soon read the data.
Read/write function