軟體是怎麼關閉的

時間 2021-06-07 23:38:42

1樓:

一般來說,退出程序是通過 exit() 來進行的,這種「主動退出」包括正常退出 exit(EXIT_SUCCESS) 和非正常退出(崩潰是其中之一) exit(EXIT_FAILURE)。exit() 對應系統呼叫 exit 和 _exit,這種退出會釋放程序占用的資源(_exit不會清理 I/O 緩衝)。

The exit operation typically performs clean-up operations within the process space before returning control back to the operating system. Some systems and programming languages allow user subroutines to be registered so that they are invoked at program termination before the process actually terminates for good. As the final step of termination, a primitive system exit call is invoked, informing the operating system that the process has terminated and allows it to reclaim the resources used by the process.

It is sometimes possible to bypass the usual cleanup; C99 offers the _exit() function which terminates the current process without any extra program clean-up. This may be used, for example, in a fork-exec routine when the exec

call fails to replace the child process; calling atexit routines would erroneously release resources belonging to the parent. 先理解一下訊號的概念:A signal is an asynchronous notification sent to a process or to a specific thread within the same process in order to notify it of an event that occurred.

乙個程式在執行的時候,你可以發各種訊號給這個程序,程序對這個訊號做出響應。比如 CTRL+C,實際上對這個程序傳送了乙個訊號(SIGINT),在預設的情況下該程序會終止。但是,如果你寫了特定的 signal handler,那麼就可以修改這個預設行為。

用於"殺死"其他程序的命令 kill 實際上是乙個程式,其功能是傳送訊號。

The kill utility sends a signal to the processes specified by the pid op-

erands.

該程式會內部會呼叫 system call 的 kill 來發起真正訊號傳遞。signal(7) - Linux manual page

//kill -- send signal to a process

//The kill() function sends the signal specified by sig to pid, a process

or a group of processes.

intkill(pid_t pid, int sig);

kill 預設傳送 SIGTERM 訊號,而 kill -9 實際上是傳送了 SIGKILL 訊號。這些訊號中只有 SIGKILL 和 SIGSTOP 不可以被截獲,這兩個命令由核心處理。

$ kill -l

HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM URG STOP TSTP CONT CHLD TTIN TTOU IO XCPU XFSZ VTALRM PROF WINCH INFO USR1 USR2

怎麼關閉「我」?

佛系少女 我 是誰?誰要關閉 我 為什麼要關閉?這個關閉者和 我 之間是什麼關係?有人把本我 小我和自我分別比作馬車上的人 馬和馬車。這三者是缺一不可的,沒有了馬,馬車跑不動,沒有了馬車裡的人,馬不知道應該往哪走,沒有馬車,人和馬也沒法走 騎馬除外 所以我不知道你為什麼想要關閉 我 俠客精神丶 只專...

怎麼看待南苑機場關閉?

人來人往 承載了我的回憶,從女朋友學校打車到南苑乙個多小時。有時候離航班起飛還有會兒,我們就在附近散會兒步,周圍幾乎沒什麼人,很清爽。我也是在北京南苑第一次真正接納當時如日中天的小黃車,冬天裡兩個人騎車趕去附近幾千公尺的一家快餐店吃飯,邊騎車還要給手哈氣取 日常心疼某蛋作為南方人卻需要冬天學校騎車 ...

QQ的6 5 5的QQ看點怎麼關閉啊?

QQ看點裡面的訊息都是坑,如果推送些有用或者是真實的內容那還不會這麼煩躁,偏偏一眼望去就感覺標題黨,現在關都不關不掉了。所有的都關閉了,但是訊息列表還是時不時會出現,而且還是置頂,永遠都是在第一條 謙卑為人 強迫症患者怎麼辦呢?哎!我是在手機設定裡,應用清除qq全部資料,重新登入,就沒有qq看點了,...