C語言標準庫
C語言標準庫
<assert.h> - C語言標準庫
C函數庫宏 assert()
<ctype.h> - C語言標準庫
isalnum() - C函數
isalpha() - C函數
iscntrl() - C函數
isdigit() - C函數
isgraph() - C函數
islower() - C函數
isprint() - C函數
ispunct() - C函數
isspace() - C函數
isupper() - C函數
isxdigit() - C函數
tolower() - C函數
toupper() - C函數
<errno.h> - C語言標準庫
errno - C語言宏
EDOM - C語言宏
ERANGE - C語言宏
<float.h> - C語言標準庫
<limits.h> - C語言標準庫
<locale.h> - C語言標準庫
setlocale() - C函數
localeconv() - C函數
<math.h> - C語言標準庫
acos() - C函數
asin() - C函數
atan() - C函數
atan2() - C函數
cos() - C函數
sin() - C函數
sinh() - C函數
tanh() - C函數
exp() - C函數
frexp() - C函數
ldexp() - C函數
log() - C函數
log10() - C函數
modf() - C函數
pow() - C函數
sqrt() - C函數
ceil() - C函數
fabs() - C函數
floor() - C函數
fmod() - C函數
<setjmp.h> - C語言標準庫
setjmp() - C函數
longjmp() - C函數
<signal.h> - C語言標準庫
signal() - C函數
raise() - C函數
<stdarg.h> - C語言標準庫
va_start() - C函數
va_arg() - C函數
va_end() - C函數
<stddef.h> - C語言標準庫
NULL - C函數
offsetof() - C函數
<stdio.h> - C語言標準庫
clearerr() - C庫函數
fclose() - C庫函數
feof() - C庫函數
ferror() - C庫函數
fflush() - C庫函數
fgetpos() - C庫函數
fopen() - C語言庫函數
fread() - C語言庫函數
freopen() - C語言庫函數
fseek() - C語言庫函數
fsetpos() - C語言庫函數
ftell() - C語言庫函數
fwrite() - C語言庫函數
remove() - C語言庫函數
rename() - C語言庫函數
rewind() - C語言庫函數
setbuf() - C語言庫函數
setvbuf() - C語言庫函數
tmpfile() - C語言庫函數
tmpnam() - C語言庫函數
fprintf() - C語言庫函數
printf() - C語言庫函數
sprintf() - C語言庫函數
vfprintf() - C語言庫函數
vprintf() - C語言庫函數
vsprintf() - C語言庫函數
fscanf() - C語言庫函數
scanf() - C語言庫函數
sscanf() - C語言庫函數
fgetc() - C語言庫函數
fgets() - C語言庫函數
fputc() - C語言庫函數
fputs() - C語言庫函數
getc() - C語言庫函數
getchar() - C語言庫函數
gets() - C語言庫函數
putc() - C語言庫函數
putchar() - C語言庫函數
puts() - C語言庫函數
ungetc() - C語言庫函數
perror() - C語言庫函數
<stdlib.h> - C語言標準庫
atof() - C語言庫函數
atoi() - C語言庫函數
atol() - C語言庫函數
strtod() - C語言庫函數
strtol() - C語言庫函數
strtoul() - C語言庫函數
calloc() - C語言庫函數
free() - C語言庫函數
malloc() - C語言庫函數
realloc() - C語言庫函數
abort() - C語言庫函數
atexit() - C語言庫函數
exit() - C語言庫函數
getenv() - C語言庫函數
system() - C語言庫函數
bsearch() - C語言庫函數
qsort() - C語言庫函數
abs() - C語言庫函數
div() - C語言庫函數
labs() - C語言庫函數
ldiv() - C語言庫函數
rand() - C語言庫函數
srand() - C語言庫函數
mblen() - C語言庫函數
mbstowcs() - C語言庫函數
mbtowc() - C語言庫函數
wcstombs() - C語言庫函數
wctomb() - C語言庫函數
<string.h> - C語言標準庫
memchr() - C語言庫函數
memcmp() - C語言庫函數
memcpy() - C語言庫函數
memmove() - C語言庫函數
memset() - C語言庫函數
strcat() - C語言庫函數
strncat() - C語言庫函數
strchr() - C語言庫函數
strcmp() - C語言庫函數
strncmp() - C語言庫函數
strcoll() - C語言庫函數
strcpy() - C語言庫函數
strcspn() - C語言庫函數
strerror() - C語言庫函數
strlen() - C語言庫函數
strpbrk() - C語言庫函數
strrchr() - C語言庫函數
strspn() - C語言庫函數
strstr() - C語言庫函數
strtok() - C語言庫函數
strxfrm() - C語言庫函數
<time.h> - C語言標準庫
asctime() - C語言庫函數
clock() - C語言庫函數
ctime() - C語言庫函數
difftime() - C語言庫函數
gmtime() - C語言庫函數
localtime() - C語言庫函數
mktime() - C語言庫函數
strftime() - C語言庫函數
time() C語言

signal() - C函數

C庫函數 void (*signal(int sig, void (*func)(int)))(int)設置一個函數來處理信號,即信號數量sig的信號處理程序 。

聲明

以下是signal()函數的聲明。

void (*signal(int sig, void (*func)(int)))(int)

參數

  • sig -- 這是信號的處理功能被設置的號碼。以下是幾個重要的標準信號的數字:

macro

signal

SIGABRT

(Signal Abort) Abnormal termination, such as is initiated by the function.

SIGFPE

(Signal Floating-Yiibai Exception) Erroneous arithmetic operation, such as zero divide or an operation resulting in overflow (not necessarily with a floating-yiibai operation).

SIGILL

(Signal Illegal Instruction) Invalid function image, such as an illegal instruction. This is generally due to a corruption in the code or to an attempt to execute data.

SIGINT

(Signal Interrupt) Interactive attention signal. Generally generated by the application user.

SIGSEGV

(Signal Segmentation Violation) Invalid access to storage: When a program tries to read or write outside the memory it is allocated for it.

SIGTERM

(Signal Terminate) Termination request sent to program.

  • func -- 這是一個指向函數的指針。這可以是由程序員或一個以下預定義的函數的定義的函數:

SIG_DFL

默認處理:對於某一特定信號,該信號處理的默認操作。

SIG_IGN

忽略信號:信號被忽略。

返回值

這個函數返回前一個信號處理程序或錯誤SIG_ERR的值。

例子

下面的例子顯示了signal()函數的用法。

#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <signal.h> void sighandler(int); int main() { signal(SIGINT, sighandler); while(1) { printf("Going to sleep for a second...
"); sleep(1); } return(0); } void sighandler(int signum) { printf("Caught signal %d, coming out...
", signum); exit(1); }

讓我們編譯和運行上面的程序,這將產生以下結果,程序將無限循環中去。跳出程序使用Ctrl + C鍵。

Going to sleep for a second...
Going to sleep for a second...
Going to sleep for a second...
Going to sleep for a second...
Going to sleep for a second...
Caught signal 2, coming out...