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