public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Using signals in redhat linux
@ 2004-08-05 17:36 Claudio Lavecchia
  2004-08-05 18:16 ` Ishwar Rattan
  2004-08-05 18:33 ` Eljay Love-Jensen
  0 siblings, 2 replies; 3+ messages in thread
From: Claudio Lavecchia @ 2004-08-05 17:36 UTC (permalink / raw)
  To: gcc-help

Hello people,

I have a quick question about using signals in Linux environment - 
redhat 7.3.
I'm using GCC version 2.96.
I'm trying to launch and intercept signals - but the signals never get 
intercepted.

Any of you guys have an idea of why? Do I have to set any compile option?

I include the very simple test (using both alarm() and raise() to send 
signals)

Thanks a lot

Claudio

#include <stdio.h>
#include <signal.h>
#include <time.h>


void processAlarm()
{
    signal(SIGALRM, processAlarm);
    printf("ALARM INTERCEPTED");
    alarm(3);
}

void processSIG()
{
    signal(100, processSIG);
    printf("SIG INTERCEPTED");  
}

int main(int argc, char *argv[])
{
    printf("Launching Alarm Test\n");
    signal(SIGALRM, processAlarm);

    printf("Launching Alarm (previous alarm value: %d)\n",alarm(3));   
    printf("Alarm value:%d\n",alarm(0));

    signal(100, processSIG);
    raise(100);
       
    while (1);
    return 0;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using signals in redhat linux
  2004-08-05 17:36 Using signals in redhat linux Claudio Lavecchia
@ 2004-08-05 18:16 ` Ishwar Rattan
  2004-08-05 18:33 ` Eljay Love-Jensen
  1 sibling, 0 replies; 3+ messages in thread
From: Ishwar Rattan @ 2004-08-05 18:16 UTC (permalink / raw)
  To: Claudio Lavecchia; +Cc: gcc-help

Did your code work on any other system?

Learn nature of signals and related calls first!

-ishwar


On Thu, 5 Aug 2004, Claudio Lavecchia wrote:

> Hello people,
>
> I have a quick question about using signals in Linux environment -
> redhat 7.3.
> I'm using GCC version 2.96.
> I'm trying to launch and intercept signals - but the signals never get
> intercepted.
>
> Any of you guys have an idea of why? Do I have to set any compile option?
>
> I include the very simple test (using both alarm() and raise() to send
> signals)
>
> Thanks a lot
>
> Claudio
>
> #include <stdio.h>
> #include <signal.h>
> #include <time.h>
>
>
> void processAlarm()
> {
>     signal(SIGALRM, processAlarm);
>     printf("ALARM INTERCEPTED");
>     alarm(3);
> }
>
> void processSIG()
> {
>     signal(100, processSIG);
>     printf("SIG INTERCEPTED");
> }
>
> int main(int argc, char *argv[])
> {
>     printf("Launching Alarm Test\n");
>     signal(SIGALRM, processAlarm);
>
>     printf("Launching Alarm (previous alarm value: %d)\n",alarm(3));
>     printf("Alarm value:%d\n",alarm(0));
>
>     signal(100, processSIG);
>     raise(100);
>
>     while (1);
>     return 0;
> }
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using signals in redhat linux
  2004-08-05 17:36 Using signals in redhat linux Claudio Lavecchia
  2004-08-05 18:16 ` Ishwar Rattan
@ 2004-08-05 18:33 ` Eljay Love-Jensen
  1 sibling, 0 replies; 3+ messages in thread
From: Eljay Love-Jensen @ 2004-08-05 18:33 UTC (permalink / raw)
  To: Claudio Lavecchia, gcc-help

Hi Claudio,

Your question is off-topic for this forum.  This forum does not support Red
Hat's 2.96 compiler (Red Hat has a forum for support of their compiler).
This forum does not support Red Hat Linux 7.3 (Red Hat has support forums
for that OS, including for developers).

That being said...

What are you NOT allowed to do within a signal?

Depending on the platform, there are MANY caveats about what you can and
cannot do within a signal handler.

Typically:
+ no I/O (such as a printf)
+ no OS API calls*
+ in C++ land, no exceptions
+ no longjmp
+ no read/writing non-volatile variables
+ no exit / abort

* The "no I/O" falls under this category, but it's so important I put it all
by itself anyway.

What should a signal handler do?

As little as possible, as quickly as possible.  Set a flag, and then have
the regular program check that (volatile) flag for being changed.  (I'm not
sure about mutexes and condvars within signal handlers... probably another
concern.)

In a multi-threading program, I'm not sure if there is any guarantee which
thread will be handling the signal.  Probably varies from platform to
platform.

I'm not sure if any of the above is applicable to Red Hat Linux 7.3, or Red
Hat 2.96 compiler.  I'm not sure if there is a attribute decoration for the
signal handling function in your situation (as I vaguely recall from my
Borland Turbo C days).

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-08-05 17:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-05 17:36 Using signals in redhat linux Claudio Lavecchia
2004-08-05 18:16 ` Ishwar Rattan
2004-08-05 18:33 ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).