CopyCodeThe Code is as follows :#! /Bin/bash
Send_thread_num = 13
Tmp_domainofile = "/tmp/$. FIFO" # ID of the current process running the script as the file name
Mkfifo "$ tmp_domainofile" # create a random FIFO pipeline File
Exec 6 <> "$ tmp_domainofile" # define file descriptor 6 to point to this FIFO pipeline File
Rm $ tmp_kerberofile
For (I = 0; I <$ send_thread_num; I ++); do
Echo # For Loop write 13 blank lines to the FIFO pipeline File
Done> & 6
For I in 'seq 100'; do #100 for loop start
Read-U6 # Read rows from file descriptor 6 (actually pointing to the FIFO pipeline)
{
Echo $ I # print I
Sleep 3 # Pause for 3 seconds
Echo> & 6 # Write an empty row to the FIFO pipeline file again.
}&
# {} This part of the statement is put into the background for execution as a sub-process, so you do not have to wait 3 seconds each time to execute
# Next, this part of ECHO $ I is almost completed at the same time. When 13 blank rows in the first-in-first-out are read, the For Loop
# Continue to wait for the read to read the FIFO data. When the 13 sub-processes in the background wait 3 seconds
# Enter blank rows in the queue to the FIFO, so that data in the FIFO is available, and the for statement continues to be executed.
PID = $! # Print the ID of the last sub-process that enters the background
Echo $ PID
Done
Wait
Exec 6> &-# delete file descriptor 6
Exit 0