I think I have found a problem in the way that Poco terminates processes. The issue is in the Process class. The launch method returns a process handle which can be used to wait for process completion. So far, so good. However, the kill method takes a pid, not a process handle. This is asymmetric and causes a problem that I will describe below:
If a poco program launches a process which is then killed by someone else and then another process is started and the pid gets reused and then poco tries to kill the process it launched, poco will try to kill the wrong process. This is a serious problem. I presume there is a similar issue in the requestTermination method which also takes a pid. In my opinion pids should not be used for termination due to pid reuse.
The issue can be mitigated on UNIX which has proper process management. If anyone else kills the poco child, the parent will receive SIGCHLD so it can update its records. It will then know that the pid it has is now out of date. This is still extra work it has to do to guard against pid reuse but at least it can be done. Not so on Windoze. On Windoze the parent and child do not have a close association, no SIGCHLD or equivalent gets delivered to the parent so there is no way that the parent can know that the pid it has for its child is still valid.
On Windoze one can keep a process handle open for a child that the parent has launched. In Process_WIN32.cpp in the killImpl method a fresh process handle is opened given the pid. I think it would be better if Poco used the process handle that was returned from the launch method. I know this will involve interface changes but I reckon the interface itself is broken since it is not reliable to terminate by pid on Windoze.
I see from the code that ProcessHandle encapsulates the pid. This is good. I reckon this means the change won't be too difficult. This should fix the problem for Windoze. UNIX can still kill by pid, in fact, it has to, so that still leaves the issue open for UNIX. For completeness Poco may have to handle SIGCHLD and invalidate the ProcessHandle. I am not sure about how this would work exactly.
I welcome comments on these issues and design thoughts.
This is not a merely theoretical problem. I have worked on a general purpose program launcher that kept track of its processes using pids and it sometimes went wrong because of this.
Regards,
Andrew Marlow





