Copy Code code as follows:
#!/bin/bash
function Pinghost {
Ping $1-c 1-w |grep rtt|cut-d "/"-f6
}
Tmp_fifofile= "/tmp/$.fifo" # script runs the current process ID number as filename
Mkfifo $tmp _fifofile # Create a new random FIFO pipeline file
exec 6<> $tmp _fifofile # definition file Descriptor 6 point to this FIFO pipe file
RM $tmp _fifofile
thread=10
For ((i=0;i< $thread i++));d O # for Loop writes 10 blank lines to the FIFO pipe file
Echo
Done >&6
While read domain
Todo
Read-u6 # Reads rows from the file descriptor 6 (actually pointing to the FIFO pipeline)
{
Pinghost ${domain}; # Execute Pinghost function
Echo >&6 # Again writes a blank line to the FIFO pipeline file.
}& # put in the background to perform
DoneWait #因为之前的进程都是后台执行, so it is only after waiting that all the processes have been executed that the entire script runs out.
EXEC 6>&-#删除文件描述符6
Exit 0
Description: {} This part of the statement is put into the background as a child process execution, this part is almost simultaneous completion, when 10 empty lines in the FIFO read the while loop
Continue waiting for read in the FIFO data, when the background of the 10 sub processes, in order to queue to FIFO input blank line, so that the FIFO data, for statements continue to execute.