Multi-thread processing in the batch processing program

Source: Internet
Author: User

As we all know, batch processing runs a single process step by step, but if the process execution is slow, such as ping an inaccessible IP address, it will greatly affect the execution efficiency of the batch processing program.

The following is a simple example. In Windows, you can use batch processing to perform multiple concurrent processes to achieve the effect of multiple threads.

For example, you need to ping all IP addresses from 192.168.0.1to 192.168.0.254, and output the vertex that can be pinged to log.txt.

The implementation is as follows:

Rem main program. bat, only one line of code, call checkip. bat, after testing, cpu2.6g mem1g can be concurrent about 40 Processes
For/L % I in (1, 1, 254) Do (start/min CMD/C checkip. Bat 192.168.0.% I)

 

The content of REM checkip. bat is as follows:
Ping % 1-N 1
If % errorlevel % = 0 (echo % 1 alive> log.txt) else (echo % 1 dead> log.txt)

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.