3 * Copyright (C) 2011 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 test_timerfdfork.c:
22 * Program to test timerfd behaviour across fork's
24 * Author: Simone Piccardi
27 * Usage: testtimerfdfork -h give all info's
29 ****************************************************************/
31 * Include needed headers
34 #include <errno.h> /* error definitions and routines */
35 #include <stdlib.h> /* C standard library */
36 #include <unistd.h> /* unix standard library */
37 #include <stdio.h> /* standard I/O library */
38 #include <string.h> /* C strings library */
39 #include <sys/timerfd.h> /* timerfd */
42 /* Help printing routine */
45 int main(int argc, char *argv[])
48 * Variables definition
51 struct itimerspec expiring;
53 * Input section: decode command line parameters
56 opterr = 0; /* don't want writing to stderr */
57 while ( (i = getopt(argc, argv, "h")) != -1) {
62 case 'h': /* help option */
63 printf("Wrong -h option use\n");
67 case '?': /* unrecognized options */
68 printf("Unrecognized options -%c\n",optopt);
70 default: /* should not reached */
74 /* ***********************************************************
76 * Options processing completed
80 * ***********************************************************/
81 /* There must be 0 remaing arguments */
82 if ( (argc-optind) != 0 ) {
83 printf("From %d arguments, removed %d options\n", argc, optind);
87 fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
88 expiring.it_interval.tv_sec=1;
89 expiring.it_interval.tv_nsec=0;
90 expiring.it_value.tv_sec=5;
91 expiring.it_value.tv_nsec=0;
92 if (timerfd_settime(fd, 0, expiring, NULL)) {
93 perror("Cannot set timer");
98 * routine to print usage info and exit
101 printf("Program testtimerfdfork : test timerfd across fork \n");
103 printf(" testtimerfdfork [-h] \n");
104 printf(" -h print this help\n");