generating timer


 
Thread Tools Search this Thread
Top Forums Programming generating timer
# 1  
Old 09-12-2003
Question 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;

myTimer.it_value.tv_sec = delay;
myTimer.it_value.tv_usec =0;

setitimer(ITIMER_REAL, &myTimer, );


Can anyone give me some idea how to debug my program ? and are there any good reference book i can read. Thanks
# 2  
Old 09-12-2003
timer/alarm

Heres a good reference on alarms and timers using interrupts:

http://www.gnu.org/manual/glibc-2.0..../libc_306.html
# 3  
Old 09-12-2003
Posting a couple of lines from a c program is not enough to do any good.

The only debugging tool that I ever use is to insert a printf statement at strategic points in my program to see what's happening. It's low tech, I know. But it actually works very well.
# 4  
Old 09-13-2003
Me too. But occasionally and to find out where a segmentation fault occurs I use gdb.

There is an official GDB manual, but usually I simply use the command-line help to view the help info of gdb commands.
# 5  
Old 09-15-2003
Further to what Perderabo said, I use a form of printf to debug my programs.

Rather than displaying messages to screen, I would write those same messages to a log file.

This could obviously mean a very large file, which will mean a performance degredation, so the logging (or tracing) is conditional on a configuration setting being activiated e.g. an environment variable or in an configuration (or ini) file or a flag on a database table.

A trace level could also be defined e.g. 9 for most detailed to 1 for the least detail.

Although creating a mechanism to log to a file will require more programming effort, it will be invaluable to you if you have developed your program and delivered it to a 'live' system where your development tools won't be available. You may not be able to predict when your fault is going to happen either, especially with background or daemon processes.

After you have put in the effort to create your new logging functions, you may want to encapsulate them into a library for use in future projects. To this end I believe many Unix systems will provide standard functions to allow you to write messages to the system log if you prefer.

Whether you are logging to a file or the screen or even using a debugger I would recommend you track the following features of your program:

1. When a function is called
2. When a function exits.
3. The input values, or paramters to functions
4. The return values, or parameters of functions
5. When a variable is first assigned.
6 When a variable changes

(Be sure to display all strings within quotes so you can see any whitespace in the string)

This should allow you to tackle most faults in your program.

MBB
# 6  
Old 09-16-2003
Quote:
Originally posted by Perderabo
Posting a couple of lines from a c program is not enough to do any good.

The only debugging tool that I ever use is to insert a printf statement at strategic points in my program to see what's happening. It's low tech, I know. But it actually works very well.
It's probably a better idea to use fprintf(stderr, ... ) so that any errors are IMMEDIATELY reported. Otherwise, your program may die before the stdout buffer makes it to the screen. I've had this happen MANY times where the last debugging line on the screen did NOT indicate where the program REALLY died. Either use stderr or use fflush() after writing to a log file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Timer as output

How do you set timer as output to the command line so that you get an output like Has been waiting for 5 seconds Has been waiting for 6 seconds ... Where only the number changes. (2 Replies)
Discussion started by: locoroco
2 Replies

2. 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

3. 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

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. AIX

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 Replies)
Discussion started by: Frank2004
2 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