3 * Copyright (C) 2021 Simone Piccardi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /****************************************************************
21 * Program rtsigvalsend.c:
22 * Program to test sigqueue and sigval send
24 * Author: Simone Piccardi
27 * Usage: ./rtsigvalsend
28 **********************************************************/
30 * Include needed headers
32 #include <unistd.h> /* unix standard library */
33 #include <stdio.h> /* standard I/O library */
34 #include <stdlib.h> /* C standard library */
35 #include <string.h> /* C strings library */
36 #include <signal.h> /* signal constants, types and functions */
37 #include <errno.h> /* error definitions and routines */
42 void sig_handler(int signum, siginfo_t *info, void *ucontext) {
43 printf("Signal %d\n", signum);
44 printf("From pid %d\n", info->si_pid);
45 printf("From user %d\n", info->si_uid);
46 printf("Value %d\n", info->si_value.sival_int);
49 int main(int argc, char *argv[], char *envp[])
51 char buffer[MAXLINE+1];
54 int signo = SIGRTMIN+1;
56 struct sigaction new_handl, old_handl;
57 sigemptyset(&new_handl.sa_mask);
58 new_handl.sa_sigaction = sig_handler;
59 new_handl.sa_flags=SA_SIGINFO;
60 /* change action for signo signal */
61 sigaction(signo, &new_handl, &old_handl);
63 nread = read(STDIN_FILENO, buffer, MAXLINE);
65 printf("Errore in lettura: %s\n", strerror(errno));
69 value.sival_int = strtol(buffer, NULL, 10);
70 if (value.sival_int > 0) {
71 sigqueue(getpid(), signo, value);
73 printf("Ignoring invalid input\n");