stream file 文件 数据流

  • c - Do stdio file descriptors (stdin, stdout, stderr) get opened, simply from #include'ing <stdio.h>? - Stack Overflow
    • standard streams of a program are opened by the operating system? or, inherit from its parent (, which inherit from its ancestor who opens these standard streams).
    • initialization - execute
      • initialization: loading symbol tables, assigning memory, initializing static data, linking dynamic libraries, open standard streams.
      • execute: main() function
    • fork() - exec():
      • fork(): to create a new process, which is still running under shell code.
      • exec(): to yield control from shell code to user code.
    • (standard) file descriptors 0, 1, and 2 (or more customer ones)
  • file - What does 'stream' mean in C? - Stack Overflow
    • file & stream.
    • 文件-静态,流-(input/流入、output/流出间可)异步动态。
    • pipe / tube / flow. cache / buffer / pool/池。
    • 具象的files, sockets, device (keyboards, USB ports, printers),抽象为接口/interface,logical entity,称为数据/data stream 。
    • 此抽象亦叫做文件句柄——pointer to the stream.
    • cout 是C++中的output stream的对象(封装)形式。
  • Standard streams - Wikipedia
In computer programmingstandard streams are interconnected input and output communication channels[1] between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin), standard output (stdout) and standard error (stderr). Originally I/O happened via a physically connected system console (input via keyboard, output via monitor), but standard streams abstract this. When a command is executed via an interactive shell, the streams are typically connected to the text terminal on which the shell is running, but can be changed with redirection or a pipeline. More generally, a child process inherits the standard streams of its parent process.
A console process (not all process) uses (standard) handles.
    • process associate with console.
    • console有input buffer, output (screen) buffer (console output)。可以通过 CreateFile +CONIN$ /CONOUT$获取。
    • console proccess有STDIN, STDOUT等。默认继承自父。可以通过 SetStdHandle 改变。
    • GetStdHandle ,  CreateFile ,  CreateConsoleScreenBuffer

The standard handles associated with a process.

During console creation, the system creates these handles.

The parent's standard handles are inherited by any child process

The value of the handles returned by GetStdHandle are not 0, 1, and 2, so the standard predefined stream constants in Stdio.h ( STDIN ,  STDOUT , and  STDERR ) cannot be used in functions that require a console handle.

    • std handle initial associate to console buffer.
    • SetStdHandle redirect/重定向
    • CreateFile +CONIN$ /CONOUT$ (CON: Console, Create: Retrieve the exist)
    • CreateConsoleScreenBuffer  - SetConsoleActiveScreenBuffer

GetFileTypecan assist in determining what device type the handle refers to

standard device (standard input, standard output, or standard error).

    • an application (such as running on an interactive desktop) may not have associated standard handles.
    • ReadConsoleInput ,  WriteConsole ,  GetConsoleScreenBufferInfo ;  CreateFile + CONIN$ /CONOUT$ 。
    • GUI(graphical user interface)可使用 AttachConsole ,  AllocConsole ,  FreeConsole 建立console交互。
    • 使用 GetFileType 检查继承到的标准输入输出/STDIO。
  • LuaFileSystem
    •  lfs.lock  lfs.unlock 
  • 随想:
    • 一个字符串也算一个对象、数据流。
    • 元数据/属性为(主)数据基于描述系统(如文件系统)的,相对于主数据的附属数据。

A console process uses handles

原文地址:https://www.cnblogs.com/RobertL/p/14182347.html