Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
trap 'TERM' do warn 'Exiting.' exit 1 end
这将打印一个 10 行的堆栈跟踪。
如何抑制堆栈跟踪并静默退出?
红宝石 2.2.0
你可以这样做:
trap "TERM" do warn "Exiting." $stderr.reopen(IO::NULL) $stdout.reopen(IO::NULL) exit 1 end
如果你击中Ctrl + C,信号会INT,不会TERM。如果你想同时抓住两者,你可以这样做:
INT
TERM
p = proc do warn 'Exiting.' exit 1 end trap 'INT',p trap 'TERM',p