c编程理解strace -o t.txt ./a.out

标签 c stdout stdin

我写了一个 C 程序。 (页面底部的问题)我可以提供实际代码,但我认为没有必要回答这个问题。

Used a while loop with fgets to get sizeof line
Assigned that fgets to line[255] in the fgets
Assigned the line to a char* (inside the loop)
Printf the char* (also inside the loop)

C 程序按预期输出。

我使用 strace -o x.txt ./a.out 查看幕后发生的事情。

我看到了这个:(当然上面/下面还有很多乱码我不明白)

read(3, "text\nMore text\nEven more text"..., 4096) = 72
write(1, "text\n",5) = 5
... more of the write() = #
read(3, "", 4096) = 0
close(3)

问题:

  1. 我得到了 write(1=stdout, "text to print", #of char) 或者这是字节数?

  2. 我不明白 read(3, "", 4096) = 0

我知道0=stdin1=stdout2=stderr,不知道3是什么意思——也许就是这个文件? 我不知道为什么要进行另一次读取,我假设 4096 是什么缓冲区大小? 我最好的猜测是因为它说 = 0 因为它的 EOF ?

最佳答案

  1. 字符数

  2. 您打开的文件。 4096 是缓冲区大小。上次读取未能读取任何字节(0 字节)。

关于c编程理解strace -o t.txt ./a.out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12750885/

相关文章:

c - 类型转换和指针

python - 如何禁用标准错误流的日志记录?

c++ - 为什么写一个用 stdout 重新打开的文件会更快?

c++ - std::getline 混合输入行结尾时的替代方法

c - 动态获取字符串函数

c - 返回列表中的第一个节点

C编程: how to create a game board with tokens in each cell?

c - strfry(char *__string) 返回 int?

file - go - 将 stderr 重定向到文件和 stdout

php - 从 PHP 写入 C 程序的 STDIN