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)