Linux shell for multi-process

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.