Answer the question
In order to leave comments, you need to log in
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
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question