Semaphore Usage List (ipcs equivilent?)

by RolandOfGilead at 2012-12-14 20:21:03

Hello,
I’m a Linux Admin that is inheriting a number of Windows servers so please forgive my ignorance. Is there a PowerSheel cmdlet that will let me look at semaphore usage for a system? I have a piece of software that was notorious for not cleaning up it’s semaphores when we bounced it, and I want to see if that will be the same problem on the Windows platform.

In Linux we use “ipcs” which allows use to both view and clean up semaphores, I was just looking for a PowerShell equivalent.

Thanks!
by MattG at 2012-12-15 06:58:46
The short answer is no. The only Windows tool out there that I’m aware of that will list the semaphores for a process is handle.exe (part of the Sysinternals package). To list all semaphores across all processes, you could run the following from an elevated command prompt:
handle -a | FIND "Semaphore"
Of course, you can always use PowerShell to parse command-line output. For example, the following code will output the handles of every semaphore on the system in sorted (hex dword) order:
$SemaphoreRegex = [Regex] “^\s+(?<Handle>[A-F0-9]+):\s+Semaphore”
$Output = handle -a
$Matches = $Output | ForEach-Object { $SemaphoreRegex.Matches($) }
$Handles = $Matches | ForEach-Object { $
.Groups[‘Handle’].Value.PadLeft(8, ‘0’) }
$Handles | Sort-Object -Unique
I’m sure the regex code can be improved upon so someone feel free to chime in.

Anyway, I hope this helps.