2013年12月5日 星期四

程式上色

請參考這一篇 文章

http://yodalee.blogspot.tw/2012_09_01_archive.html


以下兩段 codpe


    cout<<"\033[2;31;47m hello \033[m"<<endl;
    printf("\033[0;31;40m hello \033[m \n"   );


執行結果如下



2013年11月25日 星期一

PCIe 找法

http://pjack1981.blogspot.tw/2012/05/how-to-know-pci-express-speed-on-server.html


width
有 x1 x4 x8 x16  一般來說  server 一端 就只有兩個 x8
 有看 width  如果 width =16 就是 x16

在補充 就是 5GT/s  是指 gG transfer/sec


另外一個網站
http://www.techpository.com/?page_id=1335

是使用
dmidecod  去做

雖然不是很懂  他怎麼用的 !!!

http://fcamel-life.blogspot.tw/2010/06/ubuntu.html


2013年11月21日 星期四

如何 在 terminal 上看到 自己的 OS 版本



只要下這個指令

lsb_release -a


LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.4 (Final)
Release:        6.4
Codename:       Final


參考網頁
http://murray.cn/index.php/2011/03/chakan-linux-centos-var/

如何使用 qemune


這篇 有參考價值 :
http://www.ptt.cc/bbs/b97902HW/M.1287699530.A.966.html

2013年11月19日 星期二

加入 manul page

方法一

修改  /ect/man.config

加上這一行

MANPATH /opt/intel/vtune_amplifier_xe_2013/man

2013年11月14日 星期四

cent os linux 下 安裝 matlabs

http://maxubuntu.blogspot.tw/2008/12/matlab-r2008a.html


http://blog.yam.com/ybchen/article/9889039


在安裝  matlabs 的時候 會有這個問題

如果  我們 x11 的認證 只認得 user ex Andy  這個 指紋
此時  我們切換到  root 去
然後 下 ./install 的時候 會發現指紋 不對 此時
會出現很多很多錯誤
6 error class
此時可以參照這個網頁的說明  用 xauth 去改變那個指紋
joelinoff.com/blog/?p=729

xauth list 看到 對應的指紋

讓  root 的指紋變成 Andy 的指紋 則就可以去 run ./install
ex  xauth remove Paris/unix:1

xauth add Paris/unix:10 MIT-MAGIC-COOKIE-1 4b8406c88c4cba99ce312ad2~~~~~

X11 enable

先去    /etc/ssh/sshd_config

更改   X11 forward  = yes的這個值  

這樣做的意義表示    遠方的那台主機 (在冷氣很強的機房裡面的那一台主機)
允許   從那邊run 的程式 可以經由 ssh 連到 X11 這個  軟體協議上面



同時  我們開 putty 的 時候  也要在  下面的 connection 的地方 把 enable X11 forward 的選項打勾
如此一來  表示 我們 (筆電端) 的 筆電 允許 別人(機房主機) 用 x11 跟我連線


完成上述步驟之後呢

安裝東西 等等的 都可以跑出現 windows 那個安裝 圖示介面了 !!!



關於 X11 這個東西的詳細介紹 請參考 鳥哥的網站


http://linux.vbird.org/linux_basic/0590xwindow.php



ssh 的 機制

當 ssh 連不出去 而且會出現下面的訊息的時候

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
c0:87:39:48:e8:d3:d5:2d:86:62:ba:8c:9f:64:22:03.
Please contact your system administrator.
Add correct host key in /home/raid5/Andy/.ssh/known_hosts to get rid of this message.
Offending key in /home/raid5/Andy/.ssh/known_hosts:2
RSA host key for 140.AAA.BBB.CCC has changed and you have requested strict checking.
Host key verification failed.



表示 對方的  一些資訊已經被改掉了  而本地的  資訊卻沒有跟著改變 
所以 只要把 本地的 資料記錄處也給  砍掉就可以了  
方法如下  
要把rm  ~./ssh/know_host 的相關資料給砍掉  這樣就可以連過去了 

觀察 linux 下的 硬碟到底有多少


看到 硬體有幾個 blocks
http://unix.stackexchange.com/questions/52215/determine-the-size-of-a-block-device


另一個 網誌
看到一個 block 有多少 bytes
http://asser123.blog.163.com/blog/static/30170110201091995819410/


2013年11月1日 星期五

轉自鳥哥

