00001 /* 00002 RTS siginfo_t example 00003 AUP2, Sec. 9.05.1 00004 00005 Copyright 2003 by Marc J. Rochkind. All rights reserved. 00006 May be copied only for purposes and under conditions described 00007 on the Web page www.basepath.com/aup/copyright.htm. 00008 00009 The Example Files are provided "as is," without any warranty; 00010 without even the implied warranty of merchantability or fitness 00011 for a particular purpose. The author and his publisher are not 00012 responsible for any damages, direct or incidental, resulting 00013 from the use or non-use of these Example Files. 00014 00015 The Example Files may contain defects, and some contain deliberate 00016 coding mistakes that were included for educational reasons. 00017 You are responsible for determining if and how the Example Files 00018 are to be used. 00019 00020 */ 00021 #include "defs.h" 00022 00023 #ifdef FREEBSD 00024 #define sival_int sigval_int 00025 #define sival_ptr sigval_ptr 00026 #endif 00027 00028 /*[handler]*/ 00029 static void handler(int signum, siginfo_t *info, void *context) 00030 { 00031 printf("signal number: %d\n", info->si_signo); 00032 printf("sending process ID: %ld\n", (long)info->si_pid); 00033 printf("real user ID of sending process: %ld\n", (long)info->si_uid); 00034 switch (info->si_code) { 00035 case SI_USER: 00036 printf("Signal from user\n"); 00037 break; 00038 case SI_QUEUE: 00039 printf("Signal from sigqueue; value = %d\n", 00040 info->si_value.sival_int); 00041 break; 00042 case SI_TIMER: 00043 printf("Signal from timer expiration; value = %d\n", 00044 info->si_value.sival_int); 00045 break; 00046 case SI_ASYNCIO: 00047 printf("Signal from asynchronous I/O completion; value = %d\n", 00048 info->si_value.sival_int); 00049 break; 00050 case SI_MESGQ: 00051 printf("Signal from message arrival; value = %d\n", 00052 info->si_value.sival_int); 00053 break; 00054 default: 00055 printf("Other signal\n"); 00056 } 00057 } 00058 /*[main]*/ 00059 int main(void) 00060 { 00061 struct sigaction act; 00062 union sigval val; 00063 00064 memset(&act, 0, sizeof(act)); 00065 act.sa_flags = SA_SIGINFO; 00066 act.sa_sigaction = handler; 00067 ec_neg1( sigaction(SIGUSR1, &act, NULL) ) 00068 #if _POSIX_REALTIME_SIGNALS > 0 00069 ec_neg1( sigaction(SIGRTMIN, &act, NULL) ) 00070 #endif 00071 ec_neg1( kill(getpid(), SIGUSR1) ) 00072 val.sival_int = 1234; 00073 #if _POSIX_REALTIME_SIGNALS > 0 00074 ec_neg1( sigqueue(getpid(), SIGRTMIN, val) ) 00075 #endif 00076 exit(EXIT_SUCCESS); 00077 00078 EC_CLEANUP_BGN 00079 exit(EXIT_FAILURE); 00080 EC_CLEANUP_END 00081 } 00082 /*[]*/