Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!agate!agate!adrianho From: adrianho@barkley.berkeley.edu (Adrian J Ho) Newsgroups: comp.unix.questions Subject: Re: Need help on finding sources for ualarm Message-ID: Date: 28 Mar 91 02:27:24 GMT References: <91.082.19:00:19@mute.ruhr.de> <1345@dkunix9.dk.oracle.com> <1806@umvlsi.ecs.umass.edu> Sender: usenet@agate.berkeley.edu (USENET Administrator) Followup-To: comp.unix.questions Distribution: na Organization: University of California, Berkeley Lines: 87 In-Reply-To: srivasta@nazgul.ecs.umass.edu's message of 27 Mar 91 22:41:29 GMT In article <1806@umvlsi.ecs.umass.edu> srivasta@nazgul.ecs.umass.edu (Manoj Srivastava) writes: > I was compiling a "third party software" when I came across a > reference to ualarm (int arg), and apparently, from the context, it > generates a signal (unix SIGALARM) after arg microseconds. > unfortunately, my machine has no such beast, the closest it comes to > is alarm (unsigned arg), which takes an arg in seconds. Is it > possible to get the sources of any such implementation, or would it > be too hardware dependent? I am running ULTRIX v.4.1 on a DECstation > 5000/200 (MIPS Architecture). Any advice/ pointers shall be > appreciated. Well, I'm running Ultrix 3.1 on a 3100, but that shouldn't make a difference in what I'm about to say. The SunOS 4.1 man page for ualarm(3) sez: ---------- UALARM(3) C LIBRARY FUNCTIONS UALARM(3) NAME ualarm - schedule signal after interval in microseconds SYNOPSIS unsigned ualarm(value, interval) unsigned value; unsigned interval; DESCRIPTION This is a simplified interface to setitimer() (see getiti- mer(2)). ualarm() sends signal SIGALRM, see signal(3V), to the invok- ing process in a number of microseconds given by the value argument. Unless caught or ignored, the signal terminates the process. --------- As you can see, ualarm() is just a wrapper for setitimer(2). After reading the latter man page, I came up with this (off the top of my head): ========== #include unsigned ualarm(value, interval) unsigend value; unsigned interval; { struct itimerval itv, oitv; /* Set values in itv */ itv.it_interval.tv_sec = interval / 1000000; itv.it_interval.tv_usec = interval % 1000000; itv.it_value.tv_sec = value / 1000000; itv.it_value.tv_usec = value % 1000000; /* Call setitimer() */ setitimer(ITIMER_REAL,&itv,&oitv) /* and return old value */ return (oitv.it_value.tv_sec * 1000000 + oitv.it_value.tv_usec); } ========== Two things to note: 1) This code is untested. I can't think of a reason why it wouldn't work, but..... 2) You won't get microsecond resolution -- don't be fooled by the tv_usec field. From the Ultrix 3.1 getitimer(3) man page: ---------- Time values smaller than the resolution of the system clock are rounded up to this resolution (on MIPS, 3.906 mil- liseconds; on VAX, 10 milliseconds). ---------- Other than that, good luck! ----------------------------------------------------------------------------- Adrian Ho, EECS (pronounced "eeks!") Dept. Phone: (415) 642-5563 UC Berkeley adrianho@barkley.berkeley.edu Domain: sesame-street (telly,bigbird,snuffy,oscar,kermit,bert,grover,barkley)