RyanScottLewis
RyanScottLewis

Reputation: 14016

Intercepting Signals From Processes

How I would go about capturing/intercepting signals sent to another process from my own process? Willing to use C, Ruby, or any Linux package.

Upvotes: 1

Views: 1098

Answers (2)

Hugh
Hugh

Reputation: 8932

I think that the ptrace(2) system call is what you want. From the manual: "While being traced, the child will stop each time a signal is delivered, even if the signal is being ignored. (The exception is SIGKILL, which has its usual effect.) The parent will be notified at its next wait(2) and may inspect and modify the child process while it is stopped. The parent then causes the child to continue, optionally ignoring the delivered signal (or even delivering a different signal instead)."

Upvotes: 1

praetorian droid
praetorian droid

Reputation: 3029

You can write a library wrapper that will replace system signal/sigaction calls to intercept setting of the signal handler and set your own handlers. On received signal, you can do your job and call user handler later. Use LD_PRELOAD to replace system signal/sigaction routines by your own.

Upvotes: 3

Related Questions