L
L
lochost1272019-12-06 14:02:20
PowerShell
lochost127, 2019-12-06 14:02:20

Process kill script?

Hello,
I stuck with such a thing, everything went well in the tests, but I didn’t think that the real processes for which this was done had the same names, so the formula does not work out, because when outputting Get-Process -Name someprogram I get a whole list.
I see several options myself,
Either somehow bind a certain number of pids to the program (all processes start from one executable)
If possible, then read from a certain line and make such functions as many as processes, their number will be invariably, and even if they change places, then it’s okay
or even the devil knows how to redo everything.
The head is already pretty aching, tk. I know pesh only on an intuitive level + a black belt in Google, although I haven’t found out whether it is possible to bind pid to a process in Windows =) so let it be a brown belt. Although if the kernel is closed, then something tells me that it is impossible.

$sleepseconds = 1
$numcores = 4

while($true) {
$cpu1 = (Get-Process -Name KeePass).cpu
sleep $sleepseconds
$cpu2 = (Get-Process -Name KeePass).cpu
$result=[int](($cpu2 - $cpu1)/($numcores*$sleepseconds) * 100)
if ($result -gt 75)
{
Stop-Process -Name KeePass
}
}

The goal is to kill the process that eats 75% cpu
Advise something, please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxKozlov, 2019-12-12
@MaxKozlov

You can first write the data to the hashtable
And then compare the results of the second sample with the first
and do what you want with them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question