Is there a way to find the process ID of the application that caused the interrupt?
current->pid
after including #include <linux/sched.h>
will tell you a process that has been interrupted in accordance with the following question about stack overflow and Linux Chapter 6, “Interrupt Context” .
It is assumed that you call current->pid from the interrupt context that your notifier should be in if you are not doing heavy calculations in your notification, which should not be done.
If you are in the context of a process or have a proactive kernel like Andrew Medico and use a macro to get information about current , this will be changed by the scheduler if any significant time has passed.
According to TheCodeArtist's comment , the following response to a stack overflow demonstrates writing to files. It’s nice to do an IO file in the kernel, especially from an interrupt context.
An example of writing keystrokes to a buffer in memory instead of a file is available here .
The following question shows how to get the process name from the process ID.
However, all this gives you keystrokes for the process with the given name; it cannot determine that the process with the name has any connection with the browser window.
See the next stack overflow question for how to get the X11 window from a process ID and the next stack. Overflow issue with XGrabKey and Xlib to capture keys in user space.
A more reliable way to ensure that keypress from a specific browser, not only does it at the user space level, but also at the browser plugin or extension level. Chrome example: here , and Firefox example here .
source share