2015年9月4日 星期五

Android SDK Issue @ Ubuntu 14.04 64-bit

在 Ubuntu 14.04 64 bit 的版本中,執行 Android Emulator 時,如果出現
[YOUR_ANDROID_SDK_ROOT]/tools/emulator: cannot execute binary file
或是
[YOUR_ANDROID_SDK_ROOT]/tools/emulator: No such file or directory
這可能是代表你在 64 bit 的 OS,但缺少 32 bit 的 Library,解決方法如下
在 Terminal 裝一些套件,指令是
sudo apt-get install libc6-i386 lib32stdc++6 lib32gcc1 lib32ncurses5 lib32z1 lib32bz2-1.0

補充,利用 Eclispe 時,會出現
"Failed to start emulator: Cannot run program "/home/christopher/Desktop/android-sdk-linux_86//tools/emulator": java.io.IOException: error=2, No such file or directory".
也可用這種方式解決。

2015年8月27日 星期四

編譯 Ubuntu 14.04 Kernel

2016.2.21 新增 grub 手動更新的部分

最近剛好在研究 Ubuntu 14.04 Kernel 的部分,順便 Trace 一下 Kernel Source Code 的部分。不過,我試過許多的方法,包含直接至 Kernel.org 下載所對應的 Kernel 版本 (可以參考 uname -r) 然後手動下 make 編譯,或是至 apt-get source 下載 Ubuntu Kernel Source Code 下來編譯,但這幾種方法總是不如預期,不是插入的 printk 訊息沒有反應,要不然就是方法很繁瑣,繁瑣就怕不夠細心而出錯。

2015年8月14日 星期五

Grub GUI

有的時候,我們總是會遇到更新 Kernel、安裝新 Kernel,甚至是手動刪除 Kernel,在做這些動作時,會需要做更新 Grub 的動作。又或者你想要對 Grub 進行調整又不想要使用 CLI 的方式,那你倒是可以試看看 GUI 的方法來進行設定。

這邊推薦一套名叫 Grub Customizer,他的安裝方法如下
在 Terminal 鍵入
sudo add-apt-repository ppa:danielrichter2007/grub-customizer

sudo apt-get update

sudo apt-get install grub-customizer
之後再 Terminal 鍵入 grub-customizer,即可使用這個軟體。

出處於 http://ubuntuhandbook.org/index.php/2014/04/install-grub-customizer-ubuntu-1404/
已在 Ubuntu 14.04.1 測試 OK !

2015年8月13日 星期四

The Version of Linux Source Code

今天在編譯 Linux Source Code 時,意外思考到我究竟該如何取得目前的 Linux 版本,由於我是從 github 取得 Source Code 的,所以可以利用 checkout 來切換不同的版本。

方法有兩個,第一:

在 Linux Source Code 根目錄下,鍵入
make kernelversion
就可以得到目前的版本

第二:


一樣在根目錄下,觀察 Makefile,第 1 ~ 3 行會有
VERSION = 3
PATCHLEVEL = 13
SUBLEVEL = 0
也可以得知目前的版本是 3.13.0

資料來源: https://stackoverflow.com/questions/12151694/how-to-find-the-version-of-a-linux-kernel-source-tree/12151781#12151781?s=1167b1dbf51a46a68d2fa097b723bd79

2015年7月31日 星期五

Fedora 14 YUM 失效問題

每一版的 Linux 都具有所謂的支援年限,除非是 LTS 的版本,支援的年限才會比較長。

最近剛灌 Fedora 14,和許多舊版的 Linux 一樣都會遇到超過支援年限的問題,像這種超過年限的 YUM 或 APT,其實一般來說 repo 都會死掉或是移到其他地方去,所以在這邊要說明 Fedora 14 透過下列步驟的修改,應該也能夠維持 YUM 的 repo (P.S. 其他的版本可以參考下列網址看版本內容還在不在 http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/)


  1. 修改 /etc/yum.repos.d/fedora.repo 和 /etc/yum.repos.d/fedora-updates.repo
    將 mirrorlist 全部註解掉 (前面加上 # ),應該會有 6 個
  2. 修改 /etc/yum.repos.d/fedora.repo 和 /etc/yum.repos.d/fedora-updates.repo
    將 baseurl 前面的註解去掉 (前面去掉 # ),應該會有 6 個
    之後將 baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/ 修改為 baseurl=http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/$releasever/Everything/$basearch/
    $ 的部分,代表變數,指的是你現在 OS 的版本與架構,一樣應該也會有六個要改
    這邊一樣要注意一下,雖然有六個要改,其實 $basearch 後面各自會接不同的東西,例如 os debug SRPMS 等等,但這不是重點,你應該有發現其實就只是改上面紅色字體的部分而已)
  3. 執行 sudo yum update
P.S. 有時候不見得是原來 repo 死掉,而是自己的網路沒有通,為了避免烏龍,可以先 ping 看看 google 或其他之類的網站 (IP 和 DNS 要記得設定)

這是如果網路不通,或 repo 死掉時,執行 sudo yum install XXX 以及 sudo yum update 會出現的錯誤訊息
Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again

2015年7月30日 星期四

htop 編譯錯誤

1. htop 在執行 autogen.sh 時,出現
./autogen.sh: 3: ./autogen.sh: aclocal: not found
./autogen.sh: 4: ./autogen.sh: autoconf: not found
./autogen.sh: 5: ./autogen.sh: autoheader: not found
./autogen.sh: 6: ./autogen.sh: libtoolize: not found
./autogen.sh: 7: ./autogen.sh: automake: not found
解決辦法:
sudo apt-get install automake autoconf libtool

2. htop 在 configure 時出現
configure: error: missing libraries:  libncurses
解決辦法:
sudo apt-get install libncurses5-dev libncursesw5

3. htop 在 configure 時出現
configure: error: You may want to use --disable-unicode or install libncursesw.
解決辦法:
sudo apt-get install libncursesw5-dev libncursesw5
然後再重新 configure 一次

2015年7月5日 星期日

Simple pthread example on Linux

想要在 Linux 下練習 multi-thread 程式,可以從這個簡單的範例開始,首先可以先參考幾個 pthread API. 

pthread_create 是你第一個要用的 pthread API,下列是我們的範例程式
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

/*
 * 在 thread_1 裡面執行一個無窮迴圈,並不斷印出 thread_1 訊息
 * 為了避免不斷的 loop,我們用 sleep function 在每次迴圈停 1 秒
 */
void *thread_1(void *argv) {
 while(1) {
  sleep(1);
  printf("I am thread_1\n");
 }
}

/*
 * 基本上和 thread_2 相同,但時間停留 2 秒
 */
void *thread_2(void *argv) {
 while (1) {
  sleep(2);
  printf("I am thread_2\n");
 }
}

int main() {
 pthread_t t1, t2; // 先宣告兩個 pthread 的變數

 // 之後開始建立並執行這兩個 thread,這兩個 thread 分別執行上面 thread_1, thread_2 這兩個 function
 pthread_create(&t1, NULL, &thread_1, NULL);
 pthread_create(&t2, NULL, &thread_2, NULL);

 // 而我們自己的 main thread 也同樣執行無窮迴圈,每次停留三秒
 while (1) {
  sleep(3);
  printf("I am main thread\n");
 }

 return 0;
}

結果在這邊
> ./pthread-example 
I am thread_1
I am thread_2
I am thread_1
I am main thread
I am thread_1
I am thread_1
I am thread_2
I am thread_1
I am main thread
I am thread_2
I am thread_1
I am thread_1
I am thread_2
I am thread_1
I am main thread
I am thread_1
I am thread_2
I am thread_1

我們可以注意到,在撰寫 multi-thread 程式時,需要改變以往 Sequential 的思維,實際上在 multi-thread 的觀念中,所有的 thread 都是同時在執行的 (實際上可能不是啦,但我們在比較高階的角度來看,就當作是同時在進行)。
另外,可以發現雖然 thread_1 停一秒,thread_2 停兩秒,main thread 停三秒,但實際在印出來時還是有先後順序之分,而且每一次都不太固定,這也是 thread 有時候比較抽象的地方。

最後,main thread 是不能停止的,這也是為什麼我們要在 main function 也插入無窮迴圈,因為 main thread 如果直接 return 停止,連帶的會把 thread_1 和 thread_2 一起停止。


thread_create manual: http://man7.org/linux/man-pages/man3/pthread_create.3.html
source code on github: https://github.com/jackzzjack/blogger.git

可以下載 source code 並直接執行 make simple,則會編譯出 pthread-example,之後直接 ./pthread-example 直行即可。