Difference between 'Killed' and 'Terminated'

别等时光非礼了梦想. 提交于 2020-05-23 04:16:28

问题


I was just testing kill switch flags with a sleeping process.

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

And the process got terminated

 xtechkid@ubuntu:~/Desktop/expermiments$ sh testscript.sh
 This is a script which sleeps for few seconds ..
 Terminated

Then i killed it with - 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

And the process got killed

 xtechkid@ubuntu:~/Desktop/expermiments$ sh testscript.sh
 This is a script which sleeps for few seconds ..
 Killed

What is the difference ?


回答1:


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.

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)




回答2:


Terminate : it will store all your data before shutting down (write data from RAM to disk, logs, etc)

Kill: It is more like pressing PC power and reset button. It wont save any logs or other data.



来源:https://stackoverflow.com/questions/19206124/difference-between-killed-and-terminated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!