iT邦幫忙

0

[6.1810][lab] Xv6 and Unix utilities (二)

  • 分享至 

  • xImage
  •  

系列文章 : [6.1810] 跟著 MIT 6.1810 學習基礎作業系統觀念

大綱

  • find (moderate)
  • exec (moderate)

find (moderate)

作業要求

  • This exercise explores pathnames and directories.
  • Learn how to use the system calls open, read, and fstat.
  • Write a simple version of the UNIX find program for xv6: find all the files in a directory tree with a specific name. Your solution should be in the file user/find.c.
  • 給予一個名稱,要搜尋該目錄,以及所有子目錄下,有著同樣名稱的檔案

作業提示

  • 可以看 user/ls.c 來學習怎麼讀取一個 directory
  • Don't recurse into "." and "..".

作業內容

exec (moderate)

作業要求

  • 這個作業可以練習 system calls : fork, exec, and wait
  • Add a "-exec cmd" to find, which executes the program "cmd file" for each file f that find finds, instead of printing matching file names.

作業內容

  • 複習一下 fork
    • return value
      • parent 會收到 child process 的 PID
      • child 會收到 0
  • 複習一下 exec
    • (arg) char *path
      • 該執行檔在 filesystem 中的路徑
    • (arg) char **argv
      • 給予新的 program 的 command-line arguments。
    • return value
      • value == -1 : 該 function 失敗
      • value == argc : 該 function 執行成功,會 return argc ( 給予新的 program 的參數的個數 )。
  • 複習一下 wait
    • (arg) addr
      • 第 0 個參數為 address,這個參數代表 child-process 的 exit status 要複製到哪個地方。
      • 若該 address == 0,則不會複製 exit status 給 parent-process。
  • user/find.c
  • 使用 grade-lab-util 進行測試
    • ./grade-lab-util find
== Test find, in current directory == find, in current directory: OK (1.4s) 
== Test find, in sub-directory == find, in sub-directory: OK (0.9s) 
== Test find, recursive == find, recursive: OK (1.3s) 
== Test exec, recursive find == exec, recursive find: OK (1.1s)
  • ./grade-lab-util exec
== Test exec == exec: OK (1.7s) 
== Test exec, multiple args == exec, multiple args: OK (1.0s) 
== Test exec, recursive find == exec, recursive find: OK (1.2s) 

Reference


圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言