Comments (12)
That is very slow indeed. What operating system and Node.js version are you on?
from fkill.
@sindresorhus win10 + nodejs 8.0.0
from fkill.
Then probably not. fkill
is just using the built-in taskkill
command to kill processes on Windows. https://github.com/sindresorhus/taskkill
from fkill.
ok, thanks anyway
from fkill.
@debuggy Are those processes doing some kind of I/O by any chance? taskkill
should be fast, but you might be interacting with device drivers that don't properly handle the cancellation of outstanding I/O requests, for example.
EDIT: Process Explorer or Process Monitor might help you debug this issue.
from fkill.
@MarkTiedemann Thanks for your kind reply, actually I have tackled this issue by using tree-kill ...
It also executes taskkill
command in win32 platform and somehow runs faster in my senario.
from fkill.
@debuggy Since both tree-kill
and fkill
execute taskkill /pid $pid /t(ree) /f(orce)
, there should not be any significant performance difference.
Can you perhaps share a minimal reproduction for this case? I'd be happy to help figure out why this discrepancy occurs.
from fkill.
In my case fkill was running painfully slow (+40s), and I figured out its because it uses process-exist
which uses ps-list
which uses tasklist
and tasklist was the one who is slow, and also was loading cpu significantly (WMI Provider Host
in taskmanager C:\Windows\System32\wbem\WmiPrvSE.exe
). I was trying to reproduce this issue in another project and failed, then I removed node_modules
folder and package.lock
and reinstalled all packages and problem went away, it only took 0.5-2s to run tasklist now which is slow but bearable.
Also I figured it's not neccessary to check if process exists before trying to taskkill it, since taskkill return error code if it cant find specified process. I wish there was an windows-only option like faster
or quick-and-dirty
to ommit tasklist
(processExist
) call. Should I write a PR maybe?
from fkill.
@mugiseyebrows The speedup you got from reinstalling was probably related to a recent performance issue in tasklist
that has been fixed.
If you want to write a PR that properly handles taskkill
exit codes, that would be great. :)
from fkill.
@mugiseyebrows [email protected]
just got ~5x faster on Windows. Is it more bearable for your use case now?
Since you only want to kill a single process, there's a huge overhead in process-exists
which gets a list of all running processes to determine whether a single process is running.
To mitigate this overhead, we could write a Node native addon (hard to maintain) or build a simple binary which could be executed from Node which only checks whether a single process is running.
For example, from the binary, we could call the OpenProcess
function with PROCESS_QUERY_INFORMATION
rights, then pass the process handle to the GetExitCodeProcess
function and check whether it returns STILL_ACTIVE
. (Maybe there are different, better approaches - I haven't done any research yet. This is just a first idea.)
PS: If I have time in the upcoming days, I might work on this. :)
from fkill.
@mugiseyebrows I checked the exit codes for taskkill
.
0: Success
1: Access Denied
128: Not Found
0
doesn't actually guarantee that the process was killed; it only guarantees that a "termination signal was sent" (which usually means that the process was not terminated immediately, which usually means that it won't ever terminate in response to this, but more reasearch and experiments are required here).
Also, there might be other exit codes in edge cases (see: Windows system errors codes).
Also, when killing multiple processes with taskkill
, if one of them fails, the exit code will indicate failure.
λ taskkill /pid 123456 /pid 3000 /f
ERROR: The process "123456" not found.
SUCCESS: The process with PID 3000 has been terminated.
λ echo %errorlevel%
128
Also, when multiple failures occur, the exit code 128
takes priority over 1
.
λ taskkill /pid 123456 /pid 0
ERROR: The process "123456" not found.
ERROR: The process with PID 0 could not be terminated.
Reason: This is critical system process. Taskkill cannot end this process.
λ echo %errorlevel%
128
Also, you cannot reliably parse the error message strings (e.g. ERROR: The process "xyz" not found.
) for determining the error reason since those are language-specific, e.g. on a German or Spanish Windows installation, these are different.
So yeah, this is a huge mess. :)
In conclusion, I think taskkill
should be improved, if possible, or replaced by a less messy alternative, and if we can improve it, then fkill
doesn't need to check whether processes exist when it is executed on Windows since the return values should indicate what succeeded and what failed and why it failed.
from fkill.
@0maxxam0 has funded $8.00 to this issue.
- Submit pull request via IssueHunt to receive this reward.
- Want to contribute? Chip in to this issue via IssueHunt.
- Checkout the IssueHunt Issue Explorer to see more funded issues.
- Need help from developers? Add your repository on IssueHunt to raise funds.
from fkill.
Related Issues (20)
- Allow for silent failure if process not found HOT 4
- Error: Killing process processName failed: spawn killall ENOENT HOT 3
- Add Ethereum name or address to package.json HOT 2
- pkill: illegal option -- 9 HOT 2
- Invalid regular expression HOT 1
- Add `forceTimeout` option HOT 1
- Windows - fkill error if process started with /min flag HOT 5
- Global install HOT 1
- Confirm processes are no longer visible before returning HOT 1
- Don't kill `fkill` when killing `node.exe`
- Silent option is in the code, but not registered as an option in index.d.ts
- Mac ignoreCase causes error
- Fkill not installed properly with npm HOT 1
- CommonJS support - include index.cjs HOT 1
- Cannot install on Zorin 16 (Ubuntu 20.04. 2 LTS) HOT 1
- Cannot find module node:process HOT 1
- SIGINT support
- Unexpected behavior because of pkill on macOS HOT 1
- Question: There is some option to customize how many entries are displayed at the same time? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fkill.