Re: [問題] proecess間的mutual exclusive RW
※ 引述《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寫程式...?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.74.186.158
推
03/18 10:14, , 1F
03/18 10:14, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):