網頁

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

2010年5月26日 星期三

Virtual File System (VFS)

File System Category
Disk-based file system
journal file system: provide backup file system, more security
FAT -> NTFS
Network file system
NFS, SMB(CIFS), Samba(Unix-based SMB), AFS...
Special file system
/proc, /dev, devfs...


File System Abstraction Layer
/tmp (in-memory file system - RAM disk)

Unix file system
Filesystem are mounted at a specific mount point in a global hierarchy known as a namespace.
mount point(nfs, \tmp)

Each component of a path is called a directory entry(dentry)

inode - file's metadata
superblock - filesystm metadata

Non-Unix filesystem still work in Linux(FAT, NTFS)
special processing done on the fly


VFS Objects

superblock, inode, dentry, file
[              static              ]


sync_fs() best effort
link() - create a inode
dentry cache (d-cache)
inode cache (i-cache)

fs_struct (Process decriptor's fs field)

2010年5月24日 星期一

pkg-config

pkg-config is a useful tool for compiling.
It helps to insert correct compiler options on the command line for gcc/g++ compiler.
example:

            `pkg-config gtk+-2.0 --cflags`                      //include gtk+2.0 lib
            `pkg-config opencv --libs --cflags opencv`    //include opencv lib



[Reference]
pkg-config wiki - http://pkg-config.freedesktop.org/wiki/

2010年5月20日 星期四

Ubuntu - ADSL Access

對象: 需帳密的ADSL (浮動IP)
方法:
sudo pppoeconf
進入PPPOE設定程式。
  1. 偵測你哪一張網路卡連接到ISP。他會列出所有偵測到的網路介面並詢問你他是否已找到所有網路介面
  2. 問你是否想用「noauth」、「defaultroute」選項,沒有特殊需求的話,直接答「yes」即可。
  3. 鍵入ADSL用戶名稱
  4. 鍵入ADSL密碼
  5. 問你是否使用 ISP 提供的 DNS 伺服器,沒有特殊需求的話,直接答「yes」即可。
  6. 是否要把 MSS 限制不大於1452位元組,沒有特殊需求的話,直接答「yes」即可。
  7. 問你是否想每次啟動 Ubuntu 時自動連線網路
  8. 最後會問你是否想現在即時連線上網


2010年5月19日 星期三

Device Driver

Device driver
/dev : a list of device node (sudo file system)
type
major number
minor number

2 special device  nodes
dev - null
dev - zero

dev_t dev =MKDEV(major, minor)
register_chrdev


/proc/devices: list of devices

File Operations
struct file_operations scull_fops
open - initialization

2010年5月13日 星期四

[轉錄] SCREEN

使用 screen

[出自 http://tavi.debian.org.tw/index.php?page=screen ]

在命令列下打 screen 就會進入 screen 的天地:

% screen

注意,所有 screen 的指令都是以 Ctrl 鍵加上 a 鍵開始的,在之後以 C-a 代表,C-a c 代表按住 Ctrl 鍵不放再按 a 鍵,然後放開按 c 鍵;而 C-a C-c 代表按住 Ctrl 鍵不放再按 a 鍵,然後放開後再按住 Ctrl 鍵不放按 c 鍵。

開啟,關閉,切換

C-a c 或 C-a C-c 開啟新的視窗,並同時切換到這個新的視窗

C-a n 或 C-a C-n 或 C-a (space) 切換到下一個視窗(0->1 1->2 ...)

C-a p 或 C-a C-p 切換到上一個視窗(1->0 2->1 ...)

C-a C-a 切換到上一個顯示過的視窗(不是照順序切換)

C-a 0 切換到第 0 個視窗

C-a (1..9) 切換到第 (1..9) 個視窗

C-a w 或 C-a C-w 會列出目前所開啟的視窗

0$ tcsh 1$ tcsh 2*$ tcsh 3$ tcsh

有星號 "*" 的表示目前顯示中的視窗,之後的 tcsh 代表這個視窗的 title ,預設是以開啟時的 shell 名稱

C-a K 關閉所有的視窗並退出 screen

C-a ' 或 C-a " 會出現 "Switch to window:" 字樣,輸入號碼後就可切到該視窗

單一視窗使用中的指令

C-a C 清除目前的視窗內容

C-a d 或 C-a C-d 脫離(detach)目前的 screen ,並放到背景執行(不管開了幾個視窗),下面會再提到

C-a D D 強力脫離,除了放到背景執行外,並自動 logout

C-a C-g 視覺化鈴聲(visual bell)的切換,可以在畫面上顯示訊息代表一般的嗶聲

C-a H 紀錄目前視窗所有顯示過的東西(檔名為 screenlog.n n 為視窗號碼)

C-a i 或 C-a C-i 顯示目前視窗的資訊

(11,24)/(80,24)+1000 +(+)flow -ins -org +wrap +app -log -mon +r G0 [BBBB]

C-a l 或 C-a C-l 重繪視窗,如果有字顯示亂掉了可以用這個指令

C-a m 或 C-a C-m 或 C-a (enter) 可以顯示最近一次顯示過的訊息

C-a t 或 C-a C-t 顯示系統的時間及主機名稱還有負載

C-a v 顯示版本資訊

C-a x 或 C-a C-x 如果你要暫時離開目前位置又不想先 logout ,那可以用這個來鎖住 screen

C-a ? 線上求助畫面

複製/卷軸 模式

按下 C-a [ 就可以進入 複製/卷軸 模式(只有在目前視窗才算,其他視窗照常)基本上跟 vi 很像:

h, j, k, l 分別為向左,向下,向上,向右移動一格(或是一行)

0 移到該行最左邊

^ 與 $ 分別移到該行最左邊及最右邊的非空白字元

w 以字為單位往前移動並移到字首

b 以字為單位往後移動並移到字首

e 以字為單位往前移動並移到字尾

C-b 向上捲一頁

C-f 向下捲一頁

C-u 向上捲半頁

C-u 向下捲半頁

/ 與 ? 向下或向上尋找字串

(space) 第一次按下到第二次按下的區域會被複製到暫存區內

(ESC) 離開 複製/卷軸 模式

接著按下 C-a ] 便可以把剛剛存到暫存區內的內容複製出來。

善用 screen

前面提到當按了 C-a d 脫離了 screen 後,會回到沒有執行 screen 時的狀態,但是同時在之前 screen 裡每個視窗內在跑的 process (不管是前景或背景執行的)仍然繼續執行,即使 logout 也不會有影響。所以你可能接著離開身邊的電腦,然後跑出去喝個水,或者另外找個舒服的地方坐下來再接著剛剛的工作。

好,當你重新登入(login)之後,要怎麼接回剛剛的 screen 呢?重打 screen 只會讓電腦另外又開個 screen 給你,你所要做的事就是加些參數:

screen -ls 顯示目前個人所有的 screen

% screen -ls

There are screens on:

1188.ttyp4.SungSung? (Attached)

76920.ttypq.SungSung? (Detached)

2 Sockets in /tmp/screens/S-AlanSung?.

上面的 Attached 表示你現在連接的 screen ,而 Detached 則表示沒有連接的,最後則是共有多少個 screen 數量

screen -r 就是重新回到(resume)screen 裡,如果你只有開一個 screen ,那只要簡單地打

% screen -r

就沒問題了,但是像上面那個,如果你有了兩個以上的 screen ,這樣就有問題了

% screen -r

There are several screens on:

1188.ttyp4.SungSung? (Detached)

76920.ttypq.SungSung? (Detached)

Type "screen [-d] -r [pid.]tty.host" to resume one of them.

如它的訊息所述,你可以加上它的 process id 或是使用的 tty 加上主機名來決定要接回那一個 screen 。假設在這裡我們要接回 process id 為 1188 的那一個,就打

% screen -r 1188



% screen -r ttyp4



% screen -r ttyp4.SungSung?



% screen -r 1188.ttyp4.SungSung?

都可以

screen -d 假設現在自己的電腦突然當機,或是網路突然斷了一時連不上去,等到好了之後,想要接回來原來的 screen 卻發現

% screen -r

There is a screen on:

1188.ttyp4.SungSung? (Attached)

There is no screen to be resumed.

這時候 -d 這個參數就派上用場了,讓你可以控制某個 screen 脫離(detach),接著再加上 -r 把這個 screen 接手回來

% screen -d

[1188.ttyp4.SungSung? detached.]

% screen -r

或直接

% screen -d -r

screen -wipe 有時候不小心跳電了,這時候重開機後當然也不會有 screen 留著,但是由於 screen 會有紀錄所有的 screen ,因為雖然舊的沒有了,可是還是有紀錄在,因此這個指令就是把廢棄不用的 screen 給"擦拭乾淨"(wipe)

There are screens on:

69103.ttyp5.SungSung? (Removed)

529.ttyp0.SungSung? (Detached)

1 socket wiped out.

1 Socket in /tmp/screens/S-AlanSung?.

會用了上面所介紹的功能,你可以現在進入 bbs ,進入聊天室跟人聊天或是在上面發表文章到一半,發現計中要關門了,你可以從容的 detach ,回家之後再連回來 attach ,繼續剛剛的話題或發表文章,而對方可能根本沒發覺。只要你連線的主機不當機,那電話線或網路再怎麼不穏都不必怕斷線。

如果你需要更多詳細的資料,可以善用線上手冊(manual pages)或是 info 這個指令

% man screen

% info screen

2010年5月12日 星期三

VSPM

Linux Highlight (1)

lsmod (list modules)- observe how many modules included in kernel now
         -- display content: module name, size, and used by
 
insmod (insert modules) - mount modules to the kernel
rmmod (remove modules) - unmount modules from the kernel


TODO

2010年5月11日 星期二

AWK

Pattern { Action }
     -> If Pattern is true, do Action.

Pattern will exploit "Relational Expression".


[Relational Expression]
>, <, ==, != ...etc.
~(match)
!~(Not Match)


[EXE]
1. awk -f awkfile [file]
2. $ awk 'shell action' [file]
3. script and chmod +x to instruction

[awk action format]
awk 'pattern' file : display rows which match patterns
awk '{action}' file : execute the action in {} for every row
awk 'pattern{action}' file: execute the action for the rows which match patterns

[argument passing]
awk -v varible 'pattern' file
ex: awk -v avar="$svar" '$0 == avar' file

[Reference]
AWK tutorial

Regular Expression

 regular expression

一個 regular expression是被表示於斜線( / / )之間,並且比對是採用 =~ 為操作子

. # 任何單一字元除了 newline
^ # 一行或一字串的起始 [限制字串出現於行首]
$ # 一行或一字串的尾端 [限制字串出現於行末]
* # 零或多個最後的字元 [重複出現 - 可以沒有]
+ # 一或多個最後的字元 [重複出現 - 至少一個]
? # 零或一個最後的字元 [重複0或1個]

2009年9月25日 星期五

Mail Server

Mail Server

law@gmail.com
law為使用者名稱
gmail.com為主機名稱

Mail server componet
1. MUA ─ Mail User Agent 使用者用以寫信收信的程式。
2. MTA ─ Mail Transfer Agent 負責轉送信的伺服器。(功能是Relay)
3. MDA ─ Msil Delivery Agent 負責將要給本地使用者的郵件分配到使用者信箱中。(Mail)



POP3「Post Office Protocol - Version 3」
支持使用客戶端遠程管理在伺服器上的電子郵件。支援「離線」郵件處理。

Method: 郵件發送到伺服器上,MUA連接伺服器,並下載所有未閱讀的電子郵件。這種離線訪問模式是一種存儲轉發服務,將郵件從server送到terminal上,一旦郵件download,郵件伺服器上的郵件將會被刪除。

Internet Message Access Protocol (IMAP)
類似POP3 但有以下其他功能:
* 支援連線和離現兩種操作模式。
* 支援多個USER同時連線到一個郵箱。
* 支援在伺服器保留訊息狀態資訊。
* 支援在伺服器上存取多個郵箱。