c - How to pass two parameter to sa_sigaction? they are FILE* and PID of child process -
when capture signal, want send message 'end' child process , if still live use kill pid kill it. no global variable
i think have use sa_sigaction, confuse how send file* of pipe , pid of child it. can can give em example this??
i'd pass pip , pid hdl how change code?? i'd capture signal can captured, first parameter of sigaction(sigint, &act, pip) ?? instead of sigint in advance
static void hdl (int sig, siginfo_t *siginfo, void *pip) { xxxxxxx } int main() { file** pip; int* pid; struct sigaction act; memset (&act, '\0', sizeof(act)); act.sa_sigaction = &hdl; act.sa_flags = sa_siginfo; sigaction(sigint, &act, pip); sleep (10); return 0; }
this not possible (to pass more arguments signal handler). need use global or static variable.
you cannot add parameter signal handler, simple pid_t
or file*
or void*
signals delivered kernel, , kernel (with some low-level, machine , abi specific, trampoline-like code in libc
) pushes call frame signal handler (and 1 sigreturn(2)). signature of handlers fixed, documented in signal(7)
besides, have small number of signals. consider having global variable array of data related signal.
with sigaction(2) (using sa_siginfo
) int
signal number, siginfo_t
, ucontext_t
pointers handler. can use them appropriately. instance, sigio
can use si_fd
file descriptor causing signal.
beware signal handlers allowed call (even indirectly) small set of functions (the so-called async-signal-safe functions, subset of syscalls). in particular calling fputs
or <stdio.h>
function; or malloc
forbidden inside signal handlers. hence, thru global variables, should not use file*
inside signal handler (that undefined behavior, if might apparently work want sometimes).
a common habit (see posix documentation signal.h) only set global volatile sig_atomic_t
flags in signal handler, , test (and reset) flag outside handler. you'll able typically call poll(2) -probably using fileno(3)- or waitpid(2) (outside of yous signal handler, e.g. in loop inside main code).
you need reads books on advanced linux programming , or advanced posix programming
Comments
Post a Comment