如果我們要查閱一個檔案的內容時,該如何是好呢?這裡有相當多有趣的指令可以來分享一下: 最常使用的顯示檔案內容的指令可以說是 cat 與 more 及 less 了!此外,如果我們要查看一個很大型的檔案 (好幾百MB時),但是我們只需要後端的幾行字而已,那麼該如何是好?呵呵!用 tail 呀,此外, tac 這個指令也可以達到!好了,說說各個指令的用途吧!
  • cat  由第一行開始顯示檔案內容
  • tac  從最後一行開始顯示,可以看出 tac 是 cat 的倒著寫!
  • nl   顯示的時候,順道輸出行號!
  • more 一頁一頁的顯示檔案內容
  • less 與 more 類似,但是比 more 更好的是,他可以往前翻頁!
  • head 只看頭幾行
  • tail 只看尾巴幾行
  • od   以二進位的方式讀取檔案內容!

/usr 的意義與內容

/usr 的意義與內容

這邊鳥哥說得很清楚
就是
與寫程式 最相觀的就是  include/
usr/include 裡面呢  是系統預設 表頭黨

例如 include <stdio.h>
這個就放在這裡

usr/lib 或 /usr/lib64
就是 放一些library  也是預設路徑

舉例說明
gcc  main.cpp -lpthread
這個 pthread 就會來 ussr/lib 下面來做搜尋  這個 pthread.so 檔案


2013年10月31日 星期四

.a .so

.a 一堆 .o 合起來

.so  shared objects

/include 裡面 放的  一堆 .h 檔案


告訴 compiler 說 這類型的檔案  存在於某個地方


.so 是在 link 的時候 把這項 library 給  link 起來
讓   這些可以用

例如   說  printf 這個 function 的 被實做出來 並且放在 某個 .so裡面
在 程式 run 的時候才會呼叫出來
就是這個ˇ道理
通常  會放在 lib/ 下面




轉自 http://bbs.chinaunix.net/thread-1332374-1-1.html

Archive 相當於某個人(這個可能是你也可能是別人)在編一個程序的時候中途留下了很多.o 文件沒用光。怎麼辦? Archive 起來,以後寫別的程序用得著。所以你的程序如果用了archive,連接到的是“靜態”庫,庫好像已經和你的程序化為一體,不分彼此。

Shared object 呢?你的心態又不一樣了。你寫程序,寫著寫著發現很多程序都要用到同一段代碼,怎麼辦?直接copy 過去省事啊,不過維護起來麻煩。用 archive?也還行,只是有點浪費空間了。那怎麼辦?一拍大腿,點子來了,share 一下這個object,這樣既方便維護,又節省空間。

現實環境裡兩種情況都有,自己想想清楚每一種的目的是要幹啥就行了。

2013年10月30日 星期三

tar 進階版



如果 檔案 是  有 zip 的  !!

則 需要下列的指令

tar -zxvf  myfile.tgz


or
gunzip myfile.tgz |  tar -xv


Sudo

sudo 使用方式如下

以下是 example

 command.sh 是 要下的指令

sudo -u root   ./command.sh



2013年10月3日 星期四

觀看環境變數


command line 下
export
會列出所有的環境變數的值
即可

設定 環境變數 方法

注意  環境變數 是一種變數
它可以是  一個變數  例如  TILE_ROOT= /opt/tilera/....
表示 當在 Makefile 或是 其他 scritp  檔案的時候  讀取到 TILE_ROOT 會自動變成  /opt/tiler/...

要設定方法就是  export TILE_ROOT=/opt/tilera/... 即可以當下設定好此變數

如果說 是 當輸入 g++ 的時候  shell 可以找到  這執行黨的 目錄 就必須把 這個執行黨(g++)所在的目錄 給 設定到環境變數裡面 也就是說 也就是 是設定到 PATH 這個變數裡面


ex  /mynewpath/

PATH =$PATH:/mynewpath/

以上的表示 會把 現有的 環境變數 加上/mynewpath/ 這個環境

PATH =PATH  + "your new environment path"




2013年8月26日 星期一

linuex Clags

-g 表示 用來 debug 的旗號

-pg 表示用來 profile 的旗號  ( gprof )

2013年8月19日 星期一

vim linux

linux 下


開  vim


若不小心按到    pause /break 則
vim 會消失  請在 terminal 下 按 fg 他就會回來了  

2013年8月7日 星期三

gprof

在 Makefile 裡面的 flags 加上這一行
-pg

去run 程式   會產生一個  gmon 黨
舉例說明  
./bsp BSP_tree  ddd  dddd dd

再度下這一行指令 也就是
gprof (exe 檔)
gprof bsp

2013年8月1日 星期四

Valgrind 來監看 記憶體 大小

使用方法
Valgrind  -v   ./a.out


 跑完的結果會出現

Total Execution Time = 110.06 seconds
==31065==
==31065== HEAP SUMMARY:
==31065==     in use at exit: 2,591,288 bytes in 23,679 blocks
==31065==   total heap usage: 128,904 allocs, 105,225 frees, 15,854,055 bytes allocated
==31065==
==31065== Searching for pointers to 23,679 not-freed blocks
==31065== Checked 162,024 bytes
==31065==
==31065== LEAK SUMMARY:
==31065==    definitely lost: 912,142 bytes in 2,531 blocks
==31065==    indirectly lost: 1,679,146 bytes in 21,148 blocks
==31065==      possibly lost: 0 bytes in 0 blocks
==31065==    still reachable: 0 bytes in 0 blocks
==31065==         suppressed: 0 bytes in 0 blocks
==31065== Rerun with --leak-check=full to see details of leaked memory
==31065==
==31065== Use --track-origins=yes to see where uninitialised values come from
==31065== ERROR SUMMARY: 706490 errors from 2 contexts (suppressed: 4 from 4)
==31065==
==31065== 355 errors in context 1 of 2:
==31065== Conditional jump or move depends on uninitialised value(s)
==31065==    at 0x42D712: tree::Two_Maxc_in_one_part(Partition&) (tree.cpp:534)
==31065==    by 0x42F983: tree::get_info_from_onetree(int) (tree.cpp:374)
==31065==    by 0x42F9C4: tree::Sample_tree() (tree.cpp:322)
==31065==    by 0x42FE02: tree::SIS_tree() (tree.cpp:262)
==31065==    by 0x40306C: BSP_tree(std::vector<std::string, std::allocator<std::string> >) (main.cpp:841)
==31065==    by 0x407EEC: main (main.cpp:61)
==31065==
==31065==
==31065== 706135 errors in context 2 of 2:  表示出現錯誤了 !!!!  下面附上 trace tree 
==31065== Invalid read of size 8
==31065==    at 0x42D705: tree::Two_Maxc_in_one_part(Partition&) (tree.cpp:534)
==31065==    by 0x42F983: tree::get_info_from_onetree(int) (tree.cpp:374)
==31065==    by 0x42F9C4: tree::Sample_tree() (tree.cpp:322)
==31065==    by 0x42FE02: tree::SIS_tree() (tree.cpp:262)
==31065==    by 0x402C8B: BSP_tree(std::vector<std::string, std::allocator<std::string> >) (main.cpp:791)
==31065==    by 0x407EEC: main (main.cpp:61)
==31065==  Address 0x518de48 is 0 bytes after a block of size 8 alloc'd
==31065==    at 0x4A0666E: operator new(unsigned long) (vg_replace_malloc.c:220)
==31065==    by 0x41158C: __gnu_cxx::new_allocator<double>::allocate(unsigned long, void const*) (new_allocator.h:88)
==31065==    by 0x4115B4: std::_Vector_base<double, std::allocator<double> >::_M_allocate(unsigned long) (stl_vector.h:127)
==31065==    by 0x417386: std::vector<double, std::allocator<double> >::_M_fill_insert(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, unsigned long, double const&) (vector.tcc:357)
==31065==    by 0x417594: std::vector<double, std::allocator<double> >::insert(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, unsigned long, double const&) (stl_vector.h:658)
==31065==    by 0x417632: std::vector<double, std::allocator<double> >::resize(unsigned long, double) (stl_vector.h:426)
==31065==    by 0x42DE52: tree::Region_Create(Region_Node*, Region_Node*, Region_Node*, int) (tree.cpp:466)
==31065==    by 0x42F066: tree::rand_choose_one_nextleveltree(int) (tree.cpp:816)
==31065==    by 0x42FB2C: tree::Sample_tree() (tree.cpp:334)
==31065==    by 0x42FE02: tree::SIS_tree() (tree.cpp:262)
==31065==    by 0x402C8B: BSP_tree(std::vector<std::string, std::allocator<std::string> >) (main.cpp:791)
==31065==    by 0x407EEC: main (main.cpp:61)
==31065==
--31065--
--31065-- used_suppression:      4 dl-hack3
==31065==
==31065== ERROR SUMMARY: 706490 errors from 2 contexts (suppressed: 4 from 4)
有兩個 error 




如果  答案正確無誤  沒有問題的話
就會出現類似這樣的結果

Total Execution Time = 110.29 seconds
==31093==
==31093== HEAP SUMMARY:
==31093==     in use at exit: 2,591,288 bytes in 23,679 blocks
==31093==   total heap usage: 128,904 allocs, 105,225 frees, 15,854,055 bytes allocated
==31093==
==31093== Searching for pointers to 23,679 not-freed blocks
==31093== Checked 162,024 bytes
==31093==
==31093== LEAK SUMMARY:
==31093==    definitely lost: 912,142 bytes in 2,531 blocks
==31093==    indirectly lost: 1,679,146 bytes in 21,148 blocks
==31093==      possibly lost: 0 bytes in 0 blocks
==31093==    still reachable: 0 bytes in 0 blocks
==31093==         suppressed: 0 bytes in 0 blocks
==31093== Rerun with --leak-check=full to see details of leaked memory
==31093==
==31093== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
--31093--
--31093-- used_suppression:      4 dl-hack3
==31093==
==31093== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

error summary = 0 



2013年5月26日 星期日

如何 看 組合語言程式碼呢 ?

可以參考以下這篇 網誌的解說 很詳細


http://blog.csdn.net/qtyl1988/article/details/8495514


關鍵字

gcc –S hello.i –o hello.s 

舉例  
gcc -S main.c -o main.s


然後 less main.s  即可以看到 main.c 的 組合語言 程式碼了 ! 


2013年4月11日 星期四

如何用 command 看 環境變數


echo $PATH
會列出
自己 .bashrc 裡面的  PATH 目錄
和 root 設的  .bashrc 裡面的 PATH 目錄

2013年3月12日 星期二

df -h

df -h

檢查 目前 server 上面 可以用的 硬碟 空間



2013年3月11日 星期一

2013年3月4日 星期一

2013年3月3日 星期日

heap stack , global , memory concept


這篇文章寫得非常精闢


請參考


http://antrash.pixnet.net/blog/post/70456505-stack-vs-heap:執行時期儲存兩大要角




如何使用 gprof



how to use gprof


gcc ... .. . -g -o. ... ...


please put "-g" this term to make GCC produce the data for gprof



and



enter gprof ./run >my_profile.txt


run means the execution binary data !!!



2013年3月1日 星期五

2013年2月27日 星期三

uname –a

uname –a  

to check all the version in the linux you use 



tty

不是很懂



http://www.wretch.cc/blog/redsonoma/14021073

2013年2月26日 星期二

linux 環境變數 查詢

輸入  env

就會看到以下這些 設定



HOSTNAME=
TERM=
SHELL=/
HISTSIZE=1
SSH_CLIENT=12
SSH_TTY=/dev/pts/2
....


....



等等

2013年2月19日 星期二

ln -s

軟連結  的使用方法


假設  root/Andy/ test

要連到  rootAmber/beet




我只要在
Andy/ 下面


輸入    ln -s  root/Amber/beet  test


完了

就會在   Andy/ 下面 看到 test 連到 Amber 資料夾下的   beet

2013年2月17日 星期日

du -sh

du -sh

用來看當前 資料夾 下 佔有多少 空間



2013年2月14日 星期四

chmod 所列出來的 各種 表示 ?

crw-r--r--



Linux檔案種類與副檔名    
請見鳥歌 私房菜    
http://linux.vbird.org/linux_basic/0210filepermission.php#filepermission_dir   

2013年1月30日 星期三

雙引號 和 單引號的差別 From 鳥哥

變數內容若有空白字元可使用雙引號『"』或單引號『'』將變數內容結合起來,但
雙引號內的特殊字元如 $ 等,可以保有原本的特性,如下所示:
『var="lang is $LANG"』則『echo $var』可得『lang is en_US』
單引號內的特殊字元則僅為一般字元 (純文字),如下所示:
『var='lang is $LANG'』則『echo $var』可得『lang is $LANG』

2013年1月29日 星期二

basic usage for linux

du -sh
顯示 當前資料匣下 的   檔案 占全部的  多少 G


grep "string" * | vim -

在當前 資料匣下   去 搜尋  string  把 搜尋 到的 資料 丟到  | 的右邊
也就是 vim  其中  - 表示 std in 表示 寫進 vim 所開啟的檔案




2013年1月10日 星期四

system call 心得

System Call

you can reference it

http://swaywang.blogspot.tw/2011/10/system-call-system-call-process-oslinux.html