From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <14d0839475c3628914a71315dc2e21e5@9netics.com> To: 9fans@9fans.net Date: Fri, 1 May 2015 00:17:30 -0700 From: Skip Tavakkolian <9nut@9netics.com> In-Reply-To: <32E4BD35-FCDC-4859-9034-82747001C411@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-gkqpzlzlijdbvddidutdicsgmw" Subject: Re: [9fans] setitimer equivalent, and sigvtalarm equivalent Topicbox-Message-UUID: 4eb726e2-ead9-11e9-9d60-3106f5b1d025 This is a multi-part message in MIME format. --upas-gkqpzlzlijdbvddidutdicsgmw Content-Disposition: inline Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable one way to solve this would be to fork as many procs as there are timers; each would sleep the length of its timer value and then postnote an identifying artificial note (vtalarm, fooalarm, etc.) to the parent process. the parent process then interprets the artificial note as a particular type of alarm. -Skip > Hi, >=20 > I=E2=80=99m not sure I understand your proposal. >=20 > But looking more at the code I need to port, an interpreter, I think > the main issue is that the interpreter relies on sigvtalarm as > a way to preempt the interpreted program while allowing > the user program to use only sigalarm. So more generally > the problem is how can I have two alarms in plan9? I see only > one alarm signal in ape, SIGALRM. There is no SIGVTALRM. >=20 >=20 >=20 >> On Apr 29, 2015, at 9:47 AM, erik quanstrom wr= ote: >>=20 >> On Tue Apr 28 21:30:24 PDT 2015, aryx.padator@gmail.com wrote: >>> Hi, >>>=20 >>> I=E2=80=99m trying to port some code to plan9 using APE >>> but I can=E2=80=99t find the setitimer function in any include/ape/ f= iles. >>> What is the equivalent to setitimer under plan9? >>=20 >> if you're ok on using nsec() as your time source, select(3) as posix w= ould >> have it, will do. >>=20 >> - erik >>=20 --upas-gkqpzlzlijdbvddidutdicsgmw Content-Disposition: attachment; filename=notesy.c Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit #include #include #include void alarmhandler(void *a, char *msg) { USED(a); if(strstr(msg, "alarm") != 0) { printf("received alarm signal %s\n", msg); noted(NCONT); } } int timer(char *msg, int ms) { int pid, apid; pid = getpid(); switch (apid = fork()) { case -1: sysfatal("fork failed: %r"); case 0: sleep(ms); postnote(PNPROC, pid, msg); exits(nil); default: break; } return apid; } void main(int argc, char **argv) { int pid, t1pid, t2pid, count = 0; notify(alarmhandler); t1pid = timer("fooalarm", 750); count++; t2pid = timer("baralarm", 250); count++; alarm(500); while (count > 0) { pid = waitpid(); if (pid == t1pid) count--; if (pid == t2pid) count--; } exits(nil); } --upas-gkqpzlzlijdbvddidutdicsgmw--