“杀死"和“终结"之间的区别 [英] Difference between 'Killed' and 'Terminated'
问题描述
我只是在测试处于睡眠状态的终止开关标志.
I was just testing kill switch flags with a sleeping process.
首先我尝试用-15杀死它
First i tried killed it with -15
xtechkid@ubuntu:~/Desktop/expermiments$ ps cax | grep 10005
10005 pts/2 S+ 0:00 sh
xtechkid@ubuntu:~/Desktop/expermiments$ kill -15 10005
该过程终止
xtechkid@ubuntu:~/Desktop/expermiments$ sh testscript.sh
This is a script which sleeps for few seconds ..
Terminated
然后我用-9杀死了它
xtechkid@ubuntu:~/Desktop/expermiments$ ps -ef | grep testscript.sh
xtechkid 10059 9852 0 13:48 pts/2 00:00:00 sh testscript.sh
xtechkid 10064 10007 0 13:48 pts/4 00:00:00 grep --color=auto testscript.sh
xtechkid@ubuntu:~/Desktop/expermiments$ kill -9 10059
进程被杀死
xtechkid@ubuntu:~/Desktop/expermiments$ sh testscript.sh
This is a script which sleeps for few seconds ..
Killed
有什么区别?
推荐答案
终止"信号SIGTERM是可以在程序中拦截的信号.通常,打算在后台运行的进程会捕获此信号并启动关闭进程,从而导致干净退出. "kill"信号SIGKILL无法被截获.将其发送到进程后,将导致该程序的突然终止.
The 'terminate' signal, SIGTERM, is a signal that can be intercepted in a program. Often processes which are meant to run in the background will catch this signal and start a shutdown process, resulting in a clean exit. The 'kill' signal, SIGKILL, cannot be intercepted. When this is sent to a process it will result in an abrupt termination of that program.
例如,当您关闭计算机或重新启动计算机时,通常会先将SIGTERM发送给正在运行的进程,以允许它们以干净的方式退出(如果它们支持的话).然后,几秒钟后,SIGKILL被发送到仍在运行的进程,以便强行释放正在使用的资源(例如正在使用的文件),并且关闭序列可以继续(例如卸载文件系统)
When you shutdown or reboot your computer for example, usually a SIGTERM is sent to the running processes first allowing them to exit in a clean way if they support it. Then, after a few seconds a SIGKILL is sent to the processes which are still running so that resources in use are forcibly released (e.g. files in use) and the shutdown sequence can continue (e.g. unmounting filesystems)
这篇关于“杀死"和“终结"之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!