<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[signal(): undefined behavior?]]></title><description><![CDATA[<p>Hi,</p>
<p>Ich zitiere <a href="http://en.cppreference.com/w/cpp/utility/program/signal" rel="nofollow">http://en.cppreference.com/w/cpp/utility/program/signal</a> :</p>
<blockquote>
<p>If the signal handler is called NOT as a result of std::abort or std::raise, the <strong>behavior is undefined if</strong></p>
<p><strong>the signal handler calls any function within the standard library</strong>, except std::abort, std::_Exit, std::quick_exit, or std::signal with the first argument not being the number of the signal currently handled.<br />
<strong>the signal handler refers to any object with static</strong> or thread-local(since C++11) storage duration that is not std::atomic(since C++11) or volatile std::sig_atomic_t.</p>
</blockquote>
<p>Ouch? Ich darf also im Handler keinen log mit fstream schreiben? Verstehe ich das richtig? Meine Logfunktion hat dazu noch eine static-Variable <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Ist doch doof! Warum diese Einschränkung? Vor Ende der main() darf man das ja auch noch tun...</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/335349/signal-undefined-behavior</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 19:36:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/335349.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 15 Nov 2015 16:07:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to signal(): undefined behavior? on Sun, 15 Nov 2015 16:07:54 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>Ich zitiere <a href="http://en.cppreference.com/w/cpp/utility/program/signal" rel="nofollow">http://en.cppreference.com/w/cpp/utility/program/signal</a> :</p>
<blockquote>
<p>If the signal handler is called NOT as a result of std::abort or std::raise, the <strong>behavior is undefined if</strong></p>
<p><strong>the signal handler calls any function within the standard library</strong>, except std::abort, std::_Exit, std::quick_exit, or std::signal with the first argument not being the number of the signal currently handled.<br />
<strong>the signal handler refers to any object with static</strong> or thread-local(since C++11) storage duration that is not std::atomic(since C++11) or volatile std::sig_atomic_t.</p>
</blockquote>
<p>Ouch? Ich darf also im Handler keinen log mit fstream schreiben? Verstehe ich das richtig? Meine Logfunktion hat dazu noch eine static-Variable <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Ist doch doof! Warum diese Einschränkung? Vor Ende der main() darf man das ja auch noch tun...</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2475537</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2475537</guid><dc:creator><![CDATA[linux_newbe]]></dc:creator><pubDate>Sun, 15 Nov 2015 16:07:54 GMT</pubDate></item><item><title><![CDATA[Reply to signal(): undefined behavior? on Sun, 15 Nov 2015 18:31:25 GMT]]></title><description><![CDATA[<p>linux_newbe schrieb:</p>
<blockquote>
<p>Warum diese Einschränkung?</p>
</blockquote>
<p>Besonders in der C-Bibliothek sind viele Funktionen nicht reentrant.</p>
<p>signal solltest du sowieso nicht benutzen, auch aus ganz anderen Gründen nicht. Du benutzt Linux? Lies mal die Manpage von signal(2) für eine Erklärung und Hinweise zu besseren Alternativen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2475555</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2475555</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 15 Nov 2015 18:31:25 GMT</pubDate></item><item><title><![CDATA[Reply to signal(): undefined behavior? on Sun, 15 Nov 2015 19:30:10 GMT]]></title><description><![CDATA[<p>Aha okay.</p>
<p>Hm ich versuch's mal mit sigaction().</p>
<p>Ich versuche übrigens einfach, eine Qt Anwendung sauber zu beenden, also noch gewissen cleanup-Code auszuführen. Leider erkennt Qt nicht, wenn ein Signal ankommt (aboutToQuit, qAddPostRoutine oder einfach das Ende von main, nichts wird ausgeführt).</p>
<p>Gibt es da einen besseren Weg? Ansonsten würde ich bei einem Signal einfach QCoreApplication::quit() aufrufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2475563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2475563</guid><dc:creator><![CDATA[linux_newbe]]></dc:creator><pubDate>Sun, 15 Nov 2015 19:30:10 GMT</pubDate></item><item><title><![CDATA[Reply to signal(): undefined behavior? on Sun, 15 Nov 2015 20:39:44 GMT]]></title><description><![CDATA[<p>Es ist halt schon blöd, dass man bei einem Signal keine stdlib-Funktionen mehr aufrufen soll... Ich würde zB. gerne &quot;Programm beendet&quot; in eine Logdatei schreiben.</p>
<p>Gibt es unter Linux noch andere Möglichkeiten, ein Programm sauber zu beenden? Ich denke da an sowas wie WM_CLOSE bei Windows...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2475565</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2475565</guid><dc:creator><![CDATA[linux_newbe]]></dc:creator><pubDate>Sun, 15 Nov 2015 20:39:44 GMT</pubDate></item><item><title><![CDATA[Reply to signal(): undefined behavior? on Sun, 15 Nov 2015 22:57:05 GMT]]></title><description><![CDATA[<p>Wenn ich im Signalhandler QCoreApplication::quit() aufrufe, ist das aber doch eigentlich eine race condition. quit() ist nämlich nicht threadsafe...<br />
Und das Programm könnte ja gerade die event-queue durchlaufen, während das signal kommt und ein quit-event oder so posten will...</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2475581</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2475581</guid><dc:creator><![CDATA[linux_newbe]]></dc:creator><pubDate>Sun, 15 Nov 2015 22:57:05 GMT</pubDate></item><item><title><![CDATA[Reply to signal(): undefined behavior? on Mon, 16 Nov 2015 14:24:29 GMT]]></title><description><![CDATA[<p>Lösung für Qt hier: <a href="http://doc.qt.io/qt-5/unix-signals.html" rel="nofollow">http://doc.qt.io/qt-5/unix-signals.html</a> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2475650</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2475650</guid><dc:creator><![CDATA[linux_newbe]]></dc:creator><pubDate>Mon, 16 Nov 2015 14:24:29 GMT</pubDate></item></channel></rss>