Re: [問題] proecess間的mutual exclusive RW

看板Linux作者 (偷拿程式碼的八卦)時間14年前 (2010/03/17 22:25), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《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
Y, 跑HDL simulation.. 只能在這裡遇見你了
03/18 10:14, 1F
文章代碼(AID): #1BeEPqNR (Linux)
文章代碼(AID): #1BeEPqNR (Linux)