When does ( alarm(1) == alarm(INFINITY) ) ?

Keith Andrews andrews at calgary.UUCP
Sat Mar 9 01:37:13 AEST 1985


> I wrote the following fudge routine to handle a similar problem 
> when using 4.1 BSD. The 4.2 signal stuff allows a cleaner (though
> less efficient) solution. It only works on the VAX as written, though
> adaptation to other machines would probably be possible.
> 
> 
> static char pause_routine[5];		/* Pause system call or nop's */
> 
> /* Set up a routine to do a "pause" system call. */
> 
> jk_set_up_pause()
> { register char *p;
>   p = &pause_routine[2];
>   *p++ = 0274; *p++ = 035;	/* chmk $pause */
>   *p++ = 04;			/* ret */
> }
> 
			........
> 
> jk_maybe_do_pause()
> { (*(void (*)())pause_routine)();
> }
> 
> /* Disable pause call by replacing system call with nop's */
> 
> jk_disable_pause()
> { register char *p;
>   p = &pause_routine[2];
>   *p++ = 01; *p++ = 01;		/* nop; nop */
> }

Although this solution to the problem may be sound, this method of implementing
it is, er... dumb (to say the least).  The following implementation is much
easier to understand, simpler and (Oh wow!) portable:


		int (*foo)();
		int pause();
			...
		{
			...
			/* Point at the pause() call */
			foo = pause;
			/* Set up alarm */
			alarm(1);
			/* Actually do pause (well, maybe) */
			(*foo)();
			/* Proceed merrily along */
		}

		int null()
		{}	/* Do nothing function */

		alarm_signal_handler()
		{
			foo = null;
		}


					Keith Andrews
					U of Calgary, Dept. of CS



More information about the Comp.unix.wizards mailing list