proecess間的mutual exclusive RW - Linux

Table of Contents



請教一下

一篇文章

讓十個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也拿到同一行?



  


--

All Comments

Sierra Rose avatarSierra Rose2010-03-22
像是是以指令"ipcs"來使用semaphore來管理process呢?
Ursula avatarUrsula2010-03-25
多謝!! 另外找到一個 lockfile 好像蠻方便的