proecess間的mutual exclusive RW - Linux

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寫程式...?

--

All Comments

Faithe avatarFaithe2010-03-20
Y, 跑HDL simulation.. 只能在這裡遇見你了