progsys:index
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| progsys:index [2018/10/26 14:43] – [Ctrl-C] orel | progsys:index [2024/03/18 15:06] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 995: | Line 995: | ||
| int main(void) | int main(void) | ||
| { | { | ||
| - | | + | signal(SIGINT, |
| - | | + | |
| if (fork() == 0) | if (fork() == 0) | ||
| Line 1014: | Line 1013: | ||
| + | ==== Timeout ==== | ||
| + | |||
| + | <code C executer-avant-delai.c> | ||
| + | |||
| + | #define _GNU_SOURCE | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | static struct sigaction sa, old; | ||
| + | static sigjmp_buf env; | ||
| + | |||
| + | static void myalarm(int sig) | ||
| + | { | ||
| + | printf(" | ||
| + | siglongjmp(env, | ||
| + | } | ||
| + | |||
| + | int executer_avant_delai( void (*fun)(void *), void *parametre, int delai_en_seconde) | ||
| + | { | ||
| + | int ret = 1; | ||
| + | sa.sa_handler = myalarm; | ||
| + | sa.sa_flags = 0; // SA_RESETHAND; | ||
| + | sigemptyset(& | ||
| + | sigaction(SIGALRM, | ||
| + | |||
| + | alarm(delai_en_seconde); | ||
| + | if(sigsetjmp(env, | ||
| + | fun(parametre); | ||
| + | else | ||
| + | ret = 0; // alarm | ||
| + | alarm(0); | ||
| + | sigaction(SIGALRM, | ||
| + | return ret; | ||
| + | } | ||
| + | </ | ||
progsys/index.1540565034.txt.gz · Last modified: 2024/03/18 15:05 (external edit)
