2012-10-05 23 views
1

我写了一个C程序。 (页面底部的问题)我可以提供实际的代码,但我不认为有必要回答这个问题。c编程理解strace -o t.txt ./a.out

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?字符

  • 你已经打开的文件的

  • +0

    3似乎是用来引用文件的数字?读(3,x,x)并关闭(3)? – Kairan

    回答

    2
    1. 号码。 4096是缓冲区大小。上次读取未能读取任何字节(0字节)。