3 * Copyright (C) 2012 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 * File sleep-me.c: An example on how NOT to wait for a time...
22 * thanks to M.E. for suggesting it (for serious) some time ago in the
23 * FLUG (Firenze Linux User Group) mailing list
25 * Author: S. Piccardi Jan. 2012
27 *****************************************************************************/
28 #include <sys/types.h> /* primitive system data types */
29 #include <sys/stat.h> /* file characteristics constants and functions */
30 #include <unistd.h> /* unix standard library */
38 * Wait for N second (burning CPU...)
40 /* Help printing routine */
42 /* computation function for dir_scan */
43 int main(int argc, char *argv[])
48 * Input section: decode command line parameters
51 opterr = 0; /* don't want writing to stderr */
52 while ( (i = getopt(argc, argv, "h")) != -1) {
57 case 'h': /* help option */
58 printf("Wrong -h option use\n");
62 case '?': /* unrecognized options */
63 printf("Unrecognized options -%c\n",optopt);
65 default: /* should not reached */
69 /* ***********************************************************
71 * Options processing completed
75 * ***********************************************************/
76 if ((argc - optind) != 1) { /* There must be remaing parameters */
77 printf("Wrong number of arguments %d\n", argc - optind);
80 printf("I will burn CPU for %s seconds\n", argv[1]);
82 printf("wait %d sec.\n", wait);
84 end = time(NULL)+ wait;
88 printf("now %d, end %d sec.\n",now, end);
96 * routine to print usage info and exit
99 printf("Program sleep-me: wait burning CPU cicles \n");
101 printf(" sleep-me [-h] -t sec \n");
102 printf(" -t sec wait sec seconds\n");
103 printf(" -h print this help\n");