As a database DBA for Linux systems operations or Linux, there are many times when you need to write scripts to help us achieve some of the requirements, and if some content within the script can try parallel processing, it will greatly improve the speed of the work.
Not much to say, on the script
Let's start with an example of sequential execution:
[email protected] test]# cat test.sh
#!/bin/bash
For i in {1..5};d o
Sleep 1; echo "Hello"
Done
[[Email protected] test]# time SH test.sh
Hello
Hello
Hello
Hello
Hello
Real0m5.016s
User0m0.001s
SYS0m0.001s
The time spent here is 5.016s.
---------------------------------------------------------
A simple improvement
---------------------------------------------------------
[email protected] test]# cat test.sh
#!/bin/bash
For i in {1..5};d o
{
Sleep 1; echo "Hello"
}&
Done
Wait #等待上面的程序结束
[[Email protected] test]# time SH test.sh
Hello
Hello
Hello
Hello
Hello
Real0m1.008s
User0m0.004s
SYS0m0.005s
It takes 1.008 seconds to
This article from the "Linux operation and maintenance of the Road" blog, reproduced please contact the author!