I was reading The Design Of UNIX OS and had a doubt.
A signal handling function can be specified in the signal() call. The handler is supposed to execute when the process receives that particular signal. An algorithm known as psig runs to handle signals if they are received by a process.
In case of a user defined handler being specified, the psig algorithm modifies the user level context (i.e. pushes a frame at the top of the stack with the stack pointer pointing to the top of the stack) This frame indicates the execution of the handling function.
If the above mentioned is true, the signal handling function should always be executed after a return from the signal() call (as the stack frame at the top of the stack will be seen by the kernel first). However, this is not true as i can specify a signal handler for a particular signal earlier in my code (lets say in main()) and send a signal at a later point of time in code. The signal handling function is only executed when the signal is sent (say by the kill() call) and not immediately after the signal() call.
Can anyone please clarify?