Question regarding SIGTERM

Started by svenvanhal, May 29, 2018, 12:59:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

svenvanhal

Dear Liviu, Volker,

Currently, I'm working on a C# wrapper for FET-CL which interfaces with a database, prepares input files, processes FET output, etc. I am trying to implement functionality that terminates fet-cl gracefully. Per your documentation, sending a SIGTERM signal would stop the timetable generation, write the intermediary results to disk and close the program.

However, on Windows, sending a SIGTERM signal is unsupported. See:
https://stackoverflow.com/questions/1216788/win32-api-analog-of-sending-catching-sigterm

and

https://msdn.microsoft.com/en-us/library/xdkz3x12.aspx
"The SIGILL and SIGTERM signals are not generated under Windows. They are included for ANSI compatibility."


What is your recommended way to stop fet-cl gracefully on Windows? If it's actually not possible, would you consider changing SIGTERM to:

SIGBREAK -- https://docs.microsoft.com/en-us/windows/console/ctrl-c-and-ctrl-break-signals

a native Windows signal on just Windows (https://stackoverflow.com/questions/813086/can-i-send-a-ctrl-c-sigint-to-an-application-on-windows)

or maybe listen on stdin for a predefined control sequence (e.g. we could send a /x3 character or maybe a string like "STOP")

Thanks in advance!

Kind regards,
Sven

Liviu Lalescu

#1
Hello, Sven,

I just reviewed the FET README file. I should have written "SIGINT" instead of "SIGKILL" (there is a single place in which this string appears). This will be corrected in the next FET version.

If you want to stop FET and do not care about the partial results (current and highest-stage timetables), and you want to stop FET as soon as possible, you can press Ctrl+C, Ctrl+Break, or "End task" (I checked on my Windows 10 and it works). I think this is the SIGINT signal working on Windows. This will not corrupt anything on the system, the only thing is that you might obtain some incomplete output files. FET-CL will stop immediately.

If you want to stop FET and need to obtain the partial results (current and highest-stage), you need to send FET the SIGTERM signal (this will take longer to terminate, depending on the input file). Since you said this was impossible on Windows (I did not know this), in this case we need to work on a solution. Let me know if this is the case and, maybe with the help of other users here on the forum we might solve this in a way (I do not know the best method to listen to stdin).

svenvanhal

Hi Liviu,

Thanks for your quick reply!

The SIGINT signal is working perfectly on Windows and this is the approach I am currently using. However, I would indeed like to use the partial results. I think the easiest solution (and compatible with all platforms) would be to change from SIGTERM to SIGBREAK.

So when I would press CTRL+C in the console, I send a SIGINT signal and fet-cl terminates immediately.
If I would press CTRL+BREAK, fet-cl writes the partial results to the disk and terminates thereafter.

I think you can keep the SIGTERM behaviour for backwards compatibility. I'm not fluent in c++, but you might add after line 1305 in fet.cpp:

signal(SIGBREAK, terminate);

Liviu Lalescu

Sorry, but SIGBREAK seems nonstandard: http://www.cplusplus.com/reference/csignal/signal/ , and also the fact that your suggested code does not compile under GNU/Linux (I did not try if it compiles under Windows).

svenvanhal


Liviu Lalescu

Quote from: svenvanhal on May 29, 2018, 03:25:41 PM
Would this be an appropriate solution? https://stackoverflow.com/questions/181413/how-to-handle-a-ctrl-break-signal-in-a-command-line-interface

Very nice :)

I think I will use this. So, on GNU/Linux (and Mac OS X?) the users will use SIGTERM and on Windows SIGBREAK.

I will wait for other possible suggestions from the users of the forum and maybe for Qt 5.11.1 and make a FET release.

I will try this now and put a snapshot for you to test. I will announce here.

svenvanhal

Sounds good, thank you very much!

Liviu Lalescu

I have put a new snapshot, seems to be working OK. Please let me know.

The link to the forum post about the snapshot: https://lalescu.ro/liviu/fet/forum/index.php?topic=3676.0

After the official release, the snapshot will be removed from the downloads section.

svenvanhal


Liviu Lalescu

Thank you for the suggestion and report! :)

Liviu Lalescu

I just released the new official version; thank you for the report and the suggestion!