Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/691b01b4-1b64-800b-992e-192d846b72fe
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====== 1. 数据流与重定向 ====== * '''文件描述符(File Descriptor)''':进程用文件描述符表示数据流,它是一个数字,代表一条数据流 。 * '''描述符表(Descriptor Table)''':进程内部用来记录文件描述符及其对应数据流的表格 。 * '''标准数据流''':描述符表的前三项是固定的 : * '''0''':标准输入(stdin),默认连接键盘 。 * '''1''':标准输出(stdout),默认连接屏幕 。 * '''2''':标准错误(stderr),默认连接屏幕 。 * '''重定向(Redirection)''':重定向通过修改描述符表中固定编号(如1号标准输出)所对应的数据流来实现 。 * '''重定向相关的函数''': * **fileno(FILE *stream)**:返回文件指针 FILE* 对应的文件描述符编号 。 * '''dup2(oldfd, newfd)''':复制数据流,让 newfd 指向与 oldfd 相同的数据流。这是在代码中实现重定向的关键函数,例如 dup2(fileno(f), 1) 可以将标准输出重定向到文件 f 。
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)