Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!uunet!in3.uu.net!128.230.129.106!news.maxwell.syr.edu!news.algonet.se!uab.ericsson.se!erinews.ericsson.se!news
From: martti.kuparinen@era.erixsson.se (Martti Kuparinen)
Newsgroups: comp.unix.bsd.freebsd.misc,comp.unix.programmer
Subject: sigprocmask problems
Date: 12 May 1997 14:47:11 GMT
Organization: Ericsson
Lines: 73
Distribution: world
Message-ID: <5l7ahf$dld@newstoo.ericsson.se>
NNTP-Posting-Host: kk130.ericsson.se
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:40755 comp.unix.programmer:54273
The following code fragment is giving me head ache. It works great
in Linux and Solaris 2.5 but not in FreeBSD 2.2 :-(
If you send SIGHUP when signals are enabled, the program prints SIGHUP
as expected. But then after this "kill -HUP <pid>" thing the sleep(10)
statements become almost like sleep(1)...
Any ideas why?
/Martti
---8<---
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <setjmp.h>
jmp_buf jumpAddress;
void hup(int)
{
printf("\nSIGHUP\n");
longjmp(jumpAddress, 1);
}
void enable()
{
sigset_t mask;
sigpending(&mask);
if (sigismember(&mask, SIGHUP)) {
printf("SIGHUP pending\n");
fflush(stdout);
}
sigemptyset(&mask);
sigaddset(&mask, SIGHUP);
sigprocmask(SIG_UNBLOCK, &mask, NULL);
}
void disable()
{
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGHUP);
sigprocmask(SIG_BLOCK, &mask, NULL);
}
int main()
{
printf("kill -HUP %d\n", getpid());
setjmp(jumpAddress);
signal(SIGHUP, hup);
while (1) {
printf("disable() ");
fflush(stdout);
disable();
sleep(10);
printf("enable()\n");
fflush(stdout);
enable();
sleep(10);
}
}
---8<---
--
If you want to reply to me, please substitute x with c in the From: field
or :s/x/c as we vi users say it...