The basic operating system call instruction

First, today mainly to learn the basic operations command system calls, including the following: file create, open, close, read, write, location.
(1), create a file creat (filename, mode_t)
filename is the name of the file you want to create, mode_t mode can be divided into readable, writable, executable and read-write executables and so on.
(2), the file open Open
. 1, Open ( "filename", O_XRWU); open a file readable and writable.
2, open ( "filename", O_XRWU | O_CREAT); create the file, then open, can be a file already exists. Also it can be understood, if the created file already exists, then directly open.
3, open ( "filename", O_XRWU | O_CREAT | O_EXCL) ; create the file, then open. Provided that there is no need to create the file before.
(3) (fd) close
at the end of the program close the file. fd is a file descriptor, you can replace the file.
(4) read read (fd, buf, sizeof ( buf));
the size of the file descriptor in the sizeof (buf) bytes written to buf.
(5) write write (fd, buf, sizeof ( buf));
the size of buf is the sizeof (buf) bytes written to the file descriptor fd.
(6) positioned lseek
. 1, lseek (FD, 0, SEEK_SET); at the beginning of the file moves relative byte
2, lseek (fd, sizeof ( buf) * (-1), SEEK_CUR); byte position relative to the current (- 1) to the left. // left negative right
3, lseek (fd, sizeof (buf) * (-1), SEEK_END); position relative to the end byte.

Guess you like

Origin blog.csdn.net/qq_41915323/article/details/86377834