Note that there are some explanatory texts on larger screens.

plurals
  1. POData in linux FIFO seems lost
    primarykey
    data
    text
    <p>I have a bash script which wants to do some work in parallel, I did this by putting each job in an subshell which is run in the background. While the number of jobs running simultaneously should under some limit, I achieve this by first put some lines in a FIFO, then just before forking the subshell, the parent script is required to read a line from this FIFO. Only after it gets a line can it fork the subshell. Up to now, everything works fine. But when I tried to read a line from the FIFO in the subshell, it seems that only one subshell can get a line, even if there are apparently more lines in the FIFO. So I wonder why other subshell(s) cannot read a line even when there are more lines in the FIFO. <br /> My testing code looks something like this: <br /></p> <pre><code> #!/bin/sh fifo_path="/tmp/fy_u_test2.fifo" mkfifo $fifo_path #open fifo for r/w at fd 6 exec 6&lt;&gt; $fifo_path process_num=5 #put $process_num lines in the FIFO for ((i=0; i&lt;${process_num}; i++)); do echo "$i" done >&6 delay_some(){ local index="$1" echo "This is what u can see. $index \n" sleep 20; } #In each iteration, try to read 2 lines from FIFO, one from this shell, #the other from the subshell for i in 1 2 do date >>/tmp/fy_date #If a line can be read from FIFO, run a subshell in bk, otherwise, block. read -u6 echo " $$ Read --- $REPLY --- from 6 \n" >> /tmp/fy_date { delay_some $i #Try to read a line from FIFO, __ only one subshell succeeds the following line. __ read -u6 echo " $$ This is in child # $i, read --- $REPLY --- from 6 \n" >> /tmp/fy_date } & done </code></pre> <p><br /> And the output file /tmp/fy_date has content of: <br /></p> <pre><code> Mon Apr 26 16:02:18 CST 2010 32561 Read --- 0 --- from 6 \n Mon Apr 26 16:02:18 CST 2010 32561 Read --- 1 --- from 6 \n 32561 This is in child # 1, read --- 2 --- from 6 \n </code></pre> <p>There, I expect a line like this:</p> <pre><code> 32561 This is in child # 2, read --- 3 --- from 6 \n </code></pre> <p>But it never appears, and the child #2 process is blocked there until I issue:<br /> echo something > /tmp/fy_u_test2.fifo</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload