gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 03:00:30 25 4
gpt4 key购买 nike

我写了一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com