As well as using the ncurses library to do the screen handling, if you want to update it "continuously" and "in real time" you're probably going to want to look into timers and signal handling, too. timer_create()
and timer_settime()
can get you a timer going, and then you can use sigaction()
to set a handler function to trap the SIGALRM
signal and do your updating.
EDIT: Here's some sample code, as requested:
#define TIMESTEP 200000000
timer_t SetTimer(void) {
struct itimerspec new_its;
struct sigevent sevp;
timer_t main_timer;
sevp.sigev_notify = SIGEV_SIGNAL;
sevp.sigev_signo = SIGALRM;
timer_create(CLOCK_REALTIME, &sevp, &main_timer);
new_its.it_interval.tv_sec = 0;
new_its.it_interval.tv_nsec = TIMESTEP;
new_its.it_value.tv_sec = 0;
new_its.it_value.tv_nsec = TIMESTEP;
timer_settime(main_timer, 0, &new_its, NULL);
return main_timer;
}
void SetSignals(void) {
struct sigaction sa;
/* Fill in sigaction struct */
sa.sa_handler = handler;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
/* Set signal handler */
sigaction(SIGALRM, &sa, NULL);
}
void handler(int signum) {
switch (signum) {
case SIGALRM:
update_stuff(); /* Do your updating here */
break;
}
}