停止 Ruby 脚本的执行

PHP 中是否有类似 exitdie的方法可以停止 Ruby 脚本的执行?

78893 次浏览

Either abort or exit will help.

abort is an alias for Kernel.exit(false) which terminates execution immediately.

exit is an alias for Kernel.exit(true) and raises the SystemExit exception, that may be caught. Also at_exit functions and finalizers are run before termination.

abort can still hang if there's threads that are waiting. If you really want to terminate immediately try:

Process.kill 9, Process.pid

FYI for ruby on rails, you can simply use this gem shutup, in the rails directory run this command in the bash terminal

gem install shutup

it will find the PID of rails server and kill it.

and also you can do it with lsof -wi tcp:3000 in case you didnt start the server on another port otherwise you should change the port 3000