發表文章

bash:偵測程式pid消失後自動執行

測試小程式 當aplay pid消失後,程式會偵測到pid消失 然後再執行 pidof可以偵測程式的pid 無限while loop也可以這麼寫 #!/bin/sh aplay -D plughw:1 /mnt/shield/song.wav -v & arecord -D plughw:1 -r 48000 -c 2 -f s16_le  /mnt/shield/test.wav & while : do     pid1=$(pidof aplay)     pid2=$(pidof arecord)     echo aplay=$pid1 arecord=$pid2     if [ -z $pid1 ]; then           kill -9 $pid2         rm -fr /mnt/shield/test.wav         aplay -D plughw:1 /mnt/shield/song.wav -v &         arecord -D plughw:1 -r 48000 -c 2 -f s16_le  /mnt/shield/test.wav &     else         sleep 1     fi       done

lighttpd + fcgi + C language to do file upload & download

最近使用lighttpd當作http server 搭配fcgi來寫檔案上傳跟下載功能 比較討厭的是,html我完全不會寫啊~~~ 還有fcgi的範例也非常地缺乏 其他語言有很多相關API可以使用 C語言的話就得要自己寫 這邊就講一下是怎樣實現的 首先是下載的部分: 一開始得先要有個html給人下載 可以使用下面的範例             printf("Content-type: text/html\r\n"             printf("<hr />");             printf("<a href='/download/?message'>message</a>");             printf("<hr />"); 當有人點選"message"後會跳轉另一個網址 之後可以利用queryString = getenv("QUERY_STRING"); 去判別server跳轉進來的下載網址 此時需要提供另一個html告訴browser要下載東西             printf("Content-type:   application/octet-stream\r\n");                       printf("Content-Transfer-Encoding: Binary\r\n");             printf("Content-Length: %d\r\n", size);                     ...

在shell script執行某程式之後判斷是否成功

sh /etc/init.d/rcS if [ $? -ne 0 ]; then     /sbin/check 1; fi $?  is the exit status of the most recently-executed command; by convention, 0 means success and anything else indicates failure.

怎樣刪除文件的前N行?

在linux 下,删除文件file中的第1到第N行:  sed -i    '1,N d'    file PS: 上面是对原文件file做删除操作。 sed   '1,N d'    file  > newfile PS: 上面是保持原文件file不变,做删除操作后将结果另存为newfile。

buildroot可以先make想要的某些package

最近正在玩buildroot 打算用buildroot解決一些需要用到的pakcage 看看是否可以解決大部分相依性的問題 但發覺buildroot裡很多package會使用到libtool裡的aclocal.m4以及m4 folder 會出現version check error 原因是使用了舊的aclocal.m4及m4檔案夾內的script 解決方法是buildroot可以單獨編譯某個package 因此可以先make libtool後再執行make 這樣就可以將aclocal.m4等的檔案先編譯出來給其他package用

bash script 範例: 陣列中取字串

#!bin/bash modules=( "ipnc/release;ti814x" "osd/release;Venus" ) function test() {     for module in ${modules[@]}; do         mary=(${module//;/ })         echo ${mary[0]}         echo ${mary[1]}           done } test 執行結果: ipnc/release ti814x osd/release Venus 主要是在modules[@]的@是幹嘛的 以及mary=(${module//;/ })為何可以將字串分成兩個 目前還是有點不懂

UVC 1.5於linux gadget實作(2)

做了一陣子UVC1.5在Windows 8.1上的開發 感覺Microsoft似乎沒有把UVC1.5真的給實作完成 目前號稱有支援UVC1.5的Logitech connect cam 拿來用Cam Diagnostics來分析 看到的都是support UVC1.0...Orz... 實際上Logitech在Windows 8.1上 在Composite Device與Image Device各加了一個自己的driver 通通移除掉後發現變成只支援YUV&MJPG的裝置 原先的H.264 pin也消失 我猜driver一部分功能就是將configuration分成兩個來設定 UVC 1.5 spec提到的multiple configurations,MS所提供的host軟體並沒有能力可以選擇 Logitech應該是利用driver去解決UVC1.1與UVC1.5兩個streaming interface個數不同的問題 另外,從抓到的USB packet看來 Logitech是真的傳送UVC 1.5的packet格式沒錯 但是Cam Diagostics卻認為Logitech connect是UVC 1.0的裝置 只能猜測driver是否扮演了translator的角色 將device傳過來的UVC 1.5 packet翻譯成UVC 1.0(或是UVC 1.1)的packet格式後 再傳給host端去使用 而host端送過來的UVC 1.1 packet又翻譯成UVC 1.5的格式再送過去給device 這比較能解釋為何Logitech捨棄通用的UVC spec不用,改用自己的driver 所以要自己寫driver做這樣的事嗎??? Orz...