Linux Summary application of four system call functions

Source: Internet
Author: User

(i): creat system Call: System call to create file

Call Method:

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

int creat (const char* path,mode_t mode);

Where path is the file descriptor, mode is the file's permission.

completely equivalent to the modern open () call

FD = open (file,o_wronly| O_creat| O_trunc,mode);

(b): Read system call: If the file is opened with the o_rdonly or O_RDWR flag

# include <sys/types.h>

# include <unistd.h>

int read (int fd,void *buf,size_t nbytes);

Where FD is the file descriptor that you want to read, BUF is a pointer to the memory block, and Nbytes is the number to read

(c); Write system call:

# include <sys/types.h>

# include <unistd.h>

 int write (int fd,void *buf,size_t nbytes);

Note: Write writes not a disk but a memory buffer. Write cannot be written directly to disk.

FD = open (file,o_wronly| O_sync);

O_sync the effect of this flag is to make the system call to a specific file descriptor write ()

and the corresponding actual write disk is synchronized, in fact, until the actual write disk is completed, the write () system call is returned.

Linux Summary application of four system call functions

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