I notice that sigaction
has a alternate signal handler that is called when the SA_SIGINFO
flag is set. The alternate function has a void* context
parameter. Now, according to the APUE book, this parameter can be cast into a ucontext_t
structure. My question is that can I not cast it into any structure of my choice ? That way I could pass my own arguments into a signal handler. I noticed a post in stackoverflow stating that we just can't pass arguments to a signal handler as they are a very primitive feature. Is this possible ?
From this sigaction
manual page:
This is a pointer to a
ucontext_t
structure, cast tovoid *
. The structure pointed to by this field contains signal context information that was saved on the user-space stack by the kernel; ... Commonly, the handler function doesn't make any use of the third argument.
So this argument is a kernel-specific pointer to a special signal context. It's not possible to reuse it for user-data.