N
N
NeoLight32020-09-11 18:27:52
cmd/bat
NeoLight3, 2020-09-11 18:27:52

When you try to kill the process, it hangs stupidly, but does not die. What to do?

There is a server Unturned.exe. Which can sometimes freeze, for many reasons.
To do this, I found a script that automatically, when a freeze is detected, restarts the process, that is, it kills the hung one and starts a new one.
BAT code:

@ECHO OFF
:CHECK
TASKLIST /NH /FI "IMAGENAME EQ Unturned.exe" /FI "STATUS EQ RUNNING" | FIND /I ":" > NUL
IF %ERRORLEVEL%==0 GOTO NOT_RUNNING
TIMEOUT /T 10 /NOBREAK
GOTO CHECK
:NOT_RUNNING
TASKKILL /IM Unturned.exe
START Unturned.exe -pvp -port:25444 -normal -pei -players:32 -sv -nographics -nosync
TIMEOUT /T 10 /NOBREAK
GOTO CHECK


The problem is that when you try to kill a hung process, it just hangs, and you can actually kill it only by manually clicking on the cross many times.
5f5b975625a8a849721750.png

Is it possible to really kill this hung and problematic process with the help of a bat code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitsliputsli, 2020-09-11
@NeoLight3

TASKKILL has the F key - forced termination.

H
HemulGM, 2020-09-11
@HemulGM

This happens because the termination signal is given to the main thread of the application, and this main thread at this time may be dependent on another one, which is just not responding. Those. the application would be happy to close, but the signal has not yet reached the main application thread.
You can monitor this through the "Resource Monitor", where you can see the chain of expectations.
5f5b9d81004ad120482408.png
Accordingly, having completed the expected thread, the required one will also end.
My "answer" is purely for reference. Partial solution posted above.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question