Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!linac!att!emory!gatech!udel!rochester!rutgers!mcnc!borg!smith!wagner From: wagner@smith.cs.unc.edu (Michael Wagner) Newsgroups: comp.lang.c++ Subject: UNIX signals in C++ Message-ID: <2523@borg.cs.unc.edu> Date: 22 Mar 91 18:48:57 GMT Sender: news@cs.unc.edu Organization: University of North Carolina, Chapel Hill Lines: 58 Originator: wagner@smith A week or so ago, I posted news asking about UNIX signals in C++. As many of you may recall, the basic problem is that the signal() call expects a pointer to a function as its second parameter. Here's the solution that worked (note that the SIG_PF worked with Interviews' file, though SIG_PFV worked with Sun's AT&T ): /******************************/ // an ugly but invaluable kludge from Jon Leech /* A *global* pointer to the object whose method is to be invoked upon receiving SIGINT. The handler has no way of getting at local variables. */ Texted *t; /* This declares a signal handler. */ SIG_PF sighook(int, SIG_PF) { // Invoke the method t->Update(); } /********************************/ void Texted::Update() { signal(SIGUSR1, (SIG_PF)sighook); printf("Update invoked!\n"); . . . } . . . Texted::Texted () { signal(SIGUSR1, (SIG_PF)sighook); . . . } . . . The "Jon Leech" mentioned is leech@cs.unc.edu. I hope this save's someone some time and agony.