Return to BSD News archive
Xref: sserve comp.unix.ultrix:19127 comp.unix.bsd:12381 Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!doc.ic.ac.uk!pipex!uunet!utcsri!relay.cs.toronto.edu!smoke.cs.toronto.edu!cs.toronto.edu!chris Newsgroups: comp.unix.ultrix,comp.unix.bsd From: chris@cs.toronto.edu (Chris Beck) Subject: Signal catching probleem Message-ID: <93Aug10.191758edt.858@smoke.cs.toronto.edu> Organization: Department of Computer Science, University of Toronto Date: 10 Aug 93 23:18:16 GMT Lines: 75 I've got a signal handling problem that I can't see my way around. Any help that can be given is greatly appreciated. I have a process that receives signals from outside. There are 2 possible sequences of signals that will arrive at the particular point in the process. Either: SIGUSR1, SIGUSR2, SIGUSR1 or: SIGUSR2, SIGUSR1 I want to treat the SIGUSR1 after the SIGUSR2 differently than I treat the first one (if there is a first one). So the set-up I have is this: int sig2_arrived; main(){ ... /* set original catcher */ signal(SIGUSR1,catcher1); signal(SIGUSR2,catcher1); ... /* block and wait for a signal */ sig2_arrived = 0; oldmask = sigblock(sigmask(SIGUSR1) | sigmask(SIGUSR2)); while (!sig2_arrived) sigpause(sigmask(0)); /* set new catcher for SIGUSR1 */ signal(SIGUSR1,catcher2); ... } void catcher1(int sig_num){ if (sig_num == SIGUSR1){ /* do something that does not use sig2_arrived */ } if (sig_num == SIGUSR2){ sig2_arrived = 1; } } void catcher2(int sig_num){ if (sig_num == SIGUSR1){ /* do something different than above */ } } The problem is that the second SIGUSR1 might arrive while SIGUSR2 is being processed (before sigpause() returns). I want to process SIGUSR2 without being interrupted by SIGUSR1, but I also want to be able to receive SIGUSR1 if it comes before SIGUSR2 - so sigpause(sigmask(SIGUSR1)) won't help. Doing something like moving the installation of catcher2 inside of catcher1 and/or attempting to block SIGUSR1 inside of catcher1 won't guarantee not being interrupted (because of the non-atomic commands that are necessary). Anybody got any ideas? Thanks, Chris >>>>>>>>>> Sentio nos in Kansate non iam adesse, Totus. <<<<<<<<<<<<<<<<<<<< Chris Beck chris@cs.utoronto.ca