LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-12-2006, 08:18 AM   #1
sachitha
Member
 
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
Timer signals in Unix..


i have written a program to use timer signals.. to understand timer signals..But it doesn't work..
i need to use timer signals in order to kill processes after the expiration of a specific time passed as a command line argument.
pls help me out
 
Old 03-12-2006, 08:21 AM   #2
sachitha
Member
 
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104

Original Poster
Rep: Reputation: 15
This is the coding i wrote

#include<stdio.h>
#include<sys/time.h>
#include<stdlib.h>
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue);
struct itimerval {
struct timeval it_interval; /* next value */
struct timeval it_value; /* current value */
};

int main(int argc, char *argv[])
{
int val,ret;
val=atoi(argv[1]);
ret=setitimer(ITIMER_VIRTUAL,val,2);
if (ret==0)
printf("timer expired\n");
sleep(5);
return 0;
}//main

int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue)
{struct timeval it_value;
it_value=value;
}//setitimer
 
Old 03-12-2006, 07:12 PM   #3
sachitha
Member
 
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104

Original Poster
Rep: Reputation: 15
i hope what i have written is clear.. please do help me out....
 
Old 03-13-2006, 05:09 AM   #4
stephenwalter
Member
 
Registered: Jul 2005
Location: india,coimbatore
Distribution: Fedora core 4
Posts: 85

Rep: Reputation: 15
Hello ,
For creating timers in linux you must use the system calls timer_create() and you must implement your call back function which will be invoked when the timer expires. To set the time for a timer you have to use timer_settime(). Iam not sure whether u have implemented it in this manner but i was not able to make out anything from your code . Hope this helps.

Regards,
S.Suresh Stephen
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
analog WaitForSingleObject for Unix or any interuptible timer Chris_tt Programming 2 02-07-2005 02:35 PM
!!! about signals !!! b2na Programming 4 02-04-2005 12:34 AM
!! about signals !!! b2na General 1 01-03-2005 04:37 PM
Signals Speek Programming 2 12-24-2004 04:58 AM
Capturing the signals from UNIX kernel Micha Agovic Programming 3 01-30-2002 07:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration