Impossible to escape?

Ok so I have Project25 and Project26 below. Project25 endlessly checks to see if Project26 is open and if its not it starts Project26 and Project26 does the same thing for Project25. So does that make it impossible to close those programs? because whenever one is closed it gets started again by the other.

Also if someone opened up the windows command prompt and typed

taskkill /IM Project25.exe
taskkill /IM Project26.exe

Then it would be a race correct?


Project25

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <Windows.h> 
#include <WinUser.h>
#include <iostream>

using namespace std; 


HWND stealth;



int main() {

	system("title Project25");
	stealth = FindWindow(NULL, TEXT("Project26"));

	while (stealth != 0)  
	{
		stealth = FindWindow(NULL, TEXT("Project26"));

	}
	
	cout << "Project26 has been exited";
	system("start Project26.exe");
	main(); 
	 
	}



Project26

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <Windows.h> 
#include <WinUser.h>
#include <iostream>

using namespace std;


HWND stealth;



int main() {

	system("title Project26");
	stealth = FindWindow(NULL, TEXT("Project25"));

	while (stealth != 0)
	{
		stealth = FindWindow(NULL, TEXT("Project25"));

	}

	cout << "Project25 has been exited";
	system("start Project25.exe");
	main();

}
Last edited on
Well I sort of answered my own question here, I tested this out and it appears (to my knowledge) to be impossible to escape. I had to restart my computer but if you place these 2 programs in the start up folder then you are screwed aren't you?
It does present a classical race condition.
http://www.csd.uwo.ca/~magi/personal/humour/Computer_Folklore/Robin%20Hood%20And%20Friar%20Tuck.html

Except you can kill two processes at once with taskkill.
"Except you can kill two processes at once with taskkill. "
good point, is there any way that I can make my program faster than taskkill so that even if I type

taskkill /IM project25.exe /IM project26.exe

Project26 will notice that Project25 has exited before taskkill can kill Project26 ?
MS is aware of the Robin Hood / Friar Tuck problem, so I doubt it.

(But I could be wrong. If I were, you'd have to have a hook to watch for process termination messages.)
Topic archived. No new replies allowed.