Linux multi-threaded programming has the advantages of improving application response and making multi-cpu system more effective. The following small series will explain the multi-thread programming process through the shell multi-thread programming example under Linux. Let's go.
#! /bin/bash
#———————————————————&mdash ;———————–
# This example illustrates a technique for simulating multithreading with the wait and read commands
# this Techniques are often used for multi-host checks, such as ssh login, ping, etc. This single process is slow and does not consume CPU.
# Also illustrates multi-threaded control
#— & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; & mdash; —–
function a_sub
# Define a function here as a thread (child process)
sleep 3 #thread The effect is sleep 3s
}
tmp_fifofile=“/tmp/$.fifo” mkfifo $tmp_fifofile # Create a new fifo type file
Exec 6 ""$tmp_fifofile # Point fd6 to fifo type
rm $tmp_fifofile thread=15 # Define the number of threads here
for
((i=0;i "$thread;i++));do echo
done 》&6 # In fact, put $thread carriage return in fd6
for
( (i=0;i "50;i++));do #50 cycles, can be understood as 50 hosts, or other
read -u6 # A read -u6 command is executed once, from fd6 Subtract a carriage return and then execute it downwards.
# When there is no carriage return in fd6, it stops here, thus achieving thread number control
{ # here The process starts executing and is placed in the background
a_sub &&
{ # Here can be used to determine the logic of the child process
echo “a_sub is finished”
}
Every user who has certain mastery of Linux system must start to learn some common commands of Linux
The Linux system additional permissions mentioned here refer to SET bit permissions
In the Linux system, sometimes the root user accidentally deletes the root user bec
Linux system crond is mainly used to set the instructions to be executed periodically, such as regul
Linux mydumper error libmysqlclient_16 not defined how to do?
Linux how to use the last command
Does Linux use the ODBC method or the DBI way to install the R language extension package?
Ubuntu install libgdiplus error how to do?
Which is better for Linux compression tools gzip and pigz?
The specific steps of hard disk partitioning under Linux
Linux how to install and use NeoBundle
The most detailed Linux compression decompression command
What should I do if Linux vi is stuck?
What should I do if Xmanager fails to connect after the Solaris system is installed?
Vista can't get online, let it fix the connection itself
Steps for Linux to build a static link library
How to disable the Win10 preview version of the automatic update driver?
Cannot open Bluetooth device under Win7
How to delete restore points in Windows7?
Transfer "big chunks" simply transfer large files
Windows 7 RC Common Software Compatibility Test Report (Compression and Decompression)
Windows2008 system default service which can be closed
Seven measures to prevent hacking under XP system
How to open the exit mode of the win7 system to make the download more energy efficient