--- tags: Linux Kernal --- # 2023q1 週記 contributed by < [POCHUN-CHEN](https://github.com/POCHUN-CHEN?tab=repositories) > :::info 本週記,希望給未來,跟我一樣程度比較落後的同學,能有一個相同心境與陪伴感。 請一起努力,跟自己比較就好! ::: ## week 1 (02/12-02/18) ### Link list #### 小技巧: 若和 ```list_head``` 一樣使用單純的指標( ```hlist_node *``` ),則考慮到 list 有方向性,delete node 時需要額外檢查其是否為 list 的 head 或是 NULL 等等,有較冗餘的程式碼必須實做,因此使用 ```hlist_node **pprev``` 直接存取上一個 node 所在的位址。Linux 為求程式碼簡潔故以 pointer to pointer 的方式用 ```pprev``` 直接指向前一個元素的記憶體位址本身。 ```C++ struct list_head { struct list_head *next, *prev; }; struct hlist_head { struct hlist_node *first; }; struct hlist_node { struct hlist_node *next, **pprev; }; ``` ### 安裝說明 1. 安裝必要的開發工具套件 ``` $ sudo apt install make $ sudo apt install build-essential git-core valgrind $ sudo apt install cppcheck clang-format aspell colordiff ``` * 安裝 Vim ``` $ sudo apt-get install vim ``` 2. Git初次設定 [Git 教學和 GitHub 設定指引](https://hackmd.io/@sysprog/gnu-linux-dev/https%3A%2F%2Fhackmd.io%2F%40sysprog%2Fgit-with-github) :::danger * [6.到 Github 網站加入你的 SSH key](https://hackmd.io/@sysprog/gnu-linux-dev/https%3A%2F%2Fhackmd.io%2F%40sysprog%2Fgit-with-github) 將 SSH key 複製到你的剪貼簿,如果你的 key 檔案名稱不為 id_rsa.pub,請自行將以下程式碼中 id_rsa.pub 修改成你的檔案名稱。 ``` $ clip < ~/.ssh/id_rsa.pub #Copies the contents of the id_rsa.pub file to you clipboard ``` Command 'clip' not found, but can be installed with: sudo apt install geomview 解法: 將 SSH key 印在終端機上: ``` $ cat ~/.ssh/id_rsa.pub ``` * 同步 ```$ git remote add origin git@github.com:你的帳號名稱/你的專案名稱.git``` Command 'git' not found, but can be installed with: sudo apt install git ```sudo apt install git``` ::: 第六步後,先設定以下: ``` $ git config --global user.name "John Doe" $ git config --global user.email "johndoe@example.com" ``` 在輸入步驟7,即可完成。 ### 心得: 1. 一開始以為 ```make "CodeName"``` 語法是terminal預設“編譯”的語法,但是後來發現是makefile的編譯語法。自己腦補程式碼,這件事需要修正。 ### 貢獻: 1. 共筆修正 https://hackmd.io/@sysprog/B1RwlM85Z?type=view#矩陣 ![](https://i.imgur.com/O4LMd04.png) ## week 2 (02/19-02/25) ### lab0c進度推進 Linux基礎語法: * makefile語法:編譯程式 ``` $ make test ``` * 打開程式 ``` $ ./qtest ``` * 看程式碼比例 ``` $ cloc . ``` ### 更新GitHub步驟 #### 程式碼自動排版 ``` $ clang-format -i queue.c ``` #### 檢查有哪些變動的程式(非必要) ``` $ git status ``` #### 指定變更的檔案 ``` $ git add 全檔名 ``` #### 提交修改 ``` $ git commit ``` ### Push 前製驗證 1. 到GitHub上面的Setting內Personal access token,產生Token(期限最長一年) 2. 拿到Token後,複製 3. 修改路徑檔案 .git/config ```$ vim .git/config``` 也可以用 ``` $ git remote set-url origin https://"token"@github.com/"user name"/"repo".git ``` ### 分段測試: ``` $ ./qtest ``` ``` $ cd traces/ ``` ``` $ cat trace-07-string.cmd ``` ``` $ cd .. ``` ``` $ option simulation 1 ``` ### 延伸: 1. max_Depth不夠 2. GGGG for each HHHH list 操作。接合 ## week 3 (02/26-03/04) :::info 為了解決我能力不足且還沒進入狀況的窘境,我也打算通過這門課,所以期末的50%自評,我目前打算採取每週投入時間來給自己評分,跟自己比就好。由於HackMD可以公開且有版本紀錄,我就把每週的投入跟比較亂的筆記放在週記。 也希望這份心境紀錄,能幫助到未來程度跟我一樣比較落後的同學。希望你們都能撐下去且好好學習喔。 ::: 策略: 第一週的lab0-c,還沒完成。且前幾週進度已經落後,按照我過去的經驗,這種會持續惡化的狀況,應該先遏止新進度永遠追不完,應從第二三週趕快追進度,再分配投入固定時間給第一週的進度,以免影響未來持續欠進度。 --- 進度條: - [ ] 2023q1 Homework1 (quiz1)第二題 - [ ] 2023q1 Homework2 (quiz2)第一題 - [ ] 待補 --- 3/1: 7h 3/2: 4h ### 分段測試: 列出專案內的子程式(要在專案內) ``` $ ls ``` ``` $ ./qtest ``` ``` cmd> new l = [] cmd> it RAND 10 l = [mcudbf eknyh wioyuqbud hmzpe aubwxltvh mlnnszh ednwjq iwdan btaqak doymlsox] cmd> sort l = [aubwxltvh btaqak doymlsox ednwjq eknyh hmzpe iwdan mcudbf mlnnszh wioyuqbud] cmd> swap ``` 列出cmd內的功能 ``` cmd> help ``` :::warning 記得在用cmd做測試時,更改後要記得重新"編譯"。 ``` $ make ``` ::: ## week 4 改錯字 https://hackmd.io/x4IRgvnYSyCBOnrV7oH_iw?both ## week 5 * 確認專案是誰的 ``` $ vim .git/config ``` [[Linux 指令] cd 指令-切換目錄操作教學](https://www.tokfun.net/os/linux/linux-cd-command/) :::spoiler 常用cd指令 * 切換至上一層目錄 ``` $ cd.. ``` * 將目錄切換至家目錄 ``` $ cd~ ``` ::: 查看程式碼行數: ``` $ cloc . ```