Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to use sigaction function to set parameter to a callback function.

438 views
Skip to first unread message

say88

unread,
Dec 21, 2005, 4:59:31 AM12/21/05
to
Hi,all.I meet a problem.
As all know,the sigaction's prototype is
as following:

int sigaction(int signum, const struct sigaction *act, struct sigaction
*oldact);

and the second parameter is a pointer to a struct sigaction whose
defination is as following:

struct sigaction {
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t *, void *);
sigset_t sa_mask;
int sa_flags;
void (*sa_restorer)(void);
}


A typical usage is as following:

//first,define a callback function

void callme(int signum,siginfo_t * info,void * v)
{

//....;

}

//second,define a variable of struct sigaction

struct sigaction sa;

sa.sa_handler = 0;
sa.sa_sigaction = callme;
sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);

//third,call function sigaction.
sigaction(SIGALRM,&sa,NULL);

But how can I pass a lot of parameters to callme except for
global variables?

And,in windows,it is very easy to do that.

timeSetEvent( IN UINT uDelay,
IN UINT uResolution,
IN LPTIMECALLBACK fptc,
IN DWORD_PTR dwUser,
IN UINT fuEvent);

the pftc is callback function and the dwUser is the user data's pointer.

Who can tell me how to do ?

Thanks for advance!

say.u.

Josef Moellers

unread,
Dec 21, 2005, 5:13:07 AM12/21/05
to

You're comparing appleas to pears here. In Linux, there's a one-to-one
mapping of handler to signal. When dealing with timer events, there are
usually several handlers scheduled for execution.

> Who can tell me how to do ?

You'd have to build your own layer on top of SIGALRM and alarm() to
handle registration of more than one callback. You can then pass
whatever you want to your (higher level) handler.
Maybe such a beast already exists.

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

Roger Leigh

unread,
Dec 21, 2005, 5:36:13 AM12/21/05
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Josef Moellers <josef.m...@fujitsu-siemens.com> writes:

[sigaction with multiple handlers]


> You'd have to build your own layer on top of SIGALRM and alarm() to
> handle registration of more than one callback. You can then pass
> whatever you want to your (higher level) handler.
> Maybe such a beast already exists.

Perhaps an event loop would be a more appropriate design? GLib
provides a pre-canned one (GMain), but it's fairly simple to write
your own.


Regards,
Roger

- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8+ <http://mailcrypt.sourceforge.net/>

iD8DBQFDqTAcVcFcaSW/uEgRAtuPAJ9JbImd0Sg2GC8OSE/iNDoLscffOQCdFcdL
3qNtslSqiY/MG4Mo338b04Y=
=tDqs
-----END PGP SIGNATURE-----

0 new messages