Results 1 to 5 of 5

Thread: Timer and alarm in C / Java

  1. #1
    Join Date
    Nov 2009
    Posts
    45

    Timer and alarm in C / Java

    Hello,
    I would like to use a timer and an alarm function in C or in java. Here is my code, it is giving me an error, if you can then please help me with this
    Here is the code
    Code:
    void hd (void)
    (
    ...
    function(); ...
    )
     
    void function()
    (
    int timeout 30; ...
    (void) signal( SIGALRM, sigc ); ...
    (void) alarm( timeout ); ...
    )
     
    static void sigc( int sig )
    (       
    	(void) fprintf( stderr, "% s:% s - timed out\ n", argv0, url ); exit( 1 );
    )

  2. #2
    Join Date
    Mar 2010
    Posts
    338

    Re: Timer and alarm in C / Java

    Even I do have a similar kind of a problem. Look at it before I had dislodged, I try always to a minimum before search. By cons I post because I am not sure to have all understood the operation. What I'd like to know how it will behave the line:
    Code:
    (Void) alarm (timeout);
    Located in a sub function of hand but is reminded regularly. When I pass on this question to AC zero timeout each time, but if I pass in the function after the timeout what happens. It will stop the program?

  3. #3
    Join Date
    Dec 2009
    Posts
    178

    Re: Timer and alarm in C / Java

    Here is the code that can help you
    Code:
    sigc cntal;
     
    void galarm(int numSig) (
      siglongjmp( cntal, 1); / * connection has sigsetjmp () returning a * /
    )
     
    int hand(void) (
     
      int i;
     
    / * Installation the handler for SIGALRM galarm * /
     
      signal(SIGALRM, galarm); 
     
    / * Processing * /
     
      printf("You have five seconds to enter an integer\ n");
     
    / * Memorization of execution context * /
     
      if (! sigsetjmp(cntal, 1)) ( / * first pass * /
        alarm(5);     / * Set up the timer * /
        scanf("% d", & i); alarm(0);  / * seizure effected, we cancel the timer * /
        printf("OK:% s entered\ n", i);
      )
      else (
        printf("Nothing entered. Bye!\ n");
      )
     
      return(0);

  4. #4
    Join Date
    Nov 2009
    Posts
    359

    Re: Timer and alarm in C / Java

    Here are few tips for you
    sigtmp (buffer, ...) ---> during the call, saves the execution context in the buffer and returns 0.
    sigjmp (buffer, value) ---> connection to sigtmp () corresponding to the buffer passed as parameter. At this time, siftmp () returns the value sent by sigtmop (in the example, 1)
    I hope I was clear enough, the jump is triggered when the timer has reached the end of five seconds and the processing function is called salarm.

  5. #5
    Join Date
    Dec 2009
    Posts
    178

    Re: Timer and alarm in C / Java

    The functions and alarm signal functions as any Linux systems in particular and embedded on any type of processor?. Because apparently in my case, development on embedded Linux based ARM processor, the functions do nothing. The program is compiled without error or warning on this subject, by cons timeout function does nothing. In clear, even if the timeout elapsed alarm is registered in the program is proceeding normally.

Similar Threads

  1. Problem using Java.util.Timer
    By Gokul20 in forum Software Development
    Replies: 7
    Last Post: 09-09-2010, 10:20 PM
  2. Error while using the timer class in Java
    By ScarFace 01 in forum Software Development
    Replies: 4
    Last Post: 27-07-2010, 01:47 AM
  3. Help for Timer examples in Java
    By Feng in forum Software Development
    Replies: 5
    Last Post: 24-07-2010, 03:36 AM
  4. Execute timer service in java
    By Messenger in forum Software Development
    Replies: 4
    Last Post: 20-07-2010, 01:27 PM
  5. Java - System Tray with timer
    By Anthony12 in forum Software Development
    Replies: 4
    Last Post: 20-07-2010, 11:58 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,715,427,519.77834 seconds with 17 queries