Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementation of Signals under Linux and Windows?

I am not new to the use of signals in programming. I mostly work in C/C++ and Python. But I am interested in knowing how signals are actually implemented in Linux (or Windows).

Does the OS check after each CPU instruction in a signal descriptor table if there are any registered signals left to process? Or is the process manager/scheduler responsible for this?

As signal are asynchronous, is it true that a CPU instruction interrupts before it complete?

like image 301
Grijesh Chauhan Avatar asked Dec 15 '22 18:12

Grijesh Chauhan


1 Answers

The OS definitely does not process each and every instruction. No way. Too slow.

When the CPU encounters a problem (like division by 0, access to a restricted resource or a memory location that's not backed up by physical memory), it generates a special kind of interrupt, called an exception (not to be confused with C++/Java/etc high level language exception abstract).

The OS handles these exceptions. If it's so desired and if it's possible, it can reflect an exception back into the process from which it originated. The so-called Structured Exception Handling (SEH) in Windows is this kind of reflection. C signals should be implemented using the same mechanism.

like image 176
Alexey Frunze Avatar answered Dec 31 '22 01:12

Alexey Frunze