Linux system programming files and I/O (i) File open shutdown

Source: Internet
Author: User
Tags relative

First, file descriptor

For Linux, all operations on a device or file are performed through a file descriptor. When you open or create a file, the kernel returns a file descriptor (Non-negative integer) to the process. Subsequent operations on the file require only the file descriptor, and the kernel records information about the open file (the file structure body).

When a process starts, 3 files are opened by default, standard input, standard output, standard error, the corresponding file descriptor is 0 (Stdin_fileno), 1 (Stdout_fileno), 2 (Stderr_fileno), and these constants are defined in the Unistd.h header file.

Fileno: Converts a file pointer to a file descriptor

Fdopen: Converts a file descriptor to a file pointer

Second, what is I/O

Input/output is the process of copying data between main memory and external devices

Device-> memory (input operation)

Memory-> device (output operation)

Advanced I/O

The standard I/O libraries provided by ANSI C are called Advanced I/O, and are often referred to as buffered I/O

Low-level I/O

Usually also called I/O without buffering

Third, the opening of the file closed

Open System call 1:

Function prototypes

int open (const char *path, int flags);


Path: The name of the file, which can contain (absolute and relative) paths

Flags: File open mode

return value:

Open success, return file descriptor, open failed, return-1

Open System Call 2:

Function prototypes

int open (const char *path, int flags,mode_t mode);


Path: The name of the file, which can contain (absolute and relative) paths

Flags: File open mode

Related Article

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: 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.