task kill

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
joe
Posts: 35
Joined: 06 Sep 2017 07:56

task kill

#1 Post by joe » 27 Dec 2017 07:07

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: task kill

#2 Post by aGerman » 27 Dec 2017 07:39

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

joe
Posts: 35
Joined: 06 Sep 2017 07:56

Re: task kill

#3 Post by joe » 27 Dec 2017 08:28

steffen will test it tomorrow and get back to you

thank you very much for sparing me yr valuable time

highly appreciated..

joe
Posts: 35
Joined: 06 Sep 2017 07:56

Re: task kill

#4 Post by joe » 28 Dec 2017 06:43

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: task kill

#5 Post by aGerman » 28 Dec 2017 07:23

I don't know. Try to execute TASKLIST /V in order to see if the status of start.exe is changing.

Steffen

joe
Posts: 35
Joined: 06 Sep 2017 07:56

Re: task kill

#6 Post by joe » 28 Dec 2017 08:18

yes tried running tasklist /v

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: task kill

#7 Post by aGerman » 28 Dec 2017 09:46

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
Attachments
threadstatus.zip
(2.24 KiB) Downloaded 284 times

joe
Posts: 35
Joined: 06 Sep 2017 07:56

Re: task kill

#8 Post by joe » 28 Dec 2017 10:00

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

joe
Posts: 35
Joined: 06 Sep 2017 07:56

Re: task kill

#9 Post by joe » 29 Dec 2017 06:37

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: task kill

#10 Post by aGerman » 29 Dec 2017 06:52

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

joe
Posts: 35
Joined: 06 Sep 2017 07:56

Re: task kill

#11 Post by joe » 29 Dec 2017 07:02

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: task kill

#12 Post by aGerman » 29 Dec 2017 12:51

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

Post Reply