In fact, I had a similar problem with my "hung job" finder on my Navy Personnel system. The users logged in and got process ID's (PIDs, in OpenVMS-speak). But if they talked to the DB server, they might open multiple connections such as looping through a set of parent records and sub-iterating through children of that parent record. I had to test not only the VMS process status, but also the DB server's linked processes, which I could link via data in the DB server task table, such as the "remote ID" for each task. So it was a matter of building a parent/child structure to determine the overall status of the action as a whole across the two machines. It might sound a bit complicated, but the end result of killing truly idle processes saved us money twice.
Once, because in the early days we had dial-up connections over modems and long-distance charges started building due to hung jobs that should have, but didn't, get hung up properly. We settled on a rule to kill idle jobs if their resource usage statistics hadn't changed over a 15 minute interval. That one rule saved the Navy 64k$/month.
The other time was closer to the original question. We had a licensed interfacing kit that talked between our programs and ORACLE. It was an equivalent to the Access forms-and-reports GUI, though not quite as easily built as what Access did. I would have diverted the project to an Access FE, but the manager was suspected of a "sweetheart deal" with the interfacing software. But the point at hand was that the license fees were based on user count and had to be renewed each year based on usage levels. My hung job checker detected that 60% of our license consumption on a given day was idle jobs, abandoned by their users. Trimming idle jobs like that saved the Navy about 75k$/year. By that time, though , VMS had gained an "installed bulk license" checker and we COULD establish a rule that said, essentially as an error message, "Insufficient licenses, try again later."
You can do a Google search for "On Windows, track licenses in use" and get at least half-a-dozen suggestions. Things like SAM (Software Asset Management) and VAMT (Volume Activation Management Tool) may be helpful. There are other ways such as associated a system file lock with a particular utility and write some lock-checking code that uses an API to count "interest" locks and cause the app to terminate if more locks are attempted than are allowed.