顯示具有 linux 標籤的文章。 顯示所有文章
顯示具有 linux 標籤的文章。 顯示所有文章

2018年1月5日 星期五

[Book list] Computer Science

Computer Science 領域各聖經與希望念完的書目:

2017年12月9日 星期六

[Bash] tips


  • quick key
    • ctrl + R: reverse 的快速搜尋之前下過的指令
  • history
    • 可以列出最近下過的指令, 並用
      !number
      執行第 number 的指令

2017年11月29日 星期三

2017年11月25日 星期六

[Kernel] Linux kernel debug


  • 技巧
    • printk dump messages to console
      • 簡單好用, 行為類似 printf, 不過這會改變 kernel行為 (例如: 執行速度變慢, 使得 race condition 行為不一致)
      • 可同時更改 ring buffer size (更改 kernel boot parameter: log_buf_len), 避免 log的訊息被裁斷
      • 更改 log level, 預設為 KERN_WARNING, e.g. 開啟所有 log:
      • , 並刪除 boot parametersquiet, splash (runtime 查看 boot parameters: cat /proc/cmdline)
        echo 7 > /proc/sys/kernel/printk
    • gdb
      • disassemble function codes
        • gdb vmlinux
          (gdb) dissemble functionName
      • locate core dump:
        • gdb crashed_function_obj, e.g. gdb sd.o
        • (gdb) list *(backtrace_func_shown+offset), e.g. list *(sd_remove+0x20
    • 用 objdump
      • objdump -SdCg sample.o
    • ToDo: add2line 指令介紹, ELF 格式介紹, study Kernel Debugging
    • Reference

2017年8月2日 星期三

[Notes] Linux Devices Drivers 3Ed.


  • Books: Linux Device Drivers
  • Ch1. Introduction
    • 說明驅動程式的角色
    • 設計原則: 提供機制 (mechanism)-要提供什麼能力, 而非法則 (policy)-如何使用這些能力
    • Kernel 概論
      • Module
      • Device分類: character device, block device, network interface
  • Ch2. Module
    • Kernel preparation
    • 展示 Hello World Module
      • build - 
        • include kernel headers (/usr/src/linux-headers)
        • make file - obj-m
      • sample module file
      • #include 
        #include 
        
        MODULE_DESCRIPTION("Hello_world");
        MODULE_LICENSE("GPL");
        
        static int hello_init(void)
        {
         printk(KERN_INFO "Hello world !\n");
         return 0;
        }
        
        static void hello_exit(void)
        {
         printk(KERN_INFO "Bye !\n");
        }
        
        module_init(hello_init);
        module_exit(hello_exit);
        
      • sample Makefile
      • PWD := $(shell pwd) 
        KVERSION := $(shell uname -r)
        KERNEL_DIR = /usr/src/linux-headers-$(KVERSION)/
        
        MODULE_NAME = hello
        obj-m := $(MODULE_NAME).o
        
        all:
         make -C $(KERNEL_DIR) M=$(PWD) modules
        clean:
         make -C $(KERNEL_DIR) M=$(PWD) clean
      • 測試
      • insmod hello.ko
        dmseg
        
      • 程式架構
        • header: 重要 headers: linux/init.h, linux/module.h 含有後面要用到的 marcos
        • license
        • module_init()
        • module_exit
      • Kernel module v.s. user space application
      • insmod/modprobe/rmmod/lsmod
      • module lifecycle - facility
      • module parameter
        • module_param(parameterName, type, permission)

2017年7月15日 星期六

[Kernel] Portal


2017年6月16日 星期五

[License] GPL v.s. LGPL & GPL in Linux


  • 簡單比較
    • GPL:
      • 保護 application
      • 較嚴苛
      • release binary時, 需要 release source code
      • 僅為執行(非修改)此 binary使用, 不用 release source code
    • LGPL:
      • 保護 library
      • 較寬鬆
      • dynamically or statically link則無限制
  • 在 kernel 上所執行的使用者應用程式都不受 GPL制約

2013年6月5日 星期三

[Vim] Mac中 Vim 設定


  • 預設路徑
    • binary: /usr/bin
      support file: /usr/share/vim/vim73
      rc: ~/.vim/vimrc (若沒有, 請自己建)
  • 細節

    • 單一檔案的 plugin 應放在 ~/.vim/plugin下, e.g. a.vim
    • 其他 plugin一句底下的資料夾放置(例如: ctrlp)
      • ~/.vim/autoload/ctrlp/
      • ~/.vim/autoload/ctrlp/ctrlp.vim
      • ~/.vim/doc/ctrlp.txt
      • ~/.vim/plugin/ctrlp.vim
    • plugins/colorschemes/scripts 放在 ~/.vim下, not /usr/share/vim/vim73
  • 推薦 plugins:
    • a.vim: 在 header與 source file間切換
      • :A =>切換
      • :AT =>切換至新開的 tag page
      • :AS => split? 垂直分割
      • :AV => horizontal 分割
      • 不知為啥, 我覺得 :AS與 :AV 沒作用
  • Ref:

[Vim] vim 快攻


  • 重要參數
    • 可單獨操作
      • b  before
      • e  end
      • w  word
      • $  行末
      • 0  行頭
    • g global
    • c confirm
    • ! 強制
  • 移動
    • hjkl  分別是左下上右, 應該主要是右手食指上中指下
    • gg  檔案起始處
    • #shift-G  #代表行號, 沒輸入則是到檔案最後一行  
  • 檔案操作
    • :q     quit
    • :wq  write & quit
  • 文件編輯
    • i  insert
    • x  ...這不知道是啥
    • a  append, A  可在行末 append
    • d  delete, 可搭配參數, e.g: dw, d$, d0
    • p  paste
    • u  undo, U: 還原整行, ctrl-R為還原先前操作
    • o  open new line
    • %  找到配對的括號
    • dd 刪除行
  • 搜尋與取代類
    • /   向下搜尋, 找到後用 n跳至下一個, shift-N至上一個
    • ?  向上搜尋
    • 環境可設定 :set hls  highlight search, 便會有如 source Insight中 F8的功能啦, 要讓它消失則下 :noh   noHightLight
    • r   replace 單一字元
    • R  是同進入取代模式
    • c  change, 搭配參數用, e.g. cw: change word, 會取代掉 cursor所在的 word
    • :s  strike, 應該會是最常用的功能
      • s/old/new/g  將 old用 new取代, 若後面加 /g則為 global
      • s/old/new/gc  c是 confirm用
      • #,#s/old/new/gc  #是行號, 代表在這兩行之間的取代動作
  • 執行外部指令
    • :!script, script為 shell script, e.g. :!ls, 但有些動作還是不能操作, 剛試驗了一下, :!cd ~/Desktop, 再執行 :!pwd, 似乎並沒改變
    • :r fileName, 可將檔案 fileName的內容貼到目前 cursor處
  • 外掛類
    • a.vim
      • :a  switch between header/source code
    • ctag
    • auto complete
      • Ctrl-N

2013年6月1日 星期六

[Linux] GRUB2 開機順序

  • cd /etc/grub.d/ (開機順序存放在此資料夾, 以 prefix數字小到大的順序開機, 預設 linux為 10_linux, 優於 30_os-proper的 windows作業系統, 因此, 執行以下兩步驟, done!)
    • 30_os-proper 更名為 08_os-proper (mv ./30_os-proper ./08_os-proper)
    • sudo update-grub

2012年12月17日 星期一

[Linux] EOF

Linux中以 Control+D 來表示 EOF (End-Of-File), MicroSoft Windows 則是 Control+Z