X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=blobdiff_plain;f=sources%2Ftest_timerfdfork.c;fp=sources%2Ftest_timerfdfork.c;h=04fad750973f0726300a3e987fc530d5fc59e7fb;hb=bd8c369514b9f49a58fe22c095f5313a521e6ee2;hp=0000000000000000000000000000000000000000;hpb=193d612d40c5f81f5559ea6e11e70f6b6e51fb39;p=gapil.git diff --git a/sources/test_timerfdfork.c b/sources/test_timerfdfork.c new file mode 100644 index 0000000..04fad75 --- /dev/null +++ b/sources/test_timerfdfork.c @@ -0,0 +1,108 @@ +/* test_timerfdfork.c + * + * Copyright (C) 2011 Simone Piccardi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/**************************************************************** + * + * Program test_timerfdfork.c: + * Program to test timerfd behaviour across fork's + * + * Author: Simone Piccardi + * Apr. 2011 + * + * Usage: testtimerfdfork -h give all info's + * + ****************************************************************/ +/* + * Include needed headers + */ +#define _GNU_SOURCE +#include /* error definitions and routines */ +#include /* C standard library */ +#include /* unix standard library */ +#include /* standard I/O library */ +#include /* C strings library */ +#include /* timerfd */ +// #include + +/* Help printing routine */ +void usage(void); + +int main(int argc, char *argv[]) +{ +/* + * Variables definition + */ + int i, fd; + struct itimerspec expiring; + /* + * Input section: decode command line parameters + * Use getopt function + */ + opterr = 0; /* don't want writing to stderr */ + while ( (i = getopt(argc, argv, "h")) != -1) { + switch (i) { + /* + * Handling options + */ + case 'h': /* help option */ + printf("Wrong -h option use\n"); + usage(); + return -1; + break; + case '?': /* unrecognized options */ + printf("Unrecognized options -%c\n",optopt); + usage(); + default: /* should not reached */ + usage(); + } + } + /* *********************************************************** + * + * Options processing completed + * + * Main code beginning + * + * ***********************************************************/ + /* There must be 0 remaing arguments */ + if ( (argc-optind) != 0 ) { + printf("From %d arguments, removed %d options\n", argc, optind); + usage(); + } + + fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); + expiring.it_interval.tv_sec=1; + expiring.it_interval.tv_nsec=0; + expiring.it_value.tv_sec=5; + expiring.it_value.tv_nsec=0; + if (timerfd_settime(fd, 0, expiring, NULL)) { + perror("Cannot set timer"); + } + return 0; +} +/* + * routine to print usage info and exit + */ +void usage(void) { + printf("Program testtimerfdfork : test timerfd across fork \n"); + printf("Usage:\n"); + printf(" testtimerfdfork [-h] \n"); + printf(" -h print this help\n"); + + exit(1); +} +