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

c编程理解strace-o t.txt./a.out,c,stdout,stdin,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-ox.t

我写了一个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-ox.txt./a.out查看幕后发生了什么

我看到了:(当然上面/下面还有很多我不明白的地方)

问题:

  • 我得到
    write(1=stdout,“text to print”,字符的#)
    或者这是字节的#

  • 我不懂
    读(3,”,4096)=0

  • 我知道
    0=stdin
    1=stdout
    2=stderr
    ,不知道3是什么意思-也许这就是文件? 我不知道它为什么要进行另一次读取,我假设4096是什么缓冲区大小? 我最好的猜测是,既然它说=0,因为它的EOF

  • 字符数

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


  • 3似乎是用来引用文件的数字?读取(3,x,x)并关闭(3)??
    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)