proecess間的mutual exclusive RW - Linux

Genevieve avatar
By Genevieve
at 2010-03-17T22:25

Table of Contents

※ 引述《WindChris (風)》之銘言:
: 請教一下
: 一篇文章
: 讓十個process去read
: 一個process一次讀一列出來
: 怎麼在shell script下保證這十個process不會讀到同樣的列
: EX:每支process的內容
: while(`cat file | wc -l`)
: head -n1 file; sed -i '1d' file
: end
: 如果在head -n1 file時發生context switch
:   有沒有可能在sed還沒把第一行刪掉時另一個process也拿到同一行?
:   
#!/usr/bin/env tcsh
while(`cat file | wc -l`)
set tmp=`echo $$%200 | bc`
mv file $tmp
if($? == 0) then
echo $tmp
head -n1 $tmp
sed -e '1d' $tmp | tee $tmp
mv $tmp file
endif
end

讀之前先把檔案改名,讀完改好搬回來
你用tcsh寫程式...?

--
Tags: Linux

All Comments

Faithe avatar
By Faithe
at 2010-03-20T03:01
Y, 跑HDL simulation.. 只能在這裡遇見你了

proecess間的mutual exclusive RW

Charlotte avatar
By Charlotte
at 2010-03-17T21:10
請教一下 一篇文章 讓十個process去read 一個process一次讀一列出來 怎麼在shell script下保證這十個process不會讀到同樣的列 EX:每支process的內容 while(`cat file | wc -l`) ...

Matrixify your linux

Liam avatar
By Liam
at 2010-03-17T20:06
這篇文章提供了一些方法,讓你的Linux看起來更酷一些、更有Matrix風 http://bbs.archlinux.org/viewtopic.php?pid=713577 我自己嘗試了一下之後的結果: http://0rz.tw/sFi9d 分別是Terminal, top, Chrome, 和p ...

請問 vmware 與 fedora的問題

Edward Lewis avatar
By Edward Lewis
at 2010-03-17T19:03
請問各位 小弟目前是使用 VMware vSphere 4 的軟體 來做 fedora 的軟體模擬與測試 但是我在灌的時候 卻發現沒有 fedora 6 的選項 但是有 REDHAT ENTERPRISE linux 2... ...

用cron執行網頁

Lauren avatar
By Lauren
at 2010-03-17T18:05
這邊有一個網頁 http://210.71.15.139:9001/nmap/index.php 主要是掃描某特定區域ip的port有開那些功能 我在crontab裡打 */5 * * * * /usr/bin/php -q /var/www/html/nmap/index.php 顯示出來的只是 ...

創立文字檔

William avatar
By William
at 2010-03-17T17:13
對linux不熟,翻了指令書Vi Vim等好像也沒看到我要的不知該從哪下手 我現在想要用指令創建一個文字檔假設為 a.txt 然後我想用指令寫入一行資料在這個文字檔內,假設 100,200,300,400,500 請問該如何下手,麻煩指點一下,謝謝 -- - ...