mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Software > Mlucas

Reply
 
Thread Tools
Old 2019-02-16, 19:17   #1
ewmayer
2ω=0
 
ewmayer's Avatar
 
Sep 2002
República de California

1151810 Posts
Default v18 pre-release discussion

One of my main beta testers, GordP, has convinced me to add signal-catching (e.g. instead of just dying on ctrl-c, complete the current iteration, write savefiles and exit gracefully) to the v18 code upgrades - I have that working, the remaining question is which of the standard set of signals - that is, the catchable ones thereof - the program should listen for. On my Mac, 'man signal' offers the following smorgasbord:
Code:
1     SIGHUP       terminate process    terminal line hangup
2     SIGINT       terminate process    interrupt program
3     SIGQUIT      create core image    quit program
4     SIGILL       create core image    illegal instruction
5     SIGTRAP      create core image    trace trap
6     SIGABRT      create core image    abort program (formerly SIGIOT)
7     SIGEMT       create core image    emulate instruction executed
8     SIGFPE       create core image    floating-point exception
9     SIGKILL      terminate process    kill program
10    SIGBUS       create core image    bus error
11    SIGSEGV      create core image    segmentation violation
12    SIGSYS       create core image    non-existent system call invoked
13    SIGPIPE      terminate process    write on a pipe with no reader
14    SIGALRM      terminate process    real-time timer expired
15    SIGTERM      terminate process    software termination signal
16    SIGURG       discard signal       urgent condition present on socket
17    SIGSTOP      stop process         stop (cannot be caught or ignored)
18    SIGTSTP      stop process         stop signal generated from keyboard
19    SIGCONT      discard signal       continue after stop
20    SIGCHLD      discard signal       child status has changed
21    SIGTTIN      stop process         background read attempted from control terminal
22    SIGTTOU      stop process         background write attempted to control terminal
23    SIGIO        discard signal       I/O is possible on a descriptor (see fcntl(2))
24    SIGXCPU      terminate process    cpu time limit exceeded (see setrlimit(2))
25    SIGXFSZ      terminate process    file size limit exceeded (see setrlimit(2))
26    SIGVTALRM    terminate process    virtual time alarm (see setitimer(2))
27    SIGPROF      terminate process    profiling timer alarm (see setitimer(2))
28    SIGWINCH     discard signal       Window size change
29    SIGINFO      discard signal       status request from keyboard
30    SIGUSR1      terminate process    User defined signal 1
31    SIGUSR2      terminate process    User defined signal 2
ewmayer is offline   Reply With Quote
Old 2019-02-16, 19:39   #2
Mark Rose
 
Mark Rose's Avatar
 
"/X\(‘-‘)/X\"
Jan 2013

1011001001112 Posts
Default

I would have SIGTERM terminate gracefully. SIGINT should terminate gracefully, but terminate expediently if another SIGINT is received (mfaktc has this behaviour). SIGHUP, SIGKILL and SIGPIPE should terminate expediently.

SIGUSR1 and SIGUSR2 are often used to cause a process to reread configuration files or to gracefully restart.
Mark Rose is offline   Reply With Quote
Old 2019-02-16, 21:17   #3
preda
 
preda's Avatar
 
"Mihai Preda"
Apr 2015

5×239 Posts
Default

On Linux on Ctrl-C I get SIGINT, and that's what I use to stop gracefully.
preda is offline   Reply With Quote
Old 2019-02-16, 21:28   #4
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

3·23·83 Posts
Default

CTRL-\ sends a SIGQUIT in Linux terminals. Ping uses this to display the current statistics and continues to run.
retina is offline   Reply With Quote
Old 2019-02-16, 21:57   #5
ewmayer
2ω=0
 
ewmayer's Avatar
 
Sep 2002
República de California

2×13×443 Posts
Default

Quote:
Originally Posted by Mark Rose View Post
I would have SIGTERM terminate gracefully. SIGINT should terminate gracefully, but terminate expediently if another SIGINT is received (mfaktc has this behaviour). SIGHUP, SIGKILL and SIGPIPE should terminate expediently.
How does one listen for multiple SIGINTs (ctrl-c) in succession? Should one also define some pause-for-X-milliseconds-after-first-SIGINT delay to listen for a second SIGINT rather than performing an immediate savefiles-and-exit?
ewmayer is offline   Reply With Quote
Old 2019-02-16, 22:42   #6
TheJudger
 
TheJudger's Avatar
 
"Oliver"
Mar 2005
Germany

33×41 Posts
Default

Hi

Quote:
Originally Posted by ewmayer View Post
How does one listen for multiple SIGINTs (ctrl-c) in succession? Should one also define some pause-for-X-milliseconds-after-first-SIGINT delay to listen for a second SIGINT rather than performing an immediate savefiles-and-exit?
just add a counter to your signal handler. Hint: on Windows you have to re-register your signal handler once it was triggered.

Oliver
TheJudger is offline   Reply With Quote
Old 2019-02-17, 00:12   #7
GP2
 
GP2's Avatar
 
Sep 2003

258010 Posts
Default

Quote:
Originally Posted by Mark Rose View Post
I would have SIGTERM terminate gracefully. SIGINT should terminate gracefully, but terminate expediently if another SIGINT is received (mfaktc has this behaviour). SIGHUP, SIGKILL and SIGPIPE should terminate expediently.

SIGUSR1 and SIGUSR2 are often used to cause a process to reread configuration files or to gracefully restart.
As far as I know, SIGKILL can't be caught at all.

The behavior of SIGINT you describe is specific to mfaktc because one CTRL-C means "stop after finishing this factor class", which may take a while, and a second CTRL-C means "no, really stop right now". With programs like mprime and Mlucas, normally writing out an LL or PRP savefile is extremely quick, just a few dozen MB, so the issue doesn't really arise, unless maybe you have a problem with a networked file system.

SIGHUP should terminate gracefully. It probably just means that your terminal session ended while the program was running. For instance if you are running a program in an ssh terminal window on your PC, and your PC went to sleep from inactivity. You can avoid that happening by running the program in screen or a similar utility, or by remembering to run the program with nohup (or run disown on the program if it's running in the background).

Probably everything should just terminate gracefully, because "graceful" and "expedient" amount to the same thing here. All you have to do is write out a small savefile, and there's no reason not to unless you have some reason to believe your data has become corrupted and should not be saved.

Last fiddled with by GP2 on 2019-02-17 at 00:13
GP2 is offline   Reply With Quote
Old 2019-02-17, 01:50   #8
Mark Rose
 
Mark Rose's Avatar
 
"/X\(‘-‘)/X\"
Jan 2013

B2716 Posts
Default

Quote:
Originally Posted by GP2 View Post
Probably everything should just terminate gracefully, because "graceful" and "expedient" amount to the same thing here.
Yeah. I'm thinking the difference is finishing a calculation round rather than interrupting it.
Mark Rose is offline   Reply With Quote
Old 2019-02-18, 03:42   #9
kladner
 
kladner's Avatar
 
"Kieren"
Jul 2011
In My Own Galaxy!

2·19·263 Posts
Default

Quote:
Originally Posted by Mark Rose View Post
Yeah. I'm thinking the difference is finishing a calculation round rather than interrupting it.
That has always been my understanding. What I have not understood is the urgency to quit the program. I think that work on the current class is lost in an immediate shutdown. Unless the per-class time is really inconveniently long, why not let it finish?
kladner is offline   Reply With Quote
Old 2019-02-18, 07:55   #10
SELROC
 

660510 Posts
Default

Quote:
Originally Posted by preda View Post
On Linux on Ctrl-C I get SIGINT, and that's what I use to stop gracefully.

If you run multiple instances of a program, for example gpuowl, there is another way to stop the running instances:


Code:
pkill -int openowl

will stop all instances of openowl gracefully letting them save checkpoints.
  Reply With Quote
Old 2019-02-18, 19:57   #11
ewmayer
2ω=0
 
ewmayer's Avatar
 
Sep 2002
República de California

263768 Posts
Default

I've fiddled the code to catch SIGINT, SIGTERM and SIGHUP, print info re. the caught signal and exit gracefully. Users can still use ctrl-\ to force immediate-exit or ctrl-z to suspend the process followed by 'kill [pid]'. There is no multiple-signals-in-a-row handling, I just don't see the need for it in the context of the kind of work Mlucas does.
ewmayer is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Next GMP release? Andi47 GMP-ECM 6 2007-11-26 07:29
v24.13 release candidate 1 Prime95 Software 13 2005-07-14 23:29
V24.12 release candidate 3 Prime95 Software 45 2005-07-02 19:13
V24.12 Release 1 Crashing on P4 M njcroquet1 Software 8 2005-06-24 14:40
Release of Exponents nitro Lone Mersenne Hunters 3 2004-01-02 06:41

All times are UTC. The time now is 02:30.

Tue Sep 22 02:30:10 UTC 2020 up 11 days, 23:41, 0 users, load averages: 1.79, 1.55, 1.57

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.