Read/write function

Source: Internet
Author: User

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:

    1. Clock time
    2. User CPU Time
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.