My program (a console application) can run twice at the same time. I want the ability that the 2nd instance can kill the 1st instance. Both instances have been started by the command line (not one by each other).
What I have is how to kill a process with a certain PID. To get the PID of a program I found this:
http://wiki.lazarus.freepascal.org/Windows_Programming_Tips#Showing.2Ffinding_processesand improved it to return an array with multiple PIDs for 1 program, if multiple instances are running.
My problem now is, that if 2 instances are running, then I get 2 PIDs for them and do not know which is which.
So my idea is, that the 2nd instance somehow shall determine it's own PID. Then the other PID must be from instance #1 and can be killed.
How can this be done?
I use FPC 3.0.4 on Windows 7 32 bit. Thanks in advance.