Skip to Content
LINUX系統程式設計 第二版
book

LINUX系統程式設計 第二版

by Robert Love
December 2013
Intermediate to advanced
496 pages
8h 57m
Chinese
GoTop Information, Inc.
Content preview from LINUX系統程式設計 第二版
信號
|
367
10-2 繼承信號的行為
信號的行為 fork exec
忽略 繼承 繼承
預定 繼承 繼承
處理 繼承 不繼承
懸而未決的信號 不繼承 繼承
此行為在行程的執行上具有一個重要的用途:當 shell 在背景執行了一個行程時(或是
當另一個背景行程在執行了另一個行程時),剛被執行的行程應該會忽略中斷與結束
字符。因此,在 shell 執行一個背景行程之前,它應該把
SIGINT
SIGQUIT
設定為
SIG_
IGN
。因此,處理這些信號的程式通常會先檢查以確定它們沒有被忽略。例如:
/* 處理 SIGINT,但只發生在它未被忽略的狀況下 */
if (signal (SIGINT, SIG_IGN) != SIG_IGN) {
if (signal (SIGINT, sigint_handler) == SIG_ERR)
fprintf (stderr, "Failed to handle SIGINT!\n");
}
* 處理 SIGQUIT,但只發生在它未被忽略的狀況下 */
if (signal (SIGQUIT, SIG_IGN) != SIG_IGN) {
if (signal (SIGQUIT, sigquit_handler) == SIG_ERR)
fprintf (stderr, "Failed to handle SIGQUIT!\n");
}
這需要設定一個信號行為來檢查信號的行為,顯然是
signal()
介面中的一個缺陷。稍
後,我們將研究一個不具此缺點的函式。
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

優雅的SciPy|Python科學研究的美學

優雅的SciPy|Python科學研究的美學

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9789862769812