Page 1 of 1

task kill

Posted: 27 Dec 2017 07:07
by joe
hi

a request to the genius out there..

I have an application start.exe running. it crashes often and the process needs to be reset with another application restart.exe.

now my request is a script that checks if start.exe and werfault.exe is running at the same time
if so kill start.exe and wait for 5 seconds before calling restart.exe and end..

thanx in advance

Re: task kill

Posted: 27 Dec 2017 07:39
by aGerman
Try that (untested):

Code: Select all

@echo off &setlocal
:loop
for /f %%i in (
  'tasklist /nh /fo csv^|findstr /bi "\"werfault\.exe\" \"start\.exe\""^|find /c /v ""'
) do if %%i geq 2 (
  taskkill /f /im "start.exe"
  >nul timeout /t 5 /nobreak
  start "" "restart.exe"
)
>nul timeout /t 10 /nobreak
goto loop
Remove the last two lines if you don't want to observe it permanently.

Steffen

Re: task kill

Posted: 27 Dec 2017 08:28
by joe
steffen will test it tomorrow and get back to you

thank you very much for sparing me yr valuable time

highly appreciated..

Re: task kill

Posted: 28 Dec 2017 06:43
by joe
steffen hi

I got the script running but it does something unusual

it restarts the start.exe even if there is some other application crash (ie werfault.exe related to some other application say b.exe)

is there any other way to relate the werfault.exe to start.exe and then do the rest of the processes

please help me out

thanx
joe

Re: task kill

Posted: 28 Dec 2017 07:23
by aGerman
I don't know. Try to execute TASKLIST /V in order to see if the status of start.exe is changing.

Steffen

Re: task kill

Posted: 28 Dec 2017 08:18
by joe
yes tried running tasklist /v

it is not varying it shows start.exe 2376 console session 0 .

Re: task kill

Posted: 28 Dec 2017 09:46
by aGerman
It's not that easy for me because "it crashes" is not a description where I could imagine what really happens.
Attached is an executable that outputs four columns.
- process ID
- number of threads the process is running
- number of suspended threads
- process name
If you run it without an argument then it outputs a list of all processes. If you pass a process name then it outputs a list of processes that have the specified process name.

Try to find out what happens if the application "crashes". Are all threads suspended or maybe a certain number of threads? Or does it already "crash" if only one thread is suspended?

Steffen

Re: task kill

Posted: 28 Dec 2017 10:00
by joe
hi steffen

sure got your point
let me see what I can gather, may be by tomorrow I can get touch with you

thanx buddy

going to bed its 2130hrs here in india.

gn

Re: task kill

Posted: 29 Dec 2017 06:37
by joe
hi steffen

checked the status in tasklist

found this

normal: start.exe pid 5040 threads 2 suspended 0

crashed: start.exe pid 5040 threads 2 suspended 1

this was checked in normal operation and when the app crashed..

can you figure out..
thanx

joe

Re: task kill

Posted: 29 Dec 2017 06:52
by aGerman
I'm not aware of any command that is able to determine the suspended status of process threads. Just keep using my tool.

Code: Select all

@echo off &setlocal
:loop
for /f "tokens=1-3" %%i in ('threadstatus "start.exe"') do if %%k neq 0 (
  taskkill /f /pid %%i
  >nul timeout /t 5 /nobreak
  start "" "restart.exe"
)
>nul timeout /t 10 /nobreak
goto loop
In case you're interested in the C source I could provide it.

Steffen

Re: task kill

Posted: 29 Dec 2017 07:02
by joe
steffen
to be very honest I like the way you guys tend to help other who are
non programmer by spending your valuable time.

will try the code with your app tomorrow and get back to you with the final results

thanx buddy once again..
joe

Re: task kill

Posted: 29 Dec 2017 12:51
by aGerman
You're only fighting against symptoms. Let the developers of the software know of your problems. As well as you, they should be interested in a stable application without frequent crashes.

Steffen