Reputation: 61
A user defined handler function is specified for a particular signal.On reception of this signal the handler function is invoked. Does the handler function run in user space or kernal space ? Or generally a action for any signal is executed in user space or kernal space?
Upvotes: 6
Views: 3617
Reputation: 2069
The kernel can send a signal to the user space, but not vice versa and the amount of data to be sent is quite limited and the signal handlers are run in user space.
Explanation :
In order to be able to send a signal from kernel space to user space, the kernel needs to know the pid of the user space process. As soon as the kernel module receives the pid, it looks for the corresponding process descriptor, and sends a signal to it. All information related to the signal is saved in a struct siginfo
.
The user space process registers a signal handler function with the kernel. This adds the address of the signal handler function to the process descriptor. This function gets executed each time a certain signal is delivered.
Upvotes: 0
Reputation: 231103
Generally speaking signals are executed in userspace. However, since the C language standard doesn't actually define a separation between user and kernel-space, it's conceivable that there may be C language implementations in which this is not the case.
Note, however, that in Windows and all flavors of Unix, signals are guaranteed to run in userspace.
Upvotes: 5
Reputation: 14458
Signal handlers have to run in user space. If they ran in kernel space, they could access anything in the entire machine (since the kernel has control over all processes). As a result, a malicious program could easily corrupt other programs' memory, steal data, or worse by simply sending a signal to itself.
Upvotes: 6
Reputation: 182619
The handler runs in user space and only has access to the virtual address space of the process.
Of course, the C standard proper doesn't know anything about "user" and "kernel".
Upvotes: 7