问题
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