Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!think.com!sdd.hp.com!caen!math.lsa.umich.edu!sharkey!bnlux1.bnl.gov!drs From: drs@bnlux1.bnl.gov (David R. Stampf) Newsgroups: comp.unix.wizards Subject: Re: Signals and context switches Message-ID: <1991Jun17.131027.8700@bnlux1.bnl.gov> Date: 17 Jun 91 13:10:27 GMT References: <1991Jun16.010626.28257@bnlux1.bnl.gov> <1991Jun17.085558.16652@prl.dec.com> Organization: Brookhaven National Laboratory, Upton, NY 11973 Lines: 61 In article <1991Jun17.085558.16652@prl.dec.com> boyd@prl.dec.com (Boyd Roberts) writes: >In article <1991Jun16.010626.28257@bnlux1.bnl.gov>, drs@bnlux1.bnl.gov (David R. Stampf) writes: >> program 1 sends a SIGUSR1 signal to program 2, then waits to >> receive a SIGUSR1 signal from program 2. It repeats this 100 >> times. >> >> program 2 just catches SIGUSR1 signals from program 1 and sends >> a SIGUSR1 signal back. >> >> What surprises me is that it takes 70 seconds to send the 100 >> signals back and forth! > >Well, it'll depend on the load on your machine and how long the >running processes run for, on average. Worst case is that you have >N compute bound processes doing no I/O, which translates into 1 second >time quantums. Your signal catching programs only receive the signal >when they run, and they have to wait till it's their turn. This could be >a long time, but it could be quick. It's just not predictable. > There is virtually no load - it is a sun ipc with only myself on and running. I guess I'm amazed that the time quanta is as large as 1 second. >Maybe you could do something gross to speed it up, but already I think >it's time for a walk into the hall of mirrors and have a good hard geek >at what you're trying to achieve. Signals were not designed for inter-process >communication. They were there to kill processes. > > I recieved a few suggestions to go to sleep rather than while(1);, which suprisingly didn't work! What we had thought was that by calling kill, we would force a context switch. That obvivously does not happen. What *did* work was to call select without any file descriptors, but with a miniscule timeout. That seemed to force the switch. I'm still puzzled by sleep's failure. As it turns out, using sleep would be inappropriate for our application since it may interfer with other timers, and this had to be written as a library function. Actually, what we are trying to achieve is to have one process notify another that it has to take care of some business. I don't believe that there is any other way to do that in unix other than by signals because of the constraints that 1) it will happen asynchronously, 2) it has to be recognized "quickly" and 3) it has to be done at a library routine level so that the application program is totally oblivious to what is going on. That leaves out message queues etc. Also, fewer than 1/4 of the signals available on my system have anything to do with "killing" a process, despite the name of the system call. It does serve as a one-bit interprocess communications pipe quite nicely. >Boyd Roberts boyd@prl.dec.com > >``When the going gets wierd, the weird turn pro...'' < dave