pturner@ese.ese.ogi.edu (Paul Turner) (10/23/90)
Hello, I'm trying to do some animation on an RS6000 (a 320 w AIX 3.1 plus the 3001 update) and I'm having problems with the alarm call. The following code fragment performs exactly as I expected on a Sun w SunOS 4.0 but fails on the RS6000 with a single call to the alarm signal handler followed by the termination of the program. like: % testalarm r <- initialize the alarm handler Called <- from the handler Alarm call <- from AIX !!?? and the program terminates What I believe to be the correct behavior is a continuous stream of 'Called' lines - as set below, every 100 milliseconds. This is what happens on our Suns. Any clues? Is there a different way of doing this using some other method? I can't use X/Xt calls to XtAddTimeOut (which is what I'm trying to replace). Is it a bug or am I doing something wrong? Any help would be appreciated. Thanks, --Paul Paul J. Turner pturner@ese.ogi.edu ------------ cut here ---------- #include <stdio.h> #include <sys/signal.h> void animate() { printf("Called\n"); } /* * set a SIGALRM handler, the ualarm * call sets the first call after 1 sec and calls * are made every 100 milliseconds thereafter */ setrun() { signal(SIGALRM, animate); ualarm(1000000, 100000); } setstop() { signal(SIGALRM, SIG_IGN); } main() { char s[256]; while (1) { gets(s); switch (s[0]) { case 'q': exit(0); break; case 'r': setrun(); break; case 's': setstop(); break; } s[0] = 0; } }
ron@woan (Ronald S. Woan) (10/24/90)
In article <13211@ogicse.ogi.edu>, pturner@ese.ese.ogi.edu (Paul Turner) writes: Paul> I'm trying to do some animation on an RS6000 (a 320 w Paul> AIX 3.1 plus the 3001 update) and I'm having problems Paul> with the alarm call. The following code fragment performs Paul> exactly as I expected on a Sun w SunOS 4.0 but fails on the Paul> RS6000 with a single call to the alarm signal handler followed Paul> by the termination of the program. Isn't this just the difference between System V (also pre 4.2 BSD) and BSD 4.2/4.3 signals, i.e. you need to reset the signal by hand in the signal handler, i.e.: void animate() { signal(SIGALRM, SIG_IGN); printf("Called\n"); signal(SIGALRM, animate); } +-----All Views Expressed Are My Own And Are Not Necessarily Shared By------+ +------------------------------My Employer----------------------------------+ + Ronald S. Woan woan@peyote.cactus.org or woan%austin@iinus1.ibm.com + + other email addresses Prodigy: XTCR74A Compuserve: 73530,2537 +
jws@anaconda.cc.purdue.edu (Jeff W. Stewart) (10/24/90)
In article <13211@ogicse.ogi.edu> pturner@ese.ese.ogi.edu (Paul Turner) writes: > >I'm trying to do some animation on an RS6000 (a 320 w >AIX 3.1 plus the 3001 update) and I'm having problems >with the alarm call. The following code fragment performs >exactly as I expected on a Sun w SunOS 4.0 but fails on the >RS6000 with a single call to the alarm signal handler followed >by the termination of the program. like: > >% testalarm >r <- initialize the alarm handler >Called <- from the handler >Alarm call <- from AIX !!?? and the program terminates > >What I believe to be the correct behavior is a continuous >stream of 'Called' lines - as set below, every 100 milliseconds. >This is what happens on our Suns. > You're getting the SYS V style signal handling instead of the BSD style. According to the documentation for sigaction() (which includes signal()): Once an action is installed for a specific signal, it remains installed until another action is explicitly requested (by another call to the sigaction subroutine), or until one of the exec subroutines is called. An exception to this is when the SA_OLDSTYLE is set in which case the action of a caught signal gets set to SIG_DFL prior to calling the signal-catching function for that signal. ... ... The signal() in libc.a does not set SA_RESTART. It sets the signal mask to the signal whose action is being specified, and sets flags to SA_OLDSTYLE. The BSD version of signal() sets SA_RESTART and preserves the current settings of the signal mask and flags. The BSD version can be used by com- piling with the Berkeley Compatibility Library (libbsd.a). And the documentation for sigset(): Upon receipt of the signal specified by the Signal parameter, the receiving process is to execute the signal catching function pointed to by Function. Pending signal of this type is released. This address is retained across calls to the other signal manage- ment functions, sighold and sigrelse. The signal number Signal will be passed as the only argument to the signal-catching func- tion. Before entering the signal-catching function, the value of Function for the caught signal will be set to SIG_HOLD. During normal return from the signal-catching handler, the system signal action is restored to Function and any held signal of this type is released. If a non-local goto (see setjmp) is taken, the sigrelse subroutine must be invoked to restore the system signal action and to release any held signal of this type. You should either load against libbsd.a or use sigset() in place of signal(). (I tried both and they both worked) - Jeff Stewart