2014年1月24日 星期五

TMUX (Terminal MUltipleXer )

screen 與 tmux 的比較  (from http://josephj.com/entry.php?id=373)

稍微整理一下 screen 與 tmux,大家就會知道 tmux 有多好了。

screen

screen 架構
screen 的架構很簡單,一個 screen 連線只能被一個 SSH 連線存取、
一個 screen 可有多個 window、
只支援水平分割、同時觀看多個 window。

tmux

tmux 的架構
tmux 管理的東西較多:包括 Session(連線)、Window(視窗)與 Pane(窗格)。

tmux 優點 1 - 可以被多個 SSH 同時連線

tmux Session 可以被多個 SSH 同時連線,這點跟 Screen 很不同。
過去用 screen 你離開辦公桌的電腦,晚上回到家裡繼續工作時,必定得 detach 再 attach。
但是用 tmux 的話,你可以在家裡 attach,隔天到公司 tmux 並不會被 detach。
所以若你開兩個 tmux 同時 attach 到同一個 Session 時,可以看到兩個視窗同時動作的有趣畫面喔。
所以在這樣的架構下,你就不用擔心像 screen 不正常斷線無法 detach 再 attach 的問題了。

tmux 優點 2 - 可在 Session 中切換到不同 Session

過去要從 screen 到另一個 screen 得先 detach,
但 tmux 只要用快速鍵(預設 Ctrl-b + s)即可切換到其他 Session。
是不是很方便呢?

tmux 優點 3 - 強大的分割視窗

screen 只能做單一水平分割,但是 tmux 可以自由自在地水平或垂直分割。
一個窗格被稱為 Pane,分割會被記錄至 Window 保存(screen 只要一 detach 就沒了)
且一個 Pane 可隨時轉換成 Window,Pane 調整大小、位置的功能更是完整。
---------------------------------------------------------------------------------------------------
操作方式、常用快捷键:
大寫的C==>Control鍵
C+b c 開新視窗
C+b n 或 space 切換到下一個視窗
C+b P 切換到上一個視窗
====視窗分割功能======
C+b " 水平分割視窗
C+b % 垂直分割視窗
C+b up or down 切換分割視窗
C+b C上 or C下 分割視窗大小調整
C+b C左 or C右 分割視窗大小調整
C+b space 重新佈置分割的視窗
C+b ! 取消所有分割視窗
指令 exit 跳出當前分割視窗
C+b + Ctrl + 方向鍵上/下/左/右
# 可以調整當前分割視窗的長寬,好用!
作用鍵 + d
# 將目前的 Tmux Session 丟到背景去
tmux ls
# 列出主機上所有的 Tmux Session
tmux a -t 0
# 將背景的第 0 號 Tmux Session 叫回,a 代表 attach
Ctrl+b激活控制台;此时以下按键生效
系统操作?列出所有快捷键;按q返回
d脱离当前会话;这样可以暂时返回Shell界面,输入tmux attach能够重新进入之前的会话
D选择要脱离的会话;在同时开启了多个会话时使用
Ctrl+z挂起当前会话
r强制重绘未脱离的会话
s选择并切换会话;在同时开启了多个会话时使用
:进入命令行模式;此时可以输入支持的命令,例如kill-server可以关闭服务器
[进入复制模式;此时的操作与vi/emacs相同,按q/Esc退出
~列出提示信息缓存;其中包含了之前tmux返回的各种提示信息
窗口操作c创建新窗口
&关闭当前窗口
数字键切换至指定窗口
p切换至上一窗口
n切换至下一窗口
l在前后两个窗口间互相切换
w通过窗口列表切换窗口
,重命名当前窗口;这样便于识别
.修改当前窗口编号;相当于窗口重新排序
f在所有窗口中查找指定文本
面板操作”将当前面板平分为上下两块
%将当前面板平分为左右两块
x关闭当前面板
!将当前面板置于新窗口;即新建一个窗口,其中仅包含当前面板
Ctrl+方向键以1个单元格为单位移动边缘以调整当前面板大小
Alt+方向键以5个单元格为单位移动边缘以调整当前面板大小
Space在预置的面板布局中循环切换;依次包括even-horizontal、even-vertical、main-horizontal、main-vertical、tiled
q显示面板编号
o在当前窗口中选择下一面板
方向键移动光标以选择面板
{向前置换当前面板
}向后置换当前面板
Alt+o逆时针旋转当前窗口的面板
Ctrl+o顺时针旋转当前窗口的面板
視窗取回
screen -r
tmux attach
視窗取回 by session name
screen -r session-name
tmux attach -t session-id
視窗開啟自訂 session-name
screen -S session-name
tmux new -s session-name # ex: tmux new -s irc
列出所有 session
screen -ls
tmux ls # tmux list-sessions
----------------------------------------------------------------------------
http://www.slideshare.net/slideshow/embed_code/30000994?rel=0&hostedIn=slideshare&no_embed_cta=true

2014年1月16日 星期四

undefined reference to rpl_malloc

如果編譯的時候遇到未定義引用rpl_malloc這個錯誤,有兩個方法可以解決。
  • 配置的時候加上了 - with-GNU-ld的這個參數
  • 或者在config.h中裡加上的#undef rpl_malloc

2013年12月20日 星期五

特殊MAC地址---官方保留

IEEE Std 802.1D and IEEE Std 802.1Q Reserved Addresses
Group MAC address value
Organization
using the value
Standard using the value
Notes
01-80-C2-00-00-00
IEEE 802
IEEE Std 802.1D
IEEE Std 802.1Q
IEEE Std 802.1D Bridge Group Address
01-80-C2-00-00-01
IEEE 802
"
IEEE MAC-specific control protocols
01-80-C2-00-00-02
IEEE 802
"
IEEE Std 802.3 Slow Protocols multicast address
01-80-C2-00-00-03
IEEE 802
"
IEEE Std 802.1X PAE address
01-80-C2-00-00-04
IEEE 802
"
IEEE MAC-specific control protocols
01-80-C2-00-00-05
IEEE 802
"
Reserved for media access method specific use
01-80-C2-00-00-06
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-07
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-08
IEEE 802
"
Provider Bridge group address
01-80-C2-00-00-09
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-0A
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-0B
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-0C
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-0D
IEEE 802
"
Provider Bridge MVRP address
01-80-C2-00-00-0E
IEEE 802
"
Std 802.1AB Link Layer Discovery Protocol address
01-80-C2-00-00-0F
IEEE 802
"
Reserved for future standardization

Standard Group MAC Addresses
Group MAC address value
Organization
using the value
Standard using the value
Notes
01-80-C2-00-00-10
IEEE 802
IEEE Std 802.1D
All LANs Bridge Management Group Address (deprectated)
01-80-C2-00-00-11
IEEE 802
IEEE Std 802.1E
Load Server Generic Address
01-80-C2-00-00-12
IEEE 802
IEEE Std 802.1E
Loadable Device Generic Address
01-80-C2-00-00-13
unassigned
  
01-80-C2-00-00-14
ISO/IEC JTC1/SC6
ISO/IEC 10589
All Level 1 Intermediate Systems Address
01-80-C2-00-00-15
ISO/IEC JTC1/SC6
ISO/IEC 10589
All Level 2 Intermediate Systems Address
01-80-C2-00-00-16
ISO/IEC JTC1/SC6
ISO/IEC 10030
All CONS End Systems Address
01-80-C2-00-00-17
ISO/IEC JTC1/SC6
ISO/IEC 10030
All CONS SNARES Address
01-80-C2-00-00-18
IEEE 802
IEEE Std 802.1B
Generic Address for All Manager Stations
01-80-C2-00-00-19
unassigned
  
01-80-C2-00-00-1A
IEEE 802
IEEE Std 802.1B
Generic Address for All Agent Stations
01-80-C2-00-00-1B
ISO/IEC JTC1/SC6
ISO/IEC 9542
All Multicast Capable End Systems Address
01-80-C2-00-00-1C
ISO/IEC JTC1/SC6
ISO/IEC 9542
All Multicast Announcements Address
01-80-C2-00-00-1D
ISO/IEC JTC1/SC6
ISO/IEC 9542
All Multicast Capable Intermediate Systems Address
01-80-C2-00-00-1E
ISO/IEC JTC1/SC6
ISO/IEC 8802-5
All DTR Concentrators MAC Group Address
01-80-C2-00-00-1F
unassigned
  
01-80-C2-00-00-20 —
01-80-C2-00-00-2F
IEEE 802
IEEE Std 802.1Q
Reserved for use by Multiple Registration Protocol (MRP) applications


01-80-C2-00-00-30 —
01-80-C2-00-00-3F
IEEE 802
IEEE Std 802.1ag
Destination group MAC addresses for CCM and Linktrace messages
01-80-C2-00-00-40 to 01-80-C2-00-00-4F
IETF
TRILL
Group MAC addresses used by the TRILL protocols
01-80-C2-00-00-40 —
01-80-C2-00-00-FF
unassigned
  
01-80-C2-00-01-00
 
ISO/IEC 9314-6
Ring Management Directed Beacon Multicast Address
01-80-C2-00-01-01 —
01-80-C2-00-01-0F
ISO/IEC JTC1/SC25
 
Assigned to ISO/IEC JTC1/SC25 for future use
01-80-C2-00-01-10
ISO/IEC JTC1/SC25
ISO/IEC 9314-6
Status Report Frame Status Report Protocol Multicast Address
01-80-C2-00-01-11 —
01-80-C2-00-01-1F
ISO/IEC JTC1/SC25
 
Assigned to ISO/IEC JTC1/SC25 for future use
01-80-C2-00-01-20
ISO/IEC JTC1/SC25
ISO/IEC 9314-2
All FDDI Concentrator MACs
01-80-C2-00-01-21 —
01-80-C2-00-01-2F
ISO/IEC JTC1/SC25
 
Assigned to ISO/IEC JTC1/SC25 for future use
01-80-C2-00-01-30
ISO/IEC JTC1/SC25
ISO/IEC 9314-6
Synchronous Bandwidth Allocation Address
01-80-C2-00-01-31 —
01-80-C2-00-01-FF
ISO/IEC JTC1/SC25
 
Assigned to ISO/IEC JTC1/SC25 for future use
01-80-C2-00-02-00 —
01-80-C2-00-02-FF
ETSI
 
Assigned to ETSI for future use
01-80-C2-00-03-00 —
01-80-C2-FF-FF-FF
unassigned
  

Group MAC Addresses Used in ISO 9542 ES-IS Protocol
Group MAC address value
Organization
using the value
Standard using the value
Notes
09-00-2B-00-00-04
ISO/IEC JTC1/SC6
ISO 9542
All End System Network Entities Address
09-00-2B-00-00-05
ISO/IEC JTC1/SC6
ISO 9542
All Intermediate System Network Entities Address
Locally Administered Group MAC Addresses Used by IEEE Std 802.5
(IEEE Std 802.5 Functional Addresses)
Group MAC address value
Organization
using the value
Standard using the value
Notes
03-00-00-00-00-08
IEEE 802
IEEE Std 802.5
Configuration Report Server (CRS) MAC Group Address
03-00-00-00-00-10
IEEE 802
IEEE Std 802.5
Ring Error Monitor (REM) MAC Group Address
03-00-00-00-00-40
IEEE 802
IEEE Std 802.5
Ring Parameter Server (RPS) MAC Group Address
03-00-00-00-01-00
IEEE 802
ISO 9542
All Intermediate System Network Entities Address
03-00-00-00-02-00
ISO/IEC JTC1/SC6,
IEEE 802
ISO 9542, and
IEEE Std 802.5
All End System Network Entities Address, and Lobe Media Test (LMT) MAC Group Address
03-00-00-00-04-00
IEEE 802
IEEE Std 802.1B
Generic Address for all Manager Stations
03-00-00-00-08-00
IEEE 802
ISO/IEC 10030
All CONs SNARES Address
03-00-00-00-10-00
IEEE 802
ISO/IEC 10030
All CONs End System Address
03-00-00-00-20-00
IEEE 802
IEEE Std 802.1E
Loadable Device Generic Address
03-00-00-00-40-00
IEEE 802
IEEE Std 802.1E
Load Server Generic Address
03-00-00-40-00-00
IEEE 802
IEEE Std 802.1B
Generic Address for all Agent Stations

2013年12月10日 星期二

Raspberri-Pi Debian Tuning

Speedup CPU:
we can easily modify the cpu work frequency modifying the config.txt file. Just edit /boot/config.txt
arm_freq=900
i always use this hack and my rpi run without problem
Change scheduler/elevator at boot time:
we use more responsive/less disk io usage scheduler:
modify the /boot/cmdline.txt 
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=120,data=writeback elevator=deadline rootwait quiet
Tuning sysctl.conf:
as manual say, sysctl.conf is the “Configuration file for setting system variables”... well there are lot of variables you can put inside this file and for everyone we can write a book.
Our goal is to gain more speed and tell our system to use less io/ram. Let’s put in the /etc/sysctl.conf:
vm.dirty_background_ratio = 20
vm.dirty_expire_centisecs = 0
vm.dirty_ratio = 80
vm.dirty_writeback_centisecs = 1200
vm.overcommit_ratio = 2
vm.laptop_mode = 5
vm.swappiness = 10
Removing unused services:
Removing services is a must to do for every system or computer, i have see some linux server with 256Mb of RAM with bluetooth, pcmcia etc etc service enabled... or pc with 100% cpu busy to run some 3d tube screensaver installed by default... also in Debian RaspberryPi official distro...
Automatically startx on boot:
I didn't use session/desktop manager like gdm, xdm or slim, it’s take ram and slow down starting up. Simply way is to use inittab:
vi /etc/inittab
1:2345:respawn:/bin/login -f root tty1

/dev/tty1 2>&1 (default is 1:23:respawn:/sbin/getty 38400 tty1)
and add this to .bash_profile on root home:
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
  exec startx >/dev/null 2>&1
fi 

2013年11月22日 星期五

libiconv: 字元集碼編轉換

from:http://www.jollen.org/blog/2006/09/libiconv_1.html

實作 Linux 系統程式時,常需要做「Unicode 與 Big5」間的字元編碼轉換;嵌入式 Linux 的應用也經常會遇到這樣的需求,例如我們原則上會將文件存成 Unicode,當程式執行時,再決定要輸出成 Unicode 或 Big5 (or GBxxxx),這時就要使用到 GNU 的 libiconv 專案。
GNU libiconv 用來做字元間的編碼轉換,已經廣泛被使用在 GNU/Linux 系統中,例如 PHP 的 iconv 系統即是使用 GNU libiconv。libiconv 要移植到 ARM9 平臺上也是非常容易的。GNU libiconv 的官方首頁是:http://www.gnu.org/software/libiconv/
把 libiconv 套件解開並編譯後,可以在 src/ 目錄下找到 iconv 執行檔,這是 libiconv 為我們寫好的一個字元轉碼 (conversion) 工具,這個工具相當的實用,比如以 jollen 的網站來說,jollen.org 的網頁是以 unicode 儲存,但是我們發佈的頁面是以 big5 編碼為主,我們所使用的轉換工具便是 iconv。
iconv 的使用可以參考 http://www.gnu.org/software/libiconv/documentation/libiconv/iconv.1.html,我們舉一個例子來說明,比如我想把 big5.txt 文件 (Big5 encode) 轉換成 Unicode (UTF-8),那麼只要執行:
$ iconv -f BIG5 -t UTF-8 big5.txt
就可以了,參數 -f 指定來源編碼,參數 -t 指定目的編碼,編碼後的字串會輸出到 stdout。字元集 BIG5 也可以寫成 BIG-5,或是 BIG-FIVE,或是 BIGFIVE;要怎麼知道 iconv 可以處理 (接受) 哪些字元集 (character set ),只要執行 'iconv -l' 就可以查詢了,輸出結果會是一大票的字元集列表。
這是使用 iconv 工具的方式,假如要自己寫程式的話也是非常簡單的,因為 libiconv 裡頭只有 3 個函數:
iconv_t iconv_open (const char* tocode, const char* fromcode):開啟 libiconv。
size_t iconv (iconv_t cd, const char* * inbuf, size_t * inbytesleft, char* * outbuf, size_t * outbytesleft):執行轉碼。
int iconv_close (iconv_t cd):做完轉碼後關閉 libiconv。
libiconv-1.xx/src/iconv.c 本身就是一個很棒的範例了,大家可以參考。

關於 gettext

關於 gettext (一、簡介)

關於 gettext (二、一個例子)

關於 gettext (po-mode 使用)

2013年11月7日 星期四

TCP offload engine (TOE)

from:http://www.kernelchina.org/node/611
延伸閱讀:
Competitive Comparison Intel® I/O Acceleration Technology vs. TCP Offload Engine

TCP減壓引擎,第一次聽說這個名詞,但是並不是一個新的概念了,若干年前聽說過設備廠商在研究在FPGA之中實現TCP Stack,但是後來沒有聽到任何的產品出來,應該是路由設備to host的traffic不多,而對於FW設備,中間的TCP Proxy實現過於復雜,工程上不可能實現。
現在的所謂TOE實現我理解主要用於host的interface之中,用於為Gbits以及10Gbits接口場景中為CPU減壓,例如部署在數據中心內部的服務器,CPU雖然越來越快,但是對於洶湧澎湃的Traffic來說,還是有些力不從心。
clip_image002
上面是TOE應用前後協議棧的差別,我覺得畫的有點絕對,TCP Stack不太可能完全實現在interface之中,其實TOE主要實現如下的offload:
1.TCP/IP Checksum offload
CPU可以不用計算checksum而由網卡計算
2.CPU不用考慮數據的分段了,估計是直接將socket送過來的buf交給網卡。
如果是僅僅實現上述功能TOE是很可能工程化實現的。
在另一篇文檔中提到了TOE的一些優勢,但是我的分析,這個可能是要實現TOP替代整個TCP之後的優勢。
1.減少中斷:不用每個報文都產生中斷,如果10G接口這個對於CPU是很大的開銷。
2.減少memory拷貝次數,很多時候網卡的buffer和app的可以直接共享。
3.協議處理的節約,這個是當然的了。

* http://en.wikipedia.org/wiki/TCP_offload_engine


How to repair and clone disk with ddrescue

  ddrescue  is a tool that can be used to repair and clone disks on a  Linux system . This includes hard drives, partitions, DVD discs, flas...