Find the answer to your Linux question:
Results 1 to 3 of 3
I want to implement basic timer in linux, so i used signal function as like this, void sig_alarm(int flag) { printf("\nthis is next string"); return; } int main() { signal(SIGALRM, ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    50

    Implementing basic timer.

    I want to implement basic timer in linux, so i used signal function as like this,

    void sig_alarm(int flag)
    {
    printf("\nthis is next string");
    return;
    }

    int main()
    {
    signal(SIGALRM, sig_alarm);
    printf("\nthis is first string");
    alarm(10);
    return 0;
    }

    I want to show 2nd printf after 10 seconds. Is I missing something in this? It shows only first printf and then exits.

    Help Plz.!!

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Alarms (and other signals) are caught only while your program is actually running. What you've done is to set up a signal catcher, set up the alarm, and then exit your program. It's simply done computing.

    Give it something to do after the alarm() string, something that takes more than 10 seconds to complete.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    50
    Thanks Bill, I got it.!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...