how to implement timer


 
Thread Tools Search this Thread
Operating Systems AIX how to implement timer
# 1  
Old 06-07-2004
how to implement timer

anyone can help me how to implement the timer on AIX?
I tried with 'setitimer' and its related functions, but it does not work correctly,the program exited each time.
thanks
# 2  
Old 06-09-2004
The following is my code:

#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

volatile int time_has_come;
time_t cur_time;

void handler(int signal)
{
//time_has_come = 1;
cur_time = time(NULL);
printf("!!!!!!! %s\n", ctime(&cur_time));
return;
}

struct itimerval interval;

int main(int argc, char * const argv[])
{
//interval.it_interval.tv_sec = 0;
interval.it_interval.tv_sec = 1;
interval.it_interval.tv_usec = 0;
interval.it_value.tv_sec = 10;
interval.it_value.tv_usec = 0;
signal(SIGVTALRM, handler);
(void) setitimer(ITIMER_VIRTUAL, &interval, NULL);
time_has_come = 0;
cur_time = time(NULL);
printf("start time =%s\n", ctime(&cur_time));
while (1) {
if (time_has_come) {
cur_time = time(NULL);
printf("time_has_come = %d exit time = %s!\n", time_has_come, ctime(&cur_time));
exit(0);
}

}
}


The above timer is active just only once and the program exit, the message " Virtual timer expired" returned.

It has the same result if we use SIGALRM signal.
# 3  
Old 06-09-2004
Thanks Driver, I will try it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Timer

is there a timer function in unix without using C? for example i want to display a message after 5 seconds how do i do that? (2 Replies)
Discussion started by: khestoi
2 Replies

2. Shell Programming and Scripting

Timer

Is there a way to make a timer? E.g Please give the seconds... ... (6 Replies)
Discussion started by: aekaramg20
6 Replies

3. Programming

How to implement polling for a function using timer in C?

Hi, Can you please help me in implementing a timer based polling for function in C? ie. the function should be called in say 30secs(when 30secs has lapsed). Thanks (7 Replies)
Discussion started by: naan
7 Replies

4. UNIX for Dummies Questions & Answers

timer interrupt

hello all since a process running in kernel mode cannnot be preempted by any other process what would be the status of Timer interrupt that occurs when the time quantum of a process is elapsed? thanks (2 Replies)
Discussion started by: compbug
2 Replies

5. UNIX for Advanced & Expert Users

Timer for VNC

Hello fellows, I am new in this forum, i would appreciate your assistance. I need a timming system for my vnc desktops (Cybercafe timer stuff). Each unix user login to my server only with vnc, and i want to write a program that can generate timer tickets and have control on the time used for... (1 Reply)
Discussion started by: foweja
1 Replies

6. Shell Programming and Scripting

VNC Timer

Hello fellows, I am new in this forum, i would appreciate your assistance. I need a timming system for my vnc desktops (Cybercafe timer stuff). Each unix user login to my server only with vnc, and i want to write a program that can generate timer tickets and have control on the time used for... (0 Replies)
Discussion started by: foweja
0 Replies

7. Shell Programming and Scripting

timer

Hi all, Wanted to a create a shell script ----------------------------------------------------------------------- 1) which when called will start a timer and wait for 48 hours. after 48 hours it will call some function(say XYZ) 2) Whenever this shell script is called (can be called... (3 Replies)
Discussion started by: k_oops9
3 Replies

8. Shell Programming and Scripting

writing a timer

Hi!, My shell script takes a quite a long time to execute.. Nothing appears on the screen during this period.. User are left guessing... whats going on???????????? Any ideas on how to create a small timer script which print a word on screen say " wait.. Program running" after every 10 seconds... (3 Replies)
Discussion started by: jyotipg
3 Replies

9. Programming

generating timer

I'm trying generate an interrupt every 1 seconds using itimer and My clock is not running. This is what i did : printf("about to sleep for 1 second \n"); signal(SIGALRM, wakeup); //myTimer.it_interval.tv_sec=0; //myTimer.it_interval.tv_usec =0; ... (5 Replies)
Discussion started by: Confuse
5 Replies

10. Post Here to Contact Site Administrators and Moderators

reply timer

Neo, can u please shorten the reply timer to like 1 min or so. It is prolly just me but i end up passing on replying to posts due to i hate waiting for my timer to reset w/ a 2.5 mins wait. (2 Replies)
Discussion started by: Optimus_P
2 Replies
Login or Register to Ask a Question