proecess間的mutual exclusive RW - Linux
By Genevieve
at 2010-03-17T22:25
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寫程式...?
--
: 請教一下
: 一篇文章
: 讓十個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
By Faithe
at 2010-03-20T03:01
at 2010-03-20T03:01
Related Posts
proecess間的mutual exclusive RW
By Charlotte
at 2010-03-17T21:10
at 2010-03-17T21:10
Matrixify your linux
By Liam
at 2010-03-17T20:06
at 2010-03-17T20:06
請問 vmware 與 fedora的問題
By Edward Lewis
at 2010-03-17T19:03
at 2010-03-17T19:03
用cron執行網頁
By Lauren
at 2010-03-17T18:05
at 2010-03-17T18:05
創立文字檔
By William
at 2010-03-17T17:13
at 2010-03-17T17:13