我在Mac机器上运行Ruby时遇到问题。我已经谷歌一段时间但没有找到令人满意的答案,所以我决定问自己。
我使用Visual Studio Code运行一些简单的ruby代码,我看到一些奇怪的东西。 ruby进程占用了99%的CPU。
正如您所看到的,它只占一个简单代码的99%CPU使用率。它将一直运行,直到我强制退出服务,有时不只有一个进程。
这是我运行的代码:
range1 = 1..5
something = 3
something.to_s
print something
这是在Ruby服务中运行文件,内存位置(我不知道它叫什么):
cwd
/
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/bin/ruby
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/libruby.2.5.0.dylib
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/enc/encdb.bundle
txt
/usr/local/Cellar/gmp/6.1.2_1/lib/libgmp.10.dylib
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/enc/trans/transdb.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/stringio.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/etc.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/pathname.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/openssl.bundle
txt
/usr/local/Cellar/openssl@1.1/1.1.0g_1/lib/libssl.1.1.dylib
txt
/usr/local/Cellar/openssl@1.1/1.1.0g_1/lib/libcrypto.1.1.dylib
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/digest.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/io/nonblock.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/zlib.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/digest/sha1.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/socket.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/io/wait.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/enc/windows_31j.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/json/ext/parser.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/json/ext/generator.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/readline.bundle
txt
/usr/local/Cellar/readline/7.0.3_1/lib/libreadline.7.0.dylib
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/strscan.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/date_core.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/cgi/escape.bundle
txt
/Users/konzaho/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/x86_64-darwin17/digest/md5.bundle
txt
/usr/lib/dyld
txt
/private/var/db/dyld/dyld_shared_cache_x86_64h
0
->0x369452a54d0e4c31
1
->0x369452a54d0e4911
2
->0x369452a54d0e38a9
3
->0x369452a54b81a3e9
4
->0x369452a54b81b769
5
->0x369452a54b81a569
6
->0x369452a54d0e38a9
7
->0x369452a54b81bb29
8
[ctl com.apple.netsrc id 9 unit 27]
9
->0x369452a54d0e5271
10
localhost:59277
11
localhost:59277
12
->0x369452a54b81a0e9
13
->0x369452a54b81a4a9
14
localhost:59277->localhost:59285
15
localhost:59277->localhost:59286
16
localhost:59277->localhost:59287
24
->0x369452a5536d6789
25
/Applications/Visual Studio Code.app/Contents/Resources/electron.asar
27
/Users/konzaho/Devs/ruby/bookTwo.rb
Ruby为了运行一个简单的代码而占用这么大的CPU能力是否正常? 是的,当然我可以立即强制退出这个过程,但是每次关闭编辑器时它都会很烦人,它也会使我的机器升温。
编辑: 我在Visual Code的终端和
中运行此代码bookTwo.rb
我和上面提到的完全一样的代码。现在我在Mac的终端中运行代码,但是当我在VS Code终端中运行时它没有问题。