Keeping a list of processes
Here is my scenario: I have a function which performs operations on other processes. It performs an operation on a given process, then performs some more operations, then undoes the first operation. I would like to do this operation only once on each process.
This leads to my question: How do I keep a list of processes to开发者_如何学Go identify which ones have already been operated on and which have not? I was thinking of storing process ids, but they are recyclable. Process handles are also recyclable.
If you hold on to the handle, the process object cannot be destroyed and the PID will not be re-used.
Once the process has quit, which you can find out by Waiting on the handle, you can close the handle. Only then will the PID be re-used, but since you know the process has quit you can be sure that any recurrence is a different process.
Nevermind, it is acceptable to use process time as a means of identifying processes for my purpose. If anyone would like to know how, see http://msdn.microsoft.com/en-us/library/ms683223
See this question, and the links there in my answer. One of them discusses GetProcessTimes, which will give you the time the process started.
精彩评论