linux System Programming Guide - Chapter IV, general purpose IO model

1. Universal IO model is used in which objects?

  Ordinary files, pipes, FIFO, terminals, equipment, socket

2. Why did the process start, all the standard file open character?

  Before the program starts, shell open standard file identifier for the program, in other words, the program inherits the shell open file descriptors.

  If the redirect, shell standard file descriptors will be adjusted, then fork program.

3. What are the standard file descriptors?

  0  STDIN_FILENO  stdin

  1  STDOUT_FILENO  stdout

  2  STDERR_FILENO  stderr

4. Why is it called Universal IO?

  I.e. using a common IO api program may be used a series of files, comprising: a common file, FIFO, pipelines, terminals, socket, device.

  To be able to use a common premise file IO is IO system to achieve the same call set.

  If you need to use a file of special features available ioctl.

5. What needs to pay attention to open?
  open the pathname argument, if it is a symbolic link, will dereference.

  flag in O_CLOEXEC, at execute exec, automatically close file descriptor.

6. What needs to pay attention to read?

  read returns 0, indicating the end of the file.

  Generally, we write

char buf[MAX_READ + 1];
nbytes = read(fd, buf, MAX_READ);
buf[nbytes] = 0;

  Since the read end of the string is not provided, it is necessary to define additional bytes.

If the returned value 7.write, less than the value should be written, how is this going?

  If the operation is a disk file, indicating that the disk is full.

What 8.lseek need to pay attention?

  lseek offset may be negative.

  lseek does not apply to pipelines, FIFO, terminal, Socket (these characteristics are read out, the data is gone)

  l represents the long lseek meaning as offset is long.

9. empty file

  Linux empty file is unique, not on windows (which is why, Thunder download the file, the file is empty, still occupy disk).

  Features file is empty, the file size> occupy disk blocks.

  Only write data, only allocating disk space, empty sections as empty and does not allocate space.

  Disk allocation is based on units of blocks, then if a disk block if only one byte of data is written, will allocate disk blocks.

10.ioctl usefulness?

  Use special features of the file.

Guess you like

Origin www.cnblogs.com/yangxinrui/p/12188429.html