9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Skip Tavakkolian <9nut@9netics.com>
To: 9fans@9fans.net
Subject: Re: [9fans] setitimer equivalent, and sigvtalarm equivalent
Date: Fri,  1 May 2015 00:17:30 -0700	[thread overview]
Message-ID: <14d0839475c3628914a71315dc2e21e5@9netics.com> (raw)
In-Reply-To: <32E4BD35-FCDC-4859-9034-82747001C411@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1253 bytes --]

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,
> 
> I’m not sure I understand your proposal.
> 
> 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.
> 
> 
> 
>> On Apr 29, 2015, at 9:47 AM, erik quanstrom <quanstro@quanstro.net> wrote:
>> 
>> On Tue Apr 28 21:30:24 PDT 2015, aryx.padator@gmail.com wrote:
>>> Hi,
>>> 
>>> I’m trying to port some code to plan9 using APE
>>> but I can’t find the setitimer function in any include/ape/ files.
>>> What is the equivalent to setitimer under plan9?
>> 
>> if you're ok on using nsec() as your time source, select(3) as posix would
>> have it, will do.
>> 
>> - erik
>> 

[-- Attachment #2: notesy.c --]
[-- Type: text/plain, Size: 798 bytes --]

#include <u.h>
#include <libc.h>
#include <stdio.h>

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);
}

  reply	other threads:[~2015-05-01  7:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-29  4:28 [9fans] setitimer equivalent yoann padioleau
2015-04-29  4:38 ` James A. Robinson
2015-04-29  4:55   ` lucio
2015-04-29  5:19     ` James A. Robinson
2015-04-29  6:38       ` lucio
2015-04-29 16:47 ` erik quanstrom
2015-05-01  3:21   ` [9fans] setitimer equivalent, and sigvtalarm equivalent yoann padioleau
2015-05-01  7:17     ` Skip Tavakkolian [this message]
2015-05-02 15:06     ` erik quanstrom
2015-05-02 15:27       ` cinap_lenrek
2015-05-02 18:01       ` yoann padioleau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14d0839475c3628914a71315dc2e21e5@9netics.com \
    --to=9nut@9netics.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).