| |

VerySource

 Forgot password?
 Register
Search
View: 887|Reply: 5

How to set the timer

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-23 13:00:01
| Show all posts |Read mode
How to set a timeout. If the execution time exceeds this time during the task execution, the task execution fails. How can the boss solve it?
    thank you very much!
Reply

Use magic Report

0

Threads

63

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-5-5 16:45:01
| Show all posts
alarm (some time);

Capture SIGALRM
Reply

Use magic Report

0

Threads

78

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-8 18:45:01
| Show all posts
SetTimer (/ * time * /);

When the time is up, the OnTime function is triggered,
Just complete the exit here. . . . . . . . . . . .
Reply

Use magic Report

1

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-9 13:45:01
| Show all posts
Add what is said upstairs!
#include <setjmp.h>
#define TIMEOUT 5
static jmp_buf env;
static void sig_timeout (int sig)
{
        longjmp (env, 1);
}
main ()
{
        int num;
        signal (SIGALRM, sig_timeout);
        if (setjmp (env)! = 0)
        {
                printf ("Time out !!\n");
                exit (-1);
        }
        printf ("please input a num !!\n");
        alarm (TIMEOUT);
        scanf ("% d",&num);
        alarm (0);
        printf ("u enter a num in time !!\nexit !!\n");
}
Reply

Use magic Report

1

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-9 15:45:01
| Show all posts
#include <signal.h>
#include <stdio.h>
Reply

Use magic Report

0

Threads

8

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-14 11:25:32
| Show all posts
WeChat zhu299 is free to play c
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list