The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Timer aekaramg20 Shell Programming and Scripting 6 08-21-2008 09:47 AM
Timer for VNC foweja UNIX for Advanced & Expert Users 1 07-14-2005 10:31 AM
VNC Timer foweja Shell Programming and Scripting 0 07-13-2005 12:25 PM
timer k_oops9 Shell Programming and Scripting 3 11-08-2004 11:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-12-2003
Confuse Confuse is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 7
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 (permalink)  
Old 09-12-2003
andyj andyj is offline
Registered User
  
 

Join Date: Jul 2003
Location: UK
Posts: 27
timer/alarm

Heres a good reference on alarms and timers using interrupts:

http://www.gnu.org/manual/glibc-2.0..../libc_306.html
  #3 (permalink)  
Old 09-12-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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 (permalink)  
Old 09-12-2003
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
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 (permalink)  
Old 09-15-2003
mbb mbb is offline
Registered User
  
 

Join Date: Aug 2001
Location: UK
Posts: 104
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 (permalink)  
Old 09-16-2003
kowrip kowrip is offline
Registered User
  
 

Join Date: Sep 2003
Location: New Jersey
Posts: 32
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0