- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Trouble with timer and sleep
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-31-2009 09:44 PM
тАО08-31-2009 09:44 PM
Appreciate your assistance,thank you!!
#include
#include
#include
void sighandle(int);
static sigjmp_buf s_env;
void my_business()
{
/* call the real service function */
for(int i = 0; i < 2147483647;i ++){
rc = rc + i;
//sleep(1);
}
}
sigjmp_buf *_px_get_jmpbuf(void)
{
return &s_env;
}
int main() {
// Get system call result to determine successful or failed
int res = 0;
int rc = 0;
// Register printMsg to SIGALRM
struct itimerval tick;
struct sigaction action, oldaction;;
action.sa_flags = 0;
action.sa_handler = sighandle;
sigfillset(&action.sa_mask);
sigaction(SIGALRM, &action, &oldaction);
//sigaction(SIGINT, &action, &oldaction);
// Initialize struct
memset(&tick, 0, sizeof(tick));
// Timeout to run function first time
tick.it_value.tv_sec = 5; // sec
tick.it_value.tv_usec = 0; // micro sec.
// Interval time to run function
tick.it_interval.tv_sec = 1;
tick.it_interval.tv_usec = 0;
// Set timer, ITIMER_REAL : real-time to decrease timer,
//send SIGALRM when timeout
res = setitimer(ITIMER_REAL, &tick, NULL);
if (res) {
printf("Set timer failed!!\n");
}
// Always sleep to catch SIGALRM signal
if(sigsetjmp(s_env, 1) == 0)
{
my_business();
printf("business end ");
}
else
{
printf("business interupt");
}
return 0;
}
void sighandle(int sig) {
if (sig != SIGALRM){
printf("Receive SIG = %d\n",sig);
return;
}
printf("Receive SIG\n");
siglongjmp(*_px_get_jmpbuf(), 1);
}
Solved! Go to Solution.
- Tags:
- sleep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-31-2009 10:21 PM
тАО08-31-2009 10:21 PM
Re: Trouble with timer and sleep
The use of the nanosleep() function has no effect on the action or blockage of any signal.
- Tags:
- nanosleep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-31-2009 10:28 PM
тАО08-31-2009 10:28 PM
Re: Trouble with timer and sleep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2009 01:06 PM
тАО09-01-2009 01:06 PM
Re: Trouble with timer and sleep
I tried doing this but it didn't work:
int ret = sleep(1);
if (ret != 0) {
printf("Assume SIGALRM on sleep\n");
siglongjmp(*_px_get_jmpbuf(), 1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2009 08:13 PM
тАО09-01-2009 08:13 PM
Re: Trouble with timer and sleep
1-void my_business()
2-{
3- int ret = 0;
4- int rc;
5-
6- /* call the real service function */
7- for(int i = 0; i < 2147483647;i ++){
8- rc = rc + i;
9- ret = sleep(2);
10- if(ret != 0){
11- printf("sleep interrupted!\n");
12- siglongjmp(*_px_get_jmpbuf(), 1);
13- }
14- }
15-}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-01-2009 09:52 PM
тАО09-01-2009 09:52 PM
Re: Trouble with timer and sleep
I get both.
You may want to add this after the printf:
fflush(stdout);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2009 12:02 AM
тАО09-02-2009 12:02 AM
Re: Trouble with timer and sleep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2009 12:27 AM
тАО09-02-2009 12:27 AM
Re: Trouble with timer and sleep
tv.tv_sec=1;
tv.tv_usec=0;
select(0,0,0,0,&tv);
---> those 2 don't any sideffect over sigalarm.
else you should probably
alarm(0); just before printf end of business
or a longjump
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2009 12:35 AM
тАО09-02-2009 12:35 AM
Re: Trouble with timer and sleep
Well, sleep seems to block SIGALRM. I don't know about VTALRM? Or more importantly how to enable it.
You could just fool the user by creating your own version of sleep that calls nanosleep.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2009 01:33 AM