2012-10-05 22 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字節)。