<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated on Mon, 23 Nov 2009 19:04:53 -0800 -->
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <atom:link href="http://software.intel.com/en-us/forums/intel-c-compiler/topic/66465/feed" rel="self" type="application/rss+xml" />
    <title>Intel Software Network - <![CDATA[ Signal Handler on a Linux system. ]]> feed</title>
    <link>http://software.intel.com/en-us/forums/intel-c-compiler/topic/66465</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>Re: Signal Handler on a Linux system.</title>
      <description><![CDATA[ <div style="margin: 0px; height: auto;"></div>
<br />I could not compile the secod case even with gcc. Could you please help with compilable test case with gcc and command line.   ]]></description>
      <link>http://software.intel.com/en-us/forums/intel-c-compiler/topic/66465/</link>
      <pubDate>Tue, 23 Jun 2009 22:43:39 -0700</pubDate>
      <guid isPermaLink="true">http://software.intel.com/en-us/forums/intel-c-compiler/topic/66465/</guid>
      <category>ISN General</category>
    </item>
    <item>
      <title>Re: Signal Handler on a Linux system.</title>
      <description><![CDATA[ <div style="margin:0px;">
<div id="quote_reply" style="margin-top: 5px; width: 100%;">
<div style="margin-left:2px;margin-right:2px;">Quoting - <a href="/en-us/profile/335789">Om Sachan (Intel)</a></div>
<div style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"><em><br />I could not compile the secod case even with gcc. Could you please help with compilable test case with gcc and command line.  </em></div>
</div>
</div>
<br />That is what my problem is, the structure with sa_sigaction exists in the sigaction.h include file, it also does incorporate the 3 return arguments (instead of just signo), but I cannot get it to compile on our system.  This solution was one I found on the internet after searching for signal handlers on Linux systems.  I tried a plethera of different #define flags to see if I could force it to use the correct version of the sigaction structure with the added arguments, but to no avail.  I cannot get this to work on the Linux system using gcc or icc.  Is there another way to do it using icc?  I have to be able to capture the signal, print the call stack, and re-display the Motif window notifying the operator that a signal was caught so that they can gracefully exit the process and notify a analyst to take a look at it.  The call stack printing is to assist the analyst with what the process was doing when it received a signal.  Everything works with the first solution, except that it prints the "new" call stack containing just the signal handler information.  The only solution I can find to get to the previous stack frame "old" call stack, was the routine #2 solution.  According to the include files on the system, the system should support the second solution, I just can't figure out what I am missing to get it to compile. ]]></description>
      <link>http://software.intel.com/en-us/forums/intel-c-compiler/topic/66465/</link>
      <pubDate>Wed, 24 Jun 2009 07:11:05 -0700</pubDate>
      <guid isPermaLink="true">http://software.intel.com/en-us/forums/intel-c-compiler/topic/66465/</guid>
      <category>ISN General</category>
    </item>
    <item>
      <title>Re: Signal Handler on a Linux system.</title>
      <description><![CDATA[ <br />Mark, one of my colleagues, fixed syntax error in your code. That makes the code works on IA-32.<br /><br /><br />================== <span style="background-color: #ffff00;">t2.cpp for IA32</span> ================<br />#define _POSIX_SOURCE 199309<br /><br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;signal.h&gt;<br />#include &lt;execinfo.h&gt;<br />#include &lt;setjmp.h&gt;<br />#include &lt;unistd.h&gt;<br /><br />#define __USE_GNU 1<br />#include &lt;sys/ucontext.h&gt;<br /><br /><br /><br />void MyStackWalker (siginfo_t *info, void *my_eip)<br />{<br />void *trace[10];<br />int i;<br />int trace_size = 0;<br />char **messages = (char**)NULL;<br />trace_size = backtrace(trace, 10);<br />messages = backtrace_symbols(trace, trace_size);<br />ucontext_t *uc = (ucontext_t *)my_eip;<br />trace[1] = (void*)uc-&gt;uc_mcontext.gregs[REG_RIP];<br />for (i=0; i&lt;trace_size; i++)<br />{<br />printf("\n[bt] %s", messages[i]);<br />}<br />free (messages);<br />}<br />void MySignalHandler (int signo, siginfo_t *info, void *my_eip)<br />{<br />if (signo == SIGFPE)<br />{<br />printf("\n A floating point exception has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGSEGV)<br />{<br />printf("\n A segmentation violation has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGILL)<br />{<br />printf("\n An illegal operation has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGTRAP)<br />{<br />printf("\n A out of bounds array has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else<br />{<br />printf("\n An unknown exception has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />}<br />int main()<br />{<br />struct sigaction newAct;<br />newAct.sa_sigaction= &amp;MySignalHandler;<br />sigemptyset (&amp;newAct.sa_mask);<br />newAct.sa_flags = SA_RESTART | SA_SIGINFO;<br />sigaction(SIGFPE, &amp;newAct, NULL);<br />sigaction(SIGILL, &amp;newAct, NULL);<br />sigaction(SIGSEGV, &amp;newAct, NULL);<br />sigaction(SIGTRAP, &amp;newAct, NULL);<br />}<br />============================================<br /><br />$ icc -V<br />Intel(R) C Compiler Professional for applications running on IA-32, Version 11.0 Build 20090609 Package ID: l_cproc_p_11.0.084<br />Copyright (C) 1985-2009 Intel Corporation. All rights reserved.<br /><br />$ icpc t2.cpp<br />$ g++ t2.cpp<br />$<br /><br /><br />However, above code doesn't compile on Intel 64.  Then I did some further investigation.It looks that REG_EIP only works on IA-32. In /usr/include/sys/ucontext.h, you may see something like this<br /><br /><br />#if __WORDSIZE == 64<br />...<br />enum<br />{<br />REG_R8 = 0,<br /># define REG_R8 REG_R8<br />REG_R9,<br /># define REG_R9 REG_R9<br />REG_R10,<br /># define REG_R10 REG_R10<br />REG_R11,<br />...<br /><strong>REG_RIP,<br /></strong># define REG_RIP REG_RIP<br />...<br />};<br /><br />#else /* __WORDSIZE == 32 */<br /><br />enum<br />{<br />...<br /><strong>REG_EIP</strong>,<br /># define REG_EIP REG_EIP<br />REG_CS,<br /># define REG_CS REG_CS<br />REG_EFL,<br /># define REG_EFL REG_EFL<br />REG_UESP,<br /># define REG_UESP REG_UESP<br />REG_SS<br /># define REG_SS REG_SS<br />};<br />#endif<br /><br /><br />So, on IA-32, REG_EIP is an enum value. But on Intel 64, REG_EIP is not defined.  It seems that you should use REG_RIP instead on Intel 64.  With this modification, t2.cpp compiles.  See below.<br /><br /><br />=========== <span style="background-color: #ffff00;">t2.cpp for Intel 64</span> ================<br />#define _POSIX_SOURCE 199309<br /><br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;signal.h&gt;<br />#include &lt;execinfo.h&gt;<br />#include &lt;setjmp.h&gt;<br />#include &lt;unistd.h&gt;<br /><br />#define __USE_GNU 1<br />#include &lt;sys/ucontext.h&gt;<br /><br /><br /><br />void MyStackWalker (siginfo_t *info, void *my_eip)<br />{<br />void *trace[10];<br />int i;<br />int trace_size = 0;<br />char **messages = (char**)NULL;<br />trace_size = backtrace(trace, 10);<br />messages = backtrace_symbols(trace, trace_size);<br />ucontext_t *uc = (ucontext_t *)my_eip;<br />trace[1] = (void*)uc-&gt;uc_mcontext.gregs[REG_RIP];<br />for (i=0; i&lt;trace_size; i++)<br />{<br />printf("\n[bt] %s", messages[i]);<br />}<br />free (messages);<br />}<br />void MySignalHandler (int signo, siginfo_t *info, void *my_eip)<br />{<br />if (signo == SIGFPE)<br />{<br />printf("\n A floating point exception has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGSEGV)<br />{<br />printf("\n A segmentation violation has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGILL)<br />{<br />printf("\n An illegal operation has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGTRAP)<br />{<br />printf("\n A out of bounds array has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else<br />{<br />printf("\n An unknown exception has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />}<br />int main()<br />{<br />struct sigaction newAct;<br />newAct.sa_sigaction= &amp;MySignalHandler;<br />sigemptyset (&amp;newAct.sa_mask);<br />newAct.sa_flags = SA_RESTART | SA_SIGINFO;<br />sigaction(SIGFPE, &amp;newAct, NULL);<br />sigaction(SIGILL, &amp;newAct, NULL);<br />sigaction(SIGSEGV, &amp;newAct, NULL);<br />sigaction(SIGTRAP, &amp;newAct, NULL);<br />}<br />=======================================<br /><br />$ icc -V<br />Intel(R) C Intel(R) 64 Compiler Professional for applications running on Intel(R) 64, Version 11.0 Build 20090609 Package ID: l_cproc_p_11.0.084<br />Copyright (C) 1985-2009 Intel Corporation. All rights reserved.<br /><br />$ icpc t2.cpp<br />$ g++ t2.cpp<br />$<br /> ]]></description>
      <link>http://software.intel.com/en-us/forums/intel-c-compiler/topic/66465/</link>
      <pubDate>Thu, 02 Jul 2009 01:30:50 -0700</pubDate>
      <guid isPermaLink="true">http://software.intel.com/en-us/forums/intel-c-compiler/topic/66465/</guid>
      <category>ISN General</category>
    </item>
    <item>
      <title>Re: Signal Handler on a Linux system.</title>
      <description><![CDATA[ <div style="margin:0px;">
<div id="quote_reply" style="margin-top: 5px; width: 100%;">
<div style="margin-left:2px;margin-right:2px;">Quoting - <a href="/en-us/profile/336791">Feilong H. (Intel)</a></div>
<div style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"><em><br />Mark, one of my colleagues, fixed syntax error in your code. That makes the code works on IA-32.<br /><br /><br />================== <span style="background-color: #ffff00;">t2.cpp for IA32</span> ================<br />#define _POSIX_SOURCE 199309<br /><br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;signal.h&gt;<br />#include &lt;execinfo.h&gt;<br />#include &lt;setjmp.h&gt;<br />#include &lt;unistd.h&gt;<br /><br />#define __USE_GNU 1<br />#include &lt;sys/ucontext.h&gt;<br /><br /><br /><br />void MyStackWalker (siginfo_t *info, void *my_eip)<br />{<br />void *trace[10];<br />int i;<br />int trace_size = 0;<br />char **messages = (char**)NULL;<br />trace_size = backtrace(trace, 10);<br />messages = backtrace_symbols(trace, trace_size);<br />ucontext_t *uc = (ucontext_t *)my_eip;<br />trace[1] = (void*)uc-&gt;uc_mcontext.gregs[REG_RIP];<br />for (i=0; i&lt;trace_size; i++)<br />{<br />printf("\n[bt] %s", messages[i]);<br />}<br />free (messages);<br />}<br />void MySignalHandler (int signo, siginfo_t *info, void *my_eip)<br />{<br />if (signo == SIGFPE)<br />{<br />printf("\n A floating point exception has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGSEGV)<br />{<br />printf("\n A segmentation violation has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGILL)<br />{<br />printf("\n An illegal operation has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGTRAP)<br />{<br />printf("\n A out of bounds array has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else<br />{<br />printf("\n An unknown exception has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />}<br />int main()<br />{<br />struct sigaction newAct;<br />newAct.sa_sigaction= &amp;MySignalHandler;<br />sigemptyset (&amp;newAct.sa_mask);<br />newAct.sa_flags = SA_RESTART | SA_SIGINFO;<br />sigaction(SIGFPE, &amp;newAct, NULL);<br />sigaction(SIGILL, &amp;newAct, NULL);<br />sigaction(SIGSEGV, &amp;newAct, NULL);<br />sigaction(SIGTRAP, &amp;newAct, NULL);<br />}<br />============================================<br /><br />$ icc -V<br />Intel(R) C Compiler Professional for applications running on IA-32, Version 11.0 Build 20090609 Package ID: l_cproc_p_11.0.084<br />Copyright (C) 1985-2009 Intel Corporation. All rights reserved.<br /><br />$ icpc t2.cpp<br />$ g++ t2.cpp<br />$<br /><br /><br />However, above code doesn't compile on Intel 64.  Then I did some further investigation.It looks that REG_EIP only works on IA-32. In /usr/include/sys/ucontext.h, you may see something like this<br /><br /><br />#if __WORDSIZE == 64<br />...<br />enum<br />{<br />REG_R8 = 0,<br /># define REG_R8 REG_R8<br />REG_R9,<br /># define REG_R9 REG_R9<br />REG_R10,<br /># define REG_R10 REG_R10<br />REG_R11,<br />...<br /><strong>REG_RIP,<br /></strong># define REG_RIP REG_RIP<br />...<br />};<br /><br />#else /* __WORDSIZE == 32 */<br /><br />enum<br />{<br />...<br /><strong>REG_EIP</strong>,<br /># define REG_EIP REG_EIP<br />REG_CS,<br /># define REG_CS REG_CS<br />REG_EFL,<br /># define REG_EFL REG_EFL<br />REG_UESP,<br /># define REG_UESP REG_UESP<br />REG_SS<br /># define REG_SS REG_SS<br />};<br />#endif<br /><br /><br />So, on IA-32, REG_EIP is an enum value. But on Intel 64, REG_EIP is not defined.  It seems that you should use REG_RIP instead on Intel 64.  With this modification, t2.cpp compiles.  See below.<br /><br /><br />=========== <span style="background-color: #ffff00;">t2.cpp for Intel 64</span> ================<br />#define _POSIX_SOURCE 199309<br /><br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;signal.h&gt;<br />#include &lt;execinfo.h&gt;<br />#include &lt;setjmp.h&gt;<br />#include &lt;unistd.h&gt;<br /><br />#define __USE_GNU 1<br />#include &lt;sys/ucontext.h&gt;<br /><br /><br /><br />void MyStackWalker (siginfo_t *info, void *my_eip)<br />{<br />void *trace[10];<br />int i;<br />int trace_size = 0;<br />char **messages = (char**)NULL;<br />trace_size = backtrace(trace, 10);<br />messages = backtrace_symbols(trace, trace_size);<br />ucontext_t *uc = (ucontext_t *)my_eip;<br />trace[1] = (void*)uc-&gt;uc_mcontext.gregs[REG_RIP];<br />for (i=0; i&lt;trace_size; i++)<br />{<br />printf("\n[bt] %s", messages[i]);<br />}<br />free (messages);<br />}<br />void MySignalHandler (int signo, siginfo_t *info, void *my_eip)<br />{<br />if (signo == SIGFPE)<br />{<br />printf("\n A floating point exception has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGSEGV)<br />{<br />printf("\n A segmentation violation has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGILL)<br />{<br />printf("\n An illegal operation has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else if (signo == SIGTRAP)<br />{<br />printf("\n A out of bounds array has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />else<br />{<br />printf("\n An unknown exception has been detected.");<br />MyStackWalker(info, my_eip);<br />}<br />}<br />int main()<br />{<br />struct sigaction newAct;<br />newAct.sa_sigaction= &amp;MySignalHandler;<br />sigemptyset (&amp;newAct.sa_mask);<br />newAct.sa_flags = SA_RESTART | SA_SIGINFO;<br />sigaction(SIGFPE, &amp;newAct, NULL);<br />sigaction(SIGILL, &amp;newAct, NULL);<br />sigaction(SIGSEGV, &amp;newAct, NULL);<br />sigaction(SIGTRAP, &amp;newAct, NULL);<br />}<br />=======================================<br /><br />$ icc -V<br />Intel(R) C Intel(R) 64 Compiler Professional for applications running on Intel(R) 64, Version 11.0 Build 20090609 Package ID: l_cproc_p_11.0.084<br />Copyright (C) 1985-2009 Intel Corporation. All rights reserved.<br /><br />$ icpc t2.cpp<br />$ g++ t2.cpp<br />$<br /></em></div>
</div>
</div>
<br /><br />Thanks,  I just returned to work from vacation, and will try this fix This week.  I will let you know if it works on our system.<br /> ]]></description>
      <link>http://software.intel.com/en-us/forums/intel-c-compiler/topic/66465/</link>
      <pubDate>Tue, 07 Jul 2009 08:11:01 -0700</pubDate>
      <guid isPermaLink="true">http://software.intel.com/en-us/forums/intel-c-compiler/topic/66465/</guid>
      <category>ISN General</category>
    </item>
  </channel></rss>