?? 1-17.c
字號:
/* * Test case for assertion #1 of the sigaction system call that shows * sigaction (when used with a non-null act pointer) changes the action * for a signal. * * Steps: * 1. Initialize a global variable to indicate the signal * handler has not been called. (A signal handler of the * prototype "void func(int signo);" will set the global * variable to indicate otherwise. * 2. Use sigaction to setup a signal handler for SIGUSR1 * 3. Raise SIGUSR1. * 4. Verify the global indicates the signal was called.*/#include <signal.h>#include "compat.h"#define NTASKS 1static pthread_t thread[NTASKS];int handler_called = 0;void handler(int signo){ handler_called = 1;}void * th_code (void * arg){ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGUSR1, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return -1; } if (raise(SIGUSR1) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return -1; } if (handler_called) { printf("Test PASSED\n"); return 0; } printf("Test FAILED\n"); return -1; }int init_module(void){ int i; for(i=0;i<NTASKS;i++) pthread_create(&thread[i], NULL,th_code,(void *) i); return 0; }void cleanup_module(void){ int i; for(i=0;i<NTASKS;i++) pthread_delete_np(thread[i]);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -