Why does Cygwin execute shell commands very slowly?

前端 未结 11 1134
说谎
说谎 2020-12-08 11:29

Just tests a very simple command like:

while true; do bash -c \"echo hello\"; done

You will find how much slow the bash in Cygwin is. Does

相关标签:
11条回答
  • 2020-12-08 12:03

    Check your path. Referring a non-existant path or a very slow network share can cause the symptoms you are describing.

    0 讨论(0)
  • 2020-12-08 12:04

    I voted up on James McLeod, because starting a bash process takes some time, but it doesn't mean it will run commands slower than in UNIX.

    Invoking bash -c from within a bash script is near to senseless, and Makefiles can call a lot of bash subprocesses, unless you append ; \ at the end of the commands.

    For example, if a Makefile has the following:

    echo Hello World
    echo Good Bye
    

    It will call two bash processes. To make it faster and call just one bash process:

    echo Hello World; \
    echo Good Bye
    

    Debian has adopted dash instead of bash as the main shell, because starting many init scripts using bash will make the system take much longer to boot (each script call its own bash process).

    0 讨论(0)
  • 2020-12-08 12:08

    Invoking bash from a shell script can't be fast. Is it faster to just use

    while true; echo hello; done
    

    ?

    0 讨论(0)
  • 2020-12-08 12:09

    I was able to fix this problem by uninstalling bash-completion and switching from Kaspersky to Windows Security Essentials. (I diagnosed the Kaspersky interference using Process Explorer while running the "echo Hello" benchmark.) Brought my benchmark time from 7 seconds to 0.2.

    0 讨论(0)
  • 2020-12-08 12:18

    For Windows Defender:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender]
    "DisableAntiSpyware"=dword:00000001
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection]
    "DisableBehaviorMonitoring"=dword:00000001
    "DisableOnAccessProtection"=dword:00000001
    "DisableScanOnRealtimeEnable"=dword:00000001
    

    or less dramatically:

    powershell -Command Add-MpPreference -ExclusionPath "C:\opt\cygwin64"
    powershell -Command Add-MpPreference -ExclusionPath "C:\home"
    powershell -Command Add-MpPreference -ExclusionProcess "git.exe"
    powershell -Command Add-MpPreference -ExclusionExtension ".c"
    powershell -Command Add-MpPreference -ExclusionExtension ".cpp"
    powershell -Command Add-MpPreference -ExclusionExtension ".cxx"
    

    For Sophos:

    REG ADD "HKLM\SYSTEM\CurrentControlSet\Services\Sophos Endpoint Defense\Scanning\Config" /v "OnAccessExcludeFilePaths" /t REG_MULTI_SZ /d "C:\Program Files (x86)\Sophos\Sophos Anti-Virus\\0C:\home\\0D:\Video\\" /f
    REG ADD "HKLM\SYSTEM\CurrentControlSet\Services\Sophos Endpoint Defense\Scanning\Config" /v "OnAccessExcludeProcessPaths" /t REG_MULTI_SZ /d "C:\opt\cygwin64\\" /f
    
    0 讨论(0)
提交回复
热议问题