If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Rate Thread | Display Modes |
#1
|
|||
|
|||
Taskkill question
Does Taskkill do a graceful shutdown or brute force?
|
Ads |
#2
|
|||
|
|||
Taskkill question
T wrote in :
Does Taskkill do a graceful shutdown or brute force? I am assuming you are refering to the task kill that is part of Task Manager. If so, the sends a 'die' signal to the task, which is supposed to have an overriding section of code that will terminate the task as soon as possible. Usually it works, but I have had a few times when a task was apparently really fubarred where it didn't work. |
#3
|
|||
|
|||
Taskkill question
On 7/5/19 7:06 PM, lonelydad wrote:
T wrote in : Does Taskkill do a graceful shutdown or brute force? I am assuming you are refering to the task kill that is part of Task Manager. If so, the sends a 'die' signal to the task, which is supposed to have an overriding section of code that will terminate the task as soon as possible. Usually it works, but I have had a few times when a task was apparently really fubarred where it didn't work. I am talking about the command line: Taskkill /IM chrome.exe /F I wonder if it also has a "die" function. "/F" may be "force", in which case Taskkill /IM chrome.exe wait five seconds Taskkill /IM chrome.exe /F I am i Linux right now, so I can't look it up. |
#4
|
|||
|
|||
Taskkill question
On 7/5/19 7:28 PM, T wrote:
IÂ*amÂ*iÂ*LinuxÂ*rightÂ*now,Â*soÂ*IÂ*can'tÂ*lookÂ* itÂ*up. Well DuckDuckGo has it: https://docs.microsoft.com/en-us/pre...725602(v=ws.10) /f Specifies that processes be forcefully terminated. So first try, leave off the "/f". |
#5
|
|||
|
|||
Taskkill question
T wrote:
On 7/5/19 7:06 PM, lonelydad wrote: T wrote in : Does Taskkill do a graceful shutdown or brute force? I am assuming you are refering to the task kill that is part of Task Manager. If so, the sends a 'die' signal to the task, which is supposed to have an overriding section of code that will terminate the task as soon as possible. Usually it works, but I have had a few times when a task was apparently really fubarred where it didn't work. I am talking about the command line: Taskkill /IM chrome.exe /F I wonder if it also has a "die" function. "/F" may be "force", in which case Taskkill /IM chrome.exe wait five seconds Taskkill /IM chrome.exe /F I am i Linux right now, so I can't look it up. What happened to your VM ? Windows 10 doesn't have to be "activated" to be useful. An unactivated copy, only the Personalization portion of the Setup wheel is blocked. You can get a Windows 10 for "quick jobs" here. https://developer.microsoft.com/en-u...dge/tools/vms/ A VM is a 4 to 5GB download. If the VM were to refuse to run, simply delete the VM and unpack a new copy. (On VirtualBox, the appliance file is a 5GB .ova file and you keep the original download so you can unpack it over and over again.) Using your VM, you could taskkill /? to get more info. And the time to collect those VMs, was around 5 years ago, so you could get "a complete set". Paul |
#6
|
|||
|
|||
Taskkill question
T wrote:
Does Taskkill do a graceful shutdown or brute force? With the /f switch, taskkill sends a shutdown request to the process, similar to how a shutdown sends a similar request. Some apps will continue to refuse to respond, so you have to add /f switch to brute force their kill. MS Outlook (the local program, not the outlook.com web site) has no command-line switch to tell it to gracefully shutdown. When doing backups, and if your backup program doesn't support VSC (Volume Shadow Copy), then it cannot read locked/inuse files, and that would include Outlook's .pst file while Outlook is running. You could try to use "taskkill.exe /f /im outlook.exe" to kill off MS Outlook before the backup job begins, but smashing Outlook means it doesn't get to save any changes to its PST file, and that can lead to corrupt of the database file. So, you get a backup program that supports VSC, or you forego including Outlook's PST file in your backups (if you leave Outlook loaded 24x7). First the process must recognize the shutdown request. If it ignores the request, you're stuck having to kill the process. Even if it does recognize the request, it may not honor it, so you have to kill it. After recognizing the request and branching to its exit code, the exit could take too long, so the OS sees the process as unresponsive and will kill it (after prompting you). The response wait time is configurable in the registry. I'd have to go look it up again, but an online search on "windows process shutdown wait time" will probably find the registry edit(s). https://www.google.com/search?q=wind...down+wait+time found many, like: https://www.howtogeek.com/282062/con...s-at-shutdown/ I'm guessing the shutdown wait times also apply to when you request individual processes to exit. Seems something you could test by altering the values, but you'd need to find a stubborn process that doesn't recognize or doesn't honor the request or takes way too long to run its cleanup & exit code. |
#7
|
|||
|
|||
Taskkill question
On 7/5/19 9:40 PM, Paul wrote:
WhatÂ*happenedÂ*toÂ*yourÂ*VMÂ*? Duck Duck go was quicker. I had spaced on it and forgot I could do that. |
#8
|
|||
|
|||
Taskkill question
On 7/5/19 10:14 PM, VanguardLH wrote:
T wrote: Does Taskkill do a graceful shutdown or brute force? With the /f switch, taskkill sends a shutdown request to the process, similar to how a shutdown sends a similar request. Some apps will continue to refuse to respond, so you have to add /f switch to brute force their kill. MS Outlook (the local program, not the outlook.com web site) has no command-line switch to tell it to gracefully shutdown. When doing backups, and if your backup program doesn't support VSC (Volume Shadow Copy), then it cannot read locked/inuse files, and that would include Outlook's .pst file while Outlook is running. You could try to use "taskkill.exe /f /im outlook.exe" to kill off MS Outlook before the backup job begins, but smashing Outlook means it doesn't get to save any changes to its PST file, and that can lead to corrupt of the database file. So, you get a backup program that supports VSC, or you forego including Outlook's PST file in your backups (if you leave Outlook loaded 24x7). First the process must recognize the shutdown request. If it ignores the request, you're stuck having to kill the process. Even if it does recognize the request, it may not honor it, so you have to kill it. After recognizing the request and branching to its exit code, the exit could take too long, so the OS sees the process as unresponsive and will kill it (after prompting you). The response wait time is configurable in the registry. I'd have to go look it up again, but an online search on "windows process shutdown wait time" will probably find the registry edit(s). https://www.google.com/search?q=wind...down+wait+time found many, like: https://www.howtogeek.com/282062/con...s-at-shutdown/ I'm guessing the shutdown wait times also apply to when you request individual processes to exit. Seems something you could test by altering the values, but you'd need to find a stubborn process that doesn't recognize or doesn't honor the request or takes way too long to run its cleanup & exit code. Thank you! I was going to taskkill without the /f, wait five seconds (maybe 10), then do it again with the "/f". |
#9
|
|||
|
|||
Taskkill question
On 7/5/19 6:11 PM, T wrote:
Does Taskkill do a graceful shutdown or brute force? Follow up: Set this off at 05:00 TaskKillAndReboot.bat echo off :: kill off select running tasks that do not respond to Volume Shadow copy Service (VSS) msg * Killing off selective tasks that are not Volume Shadow copy Service (VSS) Friendly and rebooting echo Killing off selective tasks that are not Volume Shadow copy Service (VSS) Friendly echo. echo Asking nicely... taskkill.exe /IM chrome.exe taskkill.exe /IM brave.exe taskkill.exe /IM firefox.exe taskkill.exe /IM thunderbird.exe taskkill.exe /IM QBW32.EXE echo. echo. echo Sleeping for 10 seconds C:\NtUtil\sleep 10s /quiet echo Cutting their legs off taskkill.exe /IM chrome.exe /f taskkill.exe /IM brave.exe /f taskkill.exe /IM firefox.exe /f taskkill.exe /IM thunderbird.exe /f taskkill.exe /IM QBW32.EXE /f echo. echo Sleeping for 10 seconds C:\NtUtil\sleep 10s /quiet shutdown.exe /r /f /t 15 /TaskKillAndReboot.bat |
#10
|
|||
|
|||
Taskkill question
T wrote:
On 7/5/19 6:11 PM, T wrote: Does Taskkill do a graceful shutdown or brute force? Follow up: Set this off at 05:00 TaskKillAndReboot.bat echo off :: kill off select running tasks that do not respond to Volume Shadow copy Service (VSS) msg * Killing off selective tasks that are not Volume Shadow copy Service (VSS) Friendly and rebooting echo Killing off selective tasks that are not Volume Shadow copy Service (VSS) Friendly echo. echo Asking nicely... taskkill.exe /IM chrome.exe taskkill.exe /IM brave.exe taskkill.exe /IM firefox.exe taskkill.exe /IM thunderbird.exe taskkill.exe /IM QBW32.EXE echo. echo. echo Sleeping for 10 seconds C:\NtUtil\sleep 10s /quiet echo Cutting their legs off taskkill.exe /IM chrome.exe /f taskkill.exe /IM brave.exe /f taskkill.exe /IM firefox.exe /f taskkill.exe /IM thunderbird.exe /f taskkill.exe /IM QBW32.EXE /f echo. echo Sleeping for 10 seconds C:\NtUtil\sleep 10s /quiet shutdown.exe /r /f /t 15 /TaskKillAndReboot.bat You know, one thing that bothers me a bit, is I got my Macrium backup finished, and it looks like it didn't have a problem taking a snapshot of "places.sqlite" while Firefox was open to a news web page (the kind that puts up fresh advertising every five seconds). I found an academic paper, that claimed (somehow!) you could use two or more VSS shadows, and do a "logical OR" to gather sectors, and this somehow makes it possible to snapshot files like places.sqlite. I don't really see any evidence Macrium is doing that. There is more to this than meets the eye. Anyway, here is a poorly formatted short article from some guys in India, who claim to have added a VSS wart to the side of sqlite3.exe. http://www.digitalxplore.org/up_proc...1689512-14.pdf What's the problem ? No download link for any sample code. I don't know what the purpose of writing a paper is, if there's no sample. Paul |
#11
|
|||
|
|||
Taskkill question
On 7/8/19 10:03 PM, Paul wrote:
T wrote: On 7/5/19 6:11 PM, T wrote: Does Taskkill do a graceful shutdown or brute force? Follow up: Set this off at 05:00 TaskKillAndReboot.bat echo off :: kill off select running tasks that do not respond to Volume Shadow copy Service (VSS) msg *Â* Killing off selective tasks that are not Volume Shadow copy Service (VSS) Friendly and rebooting echo Killing off selective tasks that are not Volume Shadow copy Service (VSS) Friendly echo. echo Asking nicely... taskkill.exe /IM chrome.exe taskkill.exe /IM brave.exe taskkill.exe /IM firefox.exe taskkill.exe /IM thunderbird.exe taskkill.exe /IM QBW32.EXE echo. echo. echo Sleeping for 10 seconds C:\NtUtil\sleep 10s /quiet echo Cutting their legs off taskkill.exe /IM chrome.exeÂ*Â*Â*Â*Â* /f taskkill.exe /IM brave.exeÂ*Â*Â*Â*Â*Â* /f taskkill.exe /IM firefox.exeÂ*Â*Â*Â* /f taskkill.exe /IM thunderbird.exe /f taskkill.exe /IM QBW32.EXEÂ*Â*Â*Â*Â*Â* /f echo. echo Sleeping for 10 seconds C:\NtUtil\sleep 10s /quiet shutdown.exe /r /f /t 15 /TaskKillAndReboot.bat You know, one thing that bothers me a bit, is I got my Macrium backup finished, and it looks like it didn't have a problem taking a snapshot of "places.sqlite" while Firefox was open to a news web page (the kind that puts up fresh advertising every five seconds). I found an academic paper, that claimed (somehow!) you could use two or more VSS shadows, and do a "logical OR" to gather sectors, and this somehow makes it possible to snapshot files like places.sqlite. I don't really see any evidence Macrium is doing that. There is moreÂ* to this than meets the eye. Anyway, here is a poorly formatted short article from some guys in India, who claim to have added a VSS wart to the side of sqlite3.exe. http://www.digitalxplore.org/up_proc...1689512-14.pdf What's the problem ? No download link for any sample code. I don't know what the purpose of writing a paper is, if there's no sample. Â*Â* Paul My solution was just to shut them off. Quick Books is a particular pain in the ass to backup |
#12
|
|||
|
|||
Taskkill question
T wrote:
... C:\NtUtil\sleep 10s /quiet ... Windows 7, and later, has its own timeout command to let you pause the script for a specified time. Run "timeout /?" for help. Just something to reduce dependence of your batch script to 3rd party software. If you still want to use a 3rd party program, I would test it exists before trying to use it. If it doesn't exist, do you really want to run the rest of the script? If the 3rd party program sets the errorlevel, you could test if it ran okay instead of pre-testing it exists. Note that when you kill Firefox, it will attempt to reload the prior tabs unless you disable its recovery. Google Chrome will bitch on its next load that it wasn't exited properly and offers to reload the prior tabs. Hell, just using its own "X" exit button at the right end of the titlebar sometimes makes Chrome think it wasn't closed properly. For Chrome, there is no option to disable recovery and the only clumsy method I've seen is to edit some config file to eradicate the flag that makes Chrome think it had a dirty exit ("exited_cleanly":false). In fact, with both web browsers, I've seen where, for example, a corrupted cookie or tab history prevented loading the web browser. It would crash when loaded. The solution was to load it in its safe mode, exit, and reload. I'd use "taskkill.exe /im processname" to see which web browser will run their exit code when they are requested to unload. Are you sure any of them reject or don't honor that request, so you don't have to smash them to get rid of their processes? Smashing a process that has open files can lead to corruption of those files. When Windows shuts down, it gives a default 20 seconds (can be changed in the registry) for a process to respond. Your timeout of 20 seconds might not be reliably long enough. Microsoft is probably being generous, but they've also probably had more statistics as to when the vast majority of processes would unload when requested. I haven't used taskkill.exe for awhile, but I would expect it to return a status code. While stopping services immediately returns a status despite the service may take awhile to unload (the shutdown request is asynchronous between when the return status is returned for the request and when the service actually stops). If taskkill.exe returns a zero status, seems you could test on that using: @echo off cls echo Kill any existing processes for the following web browsers: echo - Google Chrome echo - Mozilla Firefox ... echo. echo Attempting soft request to stop the web browsers ... set chrmflag=1 set fxflag=1 ... taskkill.exe /im chrome.exe if "%errorlevel%" EQU "0" do ( echo Google Chrome exited. set chrmflag=0 ) taskkill.exe /im firefox.exe if "%errorlevel%" EQU "0" do ( echo - Mozilla Firefox exited. set fxflag=0 ) .... set /a flags=%chrmflag%+%fxflag%+... if %flags% EQU 0 do ( echo All web browsers unloaded. goto EndBatch ) echo. echo Some did not exit. Force unload on remaining processes ... for /L %i in (1,1,24) do ( if "%chrmflag%" NEQ "0" taskkill.exe /im chrome.exe /f if "%errorlevel%" EQU "0" sdo ( echo Google Chrome exited. set chrmflag=0 ) if "%fxflag%" NEQ "0" taskkill.exe /im firefox.exe /f if "%errorlevel%" EQU "0" do ( echo Mozilla Firefox exited. set fxflag=0 ) ... set /a flags=%chrmflag%+%fxflag%+... if %flags% EQU 0 goto EndBatch echo ... wait 5 seconds ... timeout /t 5 ) echo ERROR! The following process(es) refused to exit after 120 seconds: if "%chrmflag%" NEQ "0" echo chrome.exe if "%"fxflag%" NEQ "0" echo firefox.exe ... echo Hit a key to exit batch script ... pause nul :EndBatch echo -DONE- echo. Since taskkill is synchronous (its return value immediately reflects whether or not the process got killed or not), you grab its return value (since errorlevel get stepped on by a subsequent taskkill). You add up all the errorlevels. If zero, all were successful, so there's no point to wait any longer or to use /f with taskkill. When using /f, there's no point in retrying a force kill if the process managed to exit in the next iteration of the for-loop, nor even in the 1st iteration for any processes that did exit without using /f. The timeout of each iteration is just 5 seconds, so any that close sooner than the 2-minute total expiration (up to 24 iteration with each at 5 seconds = 120 seconds) don't bother getting retried with /f. If all taskkill /f return a zero status, no point in running any remaining iterations of the for-loop. Instead of waiting 20 (or 30) seconds for all taskkill /f to complete, you only run taskkill /f on those processes that haven't yet exited, and wait only 5 seconds on each iteration. You might wait 0 seconds, 5 seconds, or up to 120 seconds for /f to work. If after 2 minutes at 5-second intervals one, or more, processes still have refused to unload, you list those that are stuck. That's assuming someone is watching the console window whereing the batch script runs. I find trying to remember the priority of various errorlevel values and trying to test from top down in value a nuisance, so I just use errorlevel as a string against which to test for a value. The above batch script is off the top of my head. Probably needs some debugging. |
#13
|
|||
|
|||
Taskkill question
Oh, remember that taskkill needs elevated privileges. You cannot alter
the properties for a .bat file to elevate its privileges. You can elevate a shortcut that runs the .bat file, or when an event in Task Scheduler. Without elevated privs, all the taskkill commands will fail. |
#14
|
|||
|
|||
Taskkill question
Paul wrote:
You know, one thing that bothers me a bit, is I got my Macrium backup finished, and it looks like it didn't have a problem taking a snapshot of "places.sqlite" while Firefox was open to a news web page (the kind that puts up fresh advertising every five seconds). As I replied to Slootweg in T's other thread ("places.sqlint read timeout"), SQLite has a CLI where you can issue commands to it to quiesce its database during a backup; however, my guess is the backup program would need to create an ODBC driver to issue API calls to SQLite. VSS isn't needed *if* the backup program is SQLite aware. |
#15
|
|||
|
|||
Taskkill question
On 7/9/19 3:50 AM, VanguardLH wrote:
Oh, remember that taskkill needs elevated privileges. You cannot alter the properties for a .bat file to elevate its privileges. You can elevate a shortcut that runs the .bat file, or when an event in Task Scheduler. Without elevated privs, all the taskkill commands will fail. I tested it by opening Firefox, Chrome, Brave, and Thunderbird. Closed all four without elevated privileges. Shutdown /f /r /t 00 also ran fine without elevated privileges |
|
Thread Tools | |
Display Modes | Rate This Thread |
|
|