Is SIGALRM getting masked ???

Discussion in 'C Programming' started by apoorva.groups@gmail.com, Dec 17, 2007.

  1. Guest

    I am using setitimer function to timeout of the processing that I
    doing.

    I wrote a small program and it seems to be working...
    It works with the cgi for values less than 1024 but for values more
    that that it does not work.


    I tried to use alarm but again it is not timing out. I am not sure
    whether the SIGALRM is getting masked. If that is the case How to
    make
    sure that SIGALRM is not masked.


    main()
    {
    long int Timer_Sec = 1800;
    struct itimerval rttimer;

    signal(SIGALRM,handler);
    rttimer.it_value.tv_sec = Timer_Sec;
    rttimer.it_value.tv_usec = 0;
    rttimer.it_interval.tv_sec = 10;
    rttimer.it_interval.tv_usec = 0;

    system("date");

    setitimer (ITIMER_REAL, &rttimer, NULL);

    // alarm(Timer_Sec+120);

    for(;;);

    }

    void handler(int sig)
    {
    static int i = 0;
    i++;

    system("date");
    printf("signal handler for %d\n",sig);
    exit(1);

    }
     
    , Dec 17, 2007
    #1
    1. Advertising

  2. On Mon, 17 Dec 2007 06:01:48 -0800 (PST), ""
    <> wrote:

    > I am using setitimer function to timeout of the processing that I
    > doing.
    >
    > I wrote a small program and it seems to be working...
    > It works with the cgi for values less than 1024 but for values more
    > that that it does not work.
    >
    >
    > I tried to use alarm but again it is not timing out. I am not sure
    > whether the SIGALRM is getting masked. If that is the case How to
    > make
    > sure that SIGALRM is not masked.
    >

    Neither setitimer() nor alarm()/SIGALARM is included in Standard
    (portable) C and hence they are offtopic here. comp.unix.programmer is
    the most obvious place they are ontopic. I assume by 'cgi' you mean
    the webserving environment; if that is actually relevant I'm not sure
    where that is ontopic. But a few points:

    You must have #include'd several relevant headers for your code to
    compile at all, and perhaps more for it to work correctly. You may be
    thinking that they aren't relevant to your question, but such thinking
    is sometimes wrong; better to be clear even if a bit longer.

    >
    > main()


    Aside: This is legal prior to C99, but even so it is better to specify
    int main (void)

    > {
    > long int Timer_Sec = 1800;
    > struct itimerval rttimer;
    >

    1800 seconds is 30 minutes (and 1920 is 32 minutes). That's a pretty
    long time for a person to wait. Or even(?) a webserver.

    > signal(SIGALRM,handler);
    > rttimer.it_value.tv_sec = Timer_Sec;
    > rttimer.it_value.tv_usec = 0;
    > rttimer.it_interval.tv_sec = 10;
    > rttimer.it_interval.tv_usec = 0;
    >
    > system("date");
    >
    > setitimer (ITIMER_REAL, &rttimer, NULL);
    >
    > // alarm(Timer_Sec+120);
    >

    (doubleslash comments are legal _only_ in C99, so formally this
    conflicts with the implicit-int main. Both are legal in GNU C though.)

    > for(;;);
    >
    > }
    >
    > void handler(int sig)
    > {
    > static int i = 0;
    > i++;
    >
    > system("date");
    > printf("signal handler for %d\n",sig);


    The list of things you can safely do in a Standard C signal handler
    routine is very short; for a POSIX/Unix one is is somewhat longer, but
    still does not include system() and printf(). Although for your _very_
    simplified example, they are quite likely to work.

    > exit(1);
    >
    > }

    - formerly david.thompson1 || achar(64) || worldnet.att.net
     
    David Thompson, Dec 30, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ron Eggler

    SIGALRM in a class member?

    Ron Eggler, Aug 13, 2008, in forum: C++
    Replies:
    8
    Views:
    777
    James Kanze
    Aug 14, 2008
  2. Paul Rubin

    SIGALRM problem

    Paul Rubin, Oct 13, 2008, in forum: Python
    Replies:
    2
    Views:
    466
    Paul Rubin
    Oct 13, 2008
  3. Eric Schwartz

    timeouts with threads and SIGALRM

    Eric Schwartz, Aug 13, 2004, in forum: Ruby
    Replies:
    11
    Views:
    410
    Eric Schwartz
    Aug 20, 2004
  4. Guillaume Marcais

    SIGALRM available?

    Guillaume Marcais, Feb 14, 2005, in forum: Ruby
    Replies:
    2
    Views:
    177
    Guillaume Marcais
    Feb 15, 2005
  5. Samuel

    Catching SIGALRM in a thread

    Samuel, May 20, 2007, in forum: Perl Misc
    Replies:
    7
    Views:
    517
    zentara
    May 23, 2007
Loading...

Share This Page