![]() ![]() This identifies the signal that we want to handle and the action that we want to take when the signal is received, and it takes an optional parameter that will receive information about any previous signal handler that was installed for that signal. The next step, which is shown in Listing 2, is to install the signal handler using the sigaction() system call. ![]() Void handle_prof_signal(int signal, siginfo_t * info, void * context) Listing 1 shows an empty handler that receives information about the signal number, information about the signal delivery, and information about the thread context. The parameters are necessary if the objective is to extract information from the current state of the application. There are two kinds of signal handling routines: one kind that does not take any parameters and another kind that takes a set of three parameters. The first step is to declare a signal handling routine. Signals can be used to handle events such as timers expiring, and they can even handle hardware problems such as misaligned memory accesses or illegal/unsupported instructions. In many cases, the default handler causes the process to exit. Once a process receives a signal, it either handles it with a custom handler or leaves it for the default handler. They can come from within the process, or they can be sent externally using the kill command or some other mechanism. ![]() Signals are used to interrupt a running process and get it to do something else. This article demonstrates how to use signal handlers for various scenarios, such as profiling an application and handling illegal instructions in a UNIX environment. ![]()
0 Comments
Leave a Reply. |