問題:html
1. 工做電腦windows使用SecureCRT鏈接開發機,Ctrl + C 沒法使用,習慣性使用Ctrl + Z,表面中止輸出jquery
2. 每次Ctrl + Z再次執行相同gradlew,就會說已有在進程在運行linux
解決:vim
1. SecureCRT Ctrl + C 沒法使用: 與複製熱鍵衝突,會話選項中剔除CUA設置中的勾windows
2.方法1: 使用 Ctrl + C 終止線程bash
方法2:使用Ctrl + Z後去kill異步
#查看後臺工做,-l選項用於顯示PID jobs -l #輸出示例 [1]- 10314 Stopped vim ~/.bashrc [2]+ 10833 Stopped find / -print #殺進程,-15爲正常結束 kill -15 %1 or kill -15 10833
解析1:Ctrl+Z/Ctrl+C的區別(參考:stack)socket
Ctrl+Z: 發送信號SIGSTOP,用於掛起線程;如上顯示的STOPPED狀態,可切換到前臺fg/切換到後臺bg/殺掉kill。函數
Ctrl+C:發送信號SIGINT,用於殺線程;學習
說到這裏,和理論學習的總算對上了,這就是suspend和kill
解析2:SIGSTOP/SIGINT信號機制
計算機系統層面/Linux層面,都存在線程/進程間通訊機制,其中又都包含「信號機制」。
這是一種異步通訊機制,某個線程/進程收到信號後對其作出響應。同時也有人將這與硬件層面處理器的中斷機制類比。
信號來源:
1. 硬件層:如此處的各類快捷鍵;
2. 軟件來源:系統函數提供信號相關函數,如sigqueue() 信號發送函數;
信號種類:
支持的信號種類都是在國際標準中指定的,逐步擴展。早期設計機制存在丟失信號的可能,被稱爲「不可靠信號」,以後擴展支持的信號值就對應稱爲「可靠信號」。
經常使用的是POSIX信號量規範。
#信號示例 SIGINT #The SIGINT signal is sent to a process by its controlling terminal when a user wishes to interrupt the process SIGKILL #The SIGKILL signal is sent to a process to cause it to terminate immediately (kill) SIGSTOP #The SIGSTOP signal instructs the operating system to stop a process for later resumption.
參考:POSIX signal
信號響應:
進程/線程收到信號後對此作出響應,通常有如下三種。
1. ignore,即不作任何處理,但SIGKILL及SIGSTOP信號是不能忽略的;
2. 執行缺省操做,Linux中定義了不一樣信號的默認處理動做(wiki中截圖部分以下);
3. 捕捉信號,自定義信號處理函數。
Signal | Portable number | Default Action | Description |
---|---|---|---|
SIGABRT | 6 | Terminate (core dump) | Process abort signal |
SIGALRM | 14 | Terminate | Alarm clock |
SIGBUS | n/a | Terminate (core dump) | Access to an undefined portion of a memory object. |
SIGCHLD | n/a | Ignore | Child process terminated, stopped, or continued. |
SIGCONT | n/a | Continue | Continue executing, if stopped. |
SIGFPE | n/a | Terminate (core dump) | Erroneous arithmetic operation. |
SIGHUP | 1 | Terminate | Hangup. |
SIGILL | n/a | Terminate (core dump) | Illegal instruction. |
SIGINT | 2 | Terminate | Terminal interrupt signal. |
SIGKILL | 9 | Terminate | Kill (cannot be caught or ignored). |
SIGPIPE | n/a | Terminate | Write on a pipe with no one to read it. |
SIGPOLL | n/a | Terminate | Pollable event. |
SIGPROF | n/a | Terminate | Profiling timer expired. |
SIGQUIT | 3 | Terminate (core dump) | Terminal quit signal. |
SIGSEGV | n/a | Terminate (core dump) | Invalid memory reference. |
SIGSTOP | n/a | Stop | Stop executing (cannot be caught or ignored). |
SIGSYS | n/a | Terminate (core dump) | Bad system call. |
SIGTERM | 15 | Terminate | Termination signal. |
SIGTRAP | n/a | Terminate (core dump) | Trace/breakpoint trap. |
SIGTSTP | n/a | Stop | Terminal stop signal. |
SIGTTIN | n/a | Stop | Background process attempting read. |
SIGTTOU | n/a | Stop | Background process attempting write. |
SIGUSR1 | n/a | Terminate | User-defined signal 1. |
SIGUSR2 | n/a | Terminate | User-defined signal 2. |
SIGURG | n/a | Ignore | High bandwidth data is available at a socket. |
SIGVTALRM | n/a | Terminate | Virtual timer expired. |
SIGXCPU | n/a | Terminate (core dump) | CPU time limit exceeded. |
SIGXFSZ | n/a | Terminate (core dump) | File size limit exceeded |
參考:http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index1.html