Тема: Таймер для Ubuntu на С
Доброго дня!
Я розпочав писати таймер для ОС Ubuntu (використовую її).
Функції такого таймера в майбутньому будуть такими:
1) запуск з ОС
2) робота у фоні 
3) через N проміжок часу виводиться потрібне повідомлення.
Про графічний інтерфейс ще не кажу, тому що ще мову С погано знаю.
Поки що написав лише сам таймер з інтерфейсом користувача у терміналі. Пишу в різних файлах.
Проблема з'явилась ось в чому:
після запуску таймера процесор навантажується на 50 %, хоча перед цим навантаження на процесорі (при відкритому VIM, Google Chrome та плеєром) було близько 5 - 10 %
main.c - керує програмою
#include "prototypes.h"
/* prototypes.h - містить прототипи функцій та константи
 * variant_of_timer - варіанти роботи таймера
 *      вибір кількості повторювань таймера
 *      вибір часу роботи таймера
 * якщо була вибрана (введена власноруч або вибраний варінт) 
 * кількість повторювань таймера відмінна від ALWAYS то виконується 
 * цикл while (numbres_of_timer--)
 * в іншому випадку таймер повторюється постійно
 * timer - виклик таймера
 */
int main (void){
    int numbers_of_timer = 0;
    float time_target_seconds = 0;
    variant_of_timer (&numbers_of_timer, &time_target_seconds);
    
    if (numbers_of_timer > 0)
        while (numbers_of_timer--)
            timer (time_target_seconds);
    else while (1)
        timer (time_target_seconds);
    return 0;
}prototypes.h - знаходяться константи та прототипи функцій
#define FIVE 5
#define TEN 10
#define TWENTY 20
#define ALWAYS 0
#define ONE_HOUR 3600
#define TWO_HOUR 7200
#define STARS "\n*********************"
void variant_of_timer (int * number_of_timer, float * time_target);
int number_times_of_timer (void);
float enter_time_seconds (void);
void timer (float time_target_seconds);
/* FIVE, TEN, TWENTY, ALWAYS - кількість повторювань таймера
 * ONE_HOUR, TWO_HOUR - одна і дві години (у секундах) відповідно 
 * STARS - зірочки, для інтерфейсу
 * variant_of_timer - вибір кількості повторювань та часу роботи таймеру
 * number_times_of_timer - введення кількості повторювань таймеру
 * enter_time_seconds - введення часу роботи таймера у секундах
 * timer - таймер
 */ variant_of_timer.c - вибір режиму роботи таймера
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "prototypes.h"
/* вибір режиму роботи таймеру */
void variant_of_timer (int * p_number_timer, float * p_time_target){
    char var;
    bool todo = true;
    puts (STARS);
    printf (" Timer has variants!");
    puts (STARS);
    printf ("You can choose how many times the timer runs:\n");
    while (todo){
        printf ("1 - 5 times.\n");
        printf ("2 - 10 times.\n");
        printf ("3 - 20 times.\n");
        printf ("4 - timer runs always.\n");
        printf ("5 - enter times.\n");
        printf ("Enter q to exit.\n");
        scanf ("%c", &var);
        switch (var){
            case '1':
                *p_number_timer = FIVE;
                todo = false;
                break;
            case '2':
                *p_number_timer = TEN;
                todo = false;
                break;
            case '3':
                *p_number_timer = TWENTY;
                todo = false;
                break;
            case '4':
                *p_number_timer = ALWAYS;
                todo = false;
                break;
            case '5':
                *p_number_timer = number_times_of_timer ();
                todo = false;
                break;
            case 'q':
                exit(1);
                break;
            default:
                printf ("Please, choose variant or enter q to exit!\n");
                break;
        }
    }
    while (getchar() != '\n')
        ;
    todo = true;
    system ("clear");
    if (*p_number_timer != ALWAYS)
        printf ("\n\nTimer will be runs %d times!\n\n", *p_number_timer);
    else printf ("\n\nTimer will be runs always!\n\n");
    printf ("You can choose how much time timer work:\n");
    while (todo){
        printf ("1 - 1 hour.\n");
        printf ("2 - 2 hour.\n");
        printf ("3 - enter time timer work.\n");
        printf ("Enter q to exit.\n");
        scanf ("%c", &var);
        switch (var){
            case '1':
                *p_time_target = ONE_HOUR;
                todo = false;
                break;
            case '2':
                *p_time_target = TWO_HOUR;
                todo = false;
                break;
            case '3':
                *p_time_target = enter_time_seconds ();
                todo = false;
                break;
            case 'q':
                exit (1);
            default:
                printf ("Please, choose variant or enter q to exit!\n");
                break;
        }
    }
}enter_numbers.c - введення кількості повторювань та часу роботи таймера
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/* введення кількості повторювань таймера */
int number_times_of_timer (void){
    char ch;
    int times_of_timer = 0;  
    printf ("How much times do you want to run timer?\n");
    printf ("Enter times (or enter q to exit): ");
    while ((scanf ("%d", ×_of_timer)) != true || times_of_timer < 0){
        if (times_of_timer < 0){
            printf ("Please, enter times (only positive numbers): "); 
            times_of_timer = 0;
        }else if ((ch = getchar ()) != 'q'){
            if (ch != 'a'){
                while ((ch = getchar ()) != '\n')
                    ;
                printf ("Please, enter times (only numbers) or enter q to exit: "); 
            }else{
                times_of_timer = -1;
                break;
            }
        }else exit (1);
    }
    return times_of_timer;
}
/* введення часу роботи таймеру у секундах */ 
float enter_time_seconds (void){
    char ch;
    float time_sec;
    printf ("Enter time (seconds) for end of timer (enter q to exit): ");
    while ((scanf ("%f", &time_sec)) != true){
        if ((ch = getchar ()) == 'q')
            exit (2);
        else while ((ch = getchar ()) != '\n')
            ;
        printf ("This symbols are not numbers! Please enter number or enter q to exit: ");
    }
    return time_sec;
}timer.c -  таймер
/* timer.c - описується робота самого таймеру */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "prototypes.h"
/* timer - сам таймер  */ 
void timer (float time_target_seconds){
    int time_start_processor, time_end_processor; 
    float time_result_seconds = 0;
    time_start_processor = clock ();
    do{
        time_end_processor = clock ();
        time_result_seconds = (float)(time_end_processor - time_start_processor) / CLOCKS_PER_SEC;
    }while (time_result_seconds < time_target_seconds);    
    printf ("End of timer!\n");
}Makefile
project:
    gcc main.c variant_of_timer.c enter_numbers.c timer.c