Windows is long-formed by the UI. However, the real powerful tool is still a command line tool.
Today, we will introduce a scheme to monitor whether a process works normally using the Windows command line tool tasklist, findstr, and start.
Tasklist: lists all processes currently executed by the system;
Findtr: Uses regular expressions to search for specified content in a string or text file;
Start: Start a target in a mode specified by some parameters
At the same time, the channel in the command line is also used. | this is a supper channel.
The solution is as follows:
Assume there is a service process called botserver, which allows a short period of unavailability, for example, 5 minutes;
The botserver automatically exits when an exception occurs;
To ensure that this process can continuously provide services, we create a bat batch processing file and add it to the system'sScheduled tasks, Set the execution cycle to 3 minutes;
In the BAT file, write the following content:
Tasklist | findstr/I botserver.exe
If errorlevel 1 start/B botserver.exe
Tasklist | findstr/I botserver.exeIs in the system process list, find botserver.exe
If errorlevel 1 start/B botserver.exeIf the search above does not match, start botserver.exe