18. Kill
注意在大多数shell 下它同时也是一个内置命令
$ echo $0 && type -a kill
-bash
kill is a shell builtin
kill is /usr/bin/kill
➜ echo $0 && type -a kill
zsh
kill is a shell builtin
kill is /bin/kill
% echo $0 && type -a kill
csh
kill is a shell builtin
kill is /bin/kill
24. 守护进程对SIGHUP的处理
$ kill –s HUP pidof_nginx
“This signal [SIGHUP] is commonly used to notify
daemon processes (Chapter 13) to reread their
configuration files. The reason SIGHUP is chosen for
this is because a daemon should not have a
controlling terminal and would normally never
receive this signal.”
<<Advanced Programming in the UNIX Environment>>
53. JVM Signal Handler
scala> import sun.misc._
scala> Signal.handle(new Signal("INT"),
| new SignalHandler(){
| def handle(sig:Signal){ println("down") }}
| )
$ kill -s INT `pidof java`
scala> down // 被捕获,进程不会退出
54. JVM Signal Handler
注意,被OS或JVM已注册了的 Signal 不能被修改,比如 SIGQUIT、
SIGUSR1 等
scala> Signal.handle(
| new Signal("QUIT"),
| new SignalHandler(){
| def handle(sig:Signal){ println("down") }
| }
| )
java.lang.IllegalArgumentException: Signal already used by VM or OS:
SIGQUIT
at sun.misc.Signal.handle(Signal.java:166)
... 38 elided