In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to write Shell scripts to simulate multi-threading function". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how to write Shell scripts to simulate multi-threading function" together!
The code is as follows:
#!/ bin/bash
function pinghost {
ping $1 -c 1 -w 10 |grep rtt|cut -d "/" -f6
}
tmp_fifo file ="/tmp/$.fifo" #The ID number of the current process the script runs as the file name
mkfifo $tmp_fifo #Create a random fifo pipe file
exec 6 $tmp_fifo file #definition file descriptor 6 points to the fifo pipeline file
rm $tmp_fifofile
thread=10
for ((i=0;i&6
while read domain
do
read -u6 #reads line from file descriptor 6 (actually pointing to fifo pipe)
{
pinghost ${domain}; #Execute pinghost function
echo >&6 #Write a blank line to the fifo pipe file again.
}& #Put it in the background
done&- #delete file descriptor 6
exit 0
Description:{} This part of the statement is put into the background as a child process execution, this part is almost completed at the same time, when fifo 10 empty lines after reading while loop
Continue to wait for fifo data to be read in read. After 10 sub-processes in the background, queue up to fifo to enter blank lines in order, so that fifo has data again. The for statement continues to execute.
Thank you for reading, the above is "how to write Shell scripts to simulate multi-threading function" content, after the study of this article, I believe we have a deeper understanding of how to write Shell scripts to simulate multi-threading function, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